```
class Solution {
public:
string countAndSay(int n) {
string res = "";
string temp;
if (n == 1)
return "1";
res = "1";
for (int i = 1; i < n; i++)
{
char counter = res[0];
int c = 0;
for (int j = 0; j < res.length(); j++)
{
if (res[j] == counter)
c++;
else
{
temp += c + '0';
temp += counter;
counter=res[j];
c = 1;
}
}
temp += c + '0';
temp += counter;
counter++;
res = temp;
temp.clear();
}
return res;
}
};
```