网易雷火笔试题-1(简单)
题目描述
给定一个字符串,请你将字符串重新编码,将连续的字符替换成“连续出现的个数+字符”。比如字符串AAAABCCDAA会被编码成4A1B2C1D2A。
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int main() {
vector<int> zimu;
string f;
string a;
cin >> a;
for (int i = 0,j = 0; i < a.size();j++) {
zimu.push_back(0);
f += a[i];
int t = a[i]-'0';
while (a[i] - '0' == t) {
i++;
zimu[j]+=1;
}
}
string ff;
for (int i = 0; i < f.size(); i++) {
ff += to_string(zimu[i]);
ff += f[i];
}
cout << ff << endl;
return 0;
}
题目本身挺简单的没啥好讲的,不过这雷火的实习生笔试比本部的难太多了吧······