-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlook_and_say_problem.cpp
More file actions
44 lines (37 loc) · 939 Bytes
/
Copy pathlook_and_say_problem.cpp
File metadata and controls
44 lines (37 loc) · 939 Bytes
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
//Look and say problem
//https://ide.geeksforgeeks.org/zYlGqG5xZC
#include<bits/stdc++.h>
using namespace std;
int mod=1e9+7;
#define F(a,b,var) for(int var=a;var<b;var++)
#define FAST_INP ios_base::sync_with_stdio(false);cin.tie(NULL)
string generate(string s){
string result = "";
for(int i=0; i<s.size(); i++){
int count = 1;
while(i+1 < s.size() && s[i] == s[i+1]){ i++; count++; }
result += to_string(count) + s[i];
}
return result;
}
int main()
{
//code
FAST_INP;
int T;
cin>>T;
while(T--)
{
int n; cin>>n;
string s = "1";
vector<string> res;
for(int i=0; i<n ; i++){
s = generate(s);
res.push_back(s);
}
cout<<s<<"\n";
for(int i = 0; i<res.size(); i++)
cout<<res[i]<<" ";
}
return 0;
}