The number of columns [simulation]

Description–

Small S today to give you out of a problem to find the law, entitled as follows:
following a series 1,11,21,1211,111221,312211, ......
small S asked you first N terms of this series is how much, and you a fog water simply can not find the law.
Clever little R quietly tell you this

A is a number 1, 11 writing
a number on the two 1, 21 writing
a number on a 2, a 1, 1211 writing
a number on a 1, a 2, a two, writing 111,221,
...... ......
I believe that smart you will be able to solve this problem.


Input–

The first line includes a positive integer N.

Output–

Line a positive integer (note number may be sung long integer, string or an array note storage)


Sample Input–

6

Sample Output–

312211


Notes -

To 100% of the data 1 <-N <= 30.


Problem-solving ideas -

1:11
11:21
111:31
2:12
22:22
222:32


Code -

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
string a,b;
char tt;
int n,t;
int main()
{
	a="1";
	scanf("%d",&n);
	for (int i=2;i<=n;++i) 
	{
		t=0,b="";
		for (int j=0;j<a.size();++j)
		  if (j==0 || a[j]==tt)
		  	  t++,tt=a[j];
	      else
	      {
	      	  b=b+char(t+'0')+tt;
	      	  tt=a[j],t=1;
	      }
	    b=b+char(t+'0')+tt;
		a=b;
	}
	cout<<a;
	
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_43654542/article/details/90725560