PTA乙级 (*1084 外观数列 (20分)(int转换成string:to_string))
1084 外观数列 (20分)
https://pintia.cn/problem-sets/994805260223102976/problems/994805260583813120
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <string> #include <cstring> using namespace std; int main() { string s1; int n; cin>>s1>>n; for(int i=0;i<n-1;i++) { string s2; int count[10]={0}; for(int j=0;j<s1.length();j++) { count[s1[j]-'0']++; if((j==s1.length()-1)||(s1[j]!=s1[j+1])) { s2+=to_string(s1[j]-'0'); s2+=to_string(count[s1[j]-'0']); count[s1[j]-'0']=0; } } s1=s2; } cout<<s1; return 0; }
天晴了,起飞吧