 # Editorial for SAYITOUT

All submissions for this problem are available.You are given the following series:
1, 11, 21, 1211, 111221, 312211, 13112221, 1113213211, …
We have to find nth term of the given series.
HINT: Please read the title of the problem.
HINT2: We are given first number as 1.
We have to keep the nth number as we say the (n-1)th number ALOUD.
Like for example, 1st number contains “one times one” so 2nd number is “11”.
2nd number is 11 which is “two times one”, hence 3rd number is “21”.
3rd number is 21 which is “one time two and one time one”, hence 4th number is “1211”.
4th number is 1211, which is “1 times 1, 1 times 2, 2 times 1”. Hence 5th number is “111221”
Input:
• The first and the only line contains NN
Output:
• The output should be the nth term of the series.
Sample Input - 1:
3
Sample Output - 1:
21
Sample Input - 2:
5
Sample Output - 2:
111221
Constraints
• 1≤N≤25

Code:-

#include
#include
using namespace std;

int main()
{
string S,temp;
S=‘1’;
S=’'; int N; cin>>N; N--; for(int i=0;i<N;i++) { char key=S; int count=1; int pointS=1; int pointT=0; while(1) { if(S[pointS]=='’)
{
temp[pointT++]=count+48;
temp[pointT++]=key;
temp[pointT++]=’'; break; } else { if(S[pointS]==S[pointS-1]) { count++; } else { temp[pointT++]=count+48; temp[pointT++]=key; count=1; key=S[pointS]; } pointS++; } } int j; for(j=0;temp[j]!='’;j++)
{
S[j]=temp[j];
}
S[j]=’'; } for(int i=0;S[i]!='’;i++)
{
cout<<S[i];
}
}

Explanation:-

This problem’s solution is in it’s title - SAY IT LOUD OUT. You have to find nth number in this sequence:- 1 11 21 1211 111221 312211 13112221…

Here first number is 1.
Second number is 11 because first number is one time one.
Third number is 21 because second number is two time one and one time one.
Thus one have to find nth number of this series.