-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsuite_de_Conway.cpp
57 lines (50 loc) · 1.01 KB
/
suite_de_Conway.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
// Read inputs from stdin. Write outputs to stdout.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<int> get_line(int n, int r)
{
vector<int> output;
if(n == 1)
{
output.push_back(r);
return output;
}
vector<int> v = get_line(n-1, r);
int last_val = -1;
int count = 0;
for(vector<int>::iterator it = v.begin(); it != v.end(); ++it)
{
if(*it == last_val)
{
count++;
}
else
{
if(count > 0)
{
output.push_back(count);
output.push_back(last_val);
}
last_val = *it;
count = 1;
}
}
if(count > 0)
{
output.push_back(count);
output.push_back(last_val);
}
return output;
}
int main()
{
int r, l;
cin >> r >> l;
vector<int> v = get_line(l, r);
cout << v[0];
for(int i=1; i<v.size(); i++)
cout << " " << v[i];
return 0;
}