题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805260583813120
特别注意一下to_string的用法,里面参数要填成long long类型的才能在vs上通过,但是在PTA上面没问题
代码
#include<cstdio>#include<string>#include<iostream>#include<algorithm>using namespace std;int main(){string d;int n, j;cin>>d;scanf("%d", &n);for(int cnt = 1; cnt < n; cnt++){string t;for(int i = 0; i < d.size(); i = j){for(j = i; j < d.size() && d[j]==d[i]; j++);t += d[i] + to_string((long long)(j - i));}d = t;}cout<<d<<endl;return 0;}
理解错了题意的写法
#include<cstdio>#include<string>#include<iostream>#include<algorithm>using namespace std;int main(){string d;int n;cin>>d;scanf("%d", &n);for(int a = 0; a < n; a++){int hash[1000] = {0};for(int i = 0; i < d.size(); i++){hash[d[i] - '0']++;}d = "";for(int i = 0; i < 1000; i++){if(hash[i] != 0){d += i + '0';while(hash[i] != 0){d += hash[i] % 10 + '0';hash[i] /= 10;}}}cout<<d<<endl;}}
