Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么总是runtime error?太奇怪了。#include<stdio.h> #include<iostream> #include<limits.h> #include<string.h> #include<algorithm> #include<math.h> using namespace std; const int MAX = 210; int number[MAX]; char character[MAX]; char temp[MAX]; int circle[MAX][MAX]; int main(int argc, char *argv[]){ int n,k; //cout<<~0<<endl; while(~scanf("%d",&n)&& n!=0) { for (int i=0; i<n; i++) { scanf("%d",number+i); number[i] -= 1; } while(~scanf("%d",&k) && k ){ for (int i=0; i<n; i++) circle[0][i] = number[i]; int T=0; for (int i=1; ; i++) { for(int j=0; j<n; j++) { circle[i][number[j]] = circle[i-1][j]; } bool flag = true; for (int j=0; j<n; j++) if (circle[0][j] != circle[i][j]){ flag = false; break; } if (flag){ T = i; break; } } k = k%T;//figure out the cycle first; memset(character,0,sizeof(character)); memset(temp, 0,sizeof(temp)); getchar(); gets(character); bool flag = true; while(k--) { if (flag) { // cout<<"flag is true"<<endl; for (int i=0; i<n; i++) { temp[number[i]] = character[i]; } int i; for ( i=203; i>=0; i--) { if (temp[i]!=0) break; } temp[i+1] = 0; for(int j = i; j>=0; j--) if (temp[j]==0) temp[j]=' '; flag = (!flag); } else { //cout<<"flag is false"<<endl; for (int i=0; i<n; i++) { character[number[i]] = temp[i]; } int i; for (i=203; i>=0; i--) if (character[i]!=0) break; character[i+1] = 0; for(int j=i; j>=0; j--) { if (character[j] == 0) character[j] = ' '; } flag = (!flag); } } if (!flag) puts(temp); else{ puts(character); //cout<<"else"<<endl; } //cout<<"get temp"<<endl; } printf("\n"); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator