-
Notifications
You must be signed in to change notification settings - Fork 288
/
Copy pathAC_simulation_n2.cpp
51 lines (46 loc) · 1.09 KB
/
AC_simulation_n2.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
48
49
50
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_simulation_n2.cpp
* Create Date: 2014-12-17 14:46:49
* Descripton: simulation
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
class Solution {
public:
string countAndSay(int n) {
string pres = "1", news;
char tmpch;
int len, count;
for (int i = 1; i < n; i++) {
news = "";
len = pres.length();
tmpch = pres[0];
count = 1;
for (int i = 1; i < len; i++) {
if (tmpch == pres[i])
count++;
else {
news += count + '0';
news += tmpch;
tmpch = pres[i];
count = 1;
}
}
// the last
news += count + '0';
news += tmpch;
pres = news;
// cout << pres << endl;
}
return pres;
}
};
int main() {
int n;
Solution s;
while (cin >> n)
cout << s.countAndSay(n) << endl;
return 0;
}