关键:
理解题意
class Solution {
public:
string countAndSay(int n) {
int cnt=1;
string str="1";
while (cnt<n){
int len=str.length();
int cot=0;
char ch=str[0];
string ans="";
for (int i=0;i<len;i++){
if (ch==str[i]) cot++;
else {
ans+=to_string(cot)+ch;
ch=str[i];
cot=1;
}
}
ans+=to_string(cot)+ch;
str=ans;
cnt++;
}
return str;
}
};