知识点:字符串 双指针
版本1
耗时6分钟
注意使用双指针的时候,更新下标的方式。
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#include <map>
using namespace std;
int main(){
string str, temp;
int n;
cin>>str>>n;
for(int i = 0; i < n-1; i++){
temp.clear();
for(int j = 0; j < str.size(); ){
int k = 0;
while(j+k < str.size() && str[j] == str[j+k]) k++;
temp = temp + str[j] + char(k+'0');
j = j+k;
}
str = temp;
}
cout<<str<<endl;
return 0;
}