Primordial Values |
Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB |
Total submit users: 72, Accepted users: 68 |
Problem 12877 : No special judgement |
Problem description |
What's the next number in the following sequence? |
Input |
Input will consist of specifications for a series of tests. Information for each test is a single line containing a string of digits of length 1 <= n < 100 that specifies the last value in a sequence defined as above. A line containing the value 0 terminates the input. |
Output |
Output should consist of one line for each test comprising the test number (formatted as shown) followed by a single space and the primordial value of the input value. |
Sample Input |
2221 312211 22 0 |
Sample Output |
Test 1: 221 Test 2: 1 Test 3: 22 模拟题,还算是一般吧,不算是太水,自己用两个队列维护的。代码写的比较水 #include<iostream> #include<cmath> #include<cstring> #include<cstdio> #include<fstream> #include<algorithm> #include<string> #include<stack> #include<queue> #include<climits> #include<map> #define MAXP(x,y) (((x)>(y))?(x):(y)) #define MINP(x,y) (((x)<(y))?(x):(y)) const int MAX=0xfffffff; using namespace std; int main( ) { //freopen("1.txt","r",stdin); char s[110]; queue<int>q1; queue<int>q2; int kase=0; while(cin>>s&&strcmp("0",s)!=0) { while(!q1.empty( )) q1.pop(); while(!q2.empty( )) q2.pop(); int ls=strlen(s); if(ls%2==1) { printf("Test %d: ",++kase); puts(s); continue; } for(int i=0;i<ls;i++) { int t=s[i]-'0'; q1.push(t); } int flag1=0; int flag2=0; while(!flag1&&!flag2) { int ts1=q1.size( ); if(ts1%2==0) for(int i=0;i<ts1/2;i++) { int t1=q1.front(); q1.pop(); int t2=q1.front(); q1.pop( ); if(ts1==2&&t1==2&&t2==2) { flag1=3; break; } for(int j=1;j<=t1;j++) q2.push(t2); } while(!q1.empty( )) q1.pop(); int ts2=q2.size( ); if(flag1==3) break; if(ts2%2!=0) { flag2=1; break; } if(ts2%2==0) for(int i=0;i<ts2/2;i++) { int t1=q2.front(); q2.pop(); int t2=q2.front( ); q2.pop( ); if(ts2==2&&t1==2&&t2==2) { flag2=3; break; } for(int j=1;j<=t1;j++) q1.push(t2); } ts1=q1.size( ); if(flag2==3) break; if(ts1%2!=0) { flag1=1; break; } while(!q2.empty( )) q2.pop(); } printf("Test %d: ",++kase); if(flag1==3||flag2==3) cout<<"22\n"; else if(flag1==1) while(!q1.empty()) { cout<<q1.front(); q1.pop(); } else if(flag2==1) while(!q2.empty()) { cout<<q2.front(); q2.pop(); } cout<<endl; } return 0; } |
HNU暑假赛七B
最新推荐文章于 2021-07-28 08:50:37 发布