-
Notifications
You must be signed in to change notification settings - Fork 0
/
lookAndSay.cpp
60 lines (57 loc) · 1.06 KB
/
lookAndSay.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
51
52
53
54
55
56
57
58
59
60
/*1 8
1123123111
1 11 12 1121 122111 112213 12221131 1123123111*/
#include<iostream>
#include<vector>
using namespace std;
void las(vector<int> v, vector<int> &t){
int p=0,present,cnt;
present=v[0];
while (p<v.size())
{
if(present==v[p]){
cnt++;
}
else
{
t.push_back(present);
t.push_back(cnt);
present=v[p];
cnt=1;
}
p++;
}
t.push_back(present);
t.push_back(cnt);
}
int main() {
string s;
int n, j;
cin >> s >> n;
for (int cnt = 1; cnt < n; cnt++) {
string t;
for (int i = 0; i < s.length(); i = j) {
for (j = i; j < s.length() && s[j] == s[i]; j++);
t += s[i] + to_string(j - i);
}
s = t;
}
cout << s;
return 0;
}
int main1(){
int d,n;
cin>>d>>n;
vector<int> v;
v.push_back(d);
vector<int> t;
t.push_back(d);
for(int i=1;i<n;i++){
v = t;
t.clear();
las(v, t);
}
for(int i:t){
cout<<i;
}
}