c++ ``` class Solution { public: string a[31]; string countAndSay(int n) {
a[1]="1";
for(int i=2;i<=30;i++)
{
char s1=a[i-1][0];int num=1;
string str="";
for(int j=1;j<a[i-1].size();j++)
{
if(a[i-1][j]!=a[i-1][j-1])
{
char x = num+'0';
str+=x;
str+=s1;
num=1;
s1=a[i-1][j];
continue;
}
else
num++;
}
char x = num+'0';
str += x;
str += s1;
a[i]=str;
}
return a[n];
}
}; ``