-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp38.cpp
47 lines (41 loc) · 876 Bytes
/
p38.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
using namespace std;
class Solution {
public:
string countAndSay(int n) {
string s="1";
string next;
int i,cnt;
while (n>1) {
i=0;next="";
while (i<s.size()) {
cnt=1;
while (i+1<s.size() && s[i+1]==s[i]) {
i++;
cnt++;
}
next+=to_string(cnt)+s[i];
i++;
}
s=next;
n--;
}
return s;
}
};
static const auto io_sync_off = []()
{
// turn off sync
std::ios::sync_with_stdio(false);
// untie in/out streams
std::cin.tie(nullptr);
return nullptr;
}();
int main() {
auto res = Solution().xxx;
cout << res <<endl;
return 0;
}