题目:https://leetcode.com/problems/count-and-say/tabs/description
代码:
class Solution {
public:
string countAndSay(int n) {
string temp="1",res;
int count;
if(n==0) return "";
if(n==1) return "1";
for(int i = 1;i<n;i++){
int len = temp.size();
for(int j=0;j<len;j++){
count = 1;
while(temp[j]==temp[j+1]&&j+1<len){
count++;
j++;
}
res+=to_string(count)+temp[j];
}
temp=res;
res.clear();
}
return temp;
}
};