报数

报数指的是,按照其中的整数的顺序进行报数,然后得到下一个数。如下所示:

1, 11, 21, 1211, 111221, ...

1 读作 "one 1" -> 11.

11 读作 "two 1s" -> 21.

21 读作 "one 2, then one 1" -> 1211.

给定一个整数 n, 返回 第 n 个顺序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
string (int n) {
string a = "1";
string b = "";
int count = 1;
for(int i = 1;i<n;i++){
for(int j = 1;j<=a.size();j++){
if(a[j]==a[j-1]){
count++;
}
else{
b = b + to_string(count) + a[j-1];
count = 1;
}
}
a = b;
b = "";
}
return a;
}