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 |
请大家看看吧,小弟的程序WA了8次,我实在受不了了,请那位大侠看看吧,求您们了#include < iostream > using namespace std; int main () { char chArr [83]; int lenth , i , k , nInvAlen(0); while ( cin >> chArr ) { int nArr[83] , Pre[16][83] , Prelen[16]; int nInvArr[83] , sta[10]; if ( chArr[0] == '-' ){ break; } lenth = strlen( chArr ); Prelen [0] = lenth; for ( i = 0;i < lenth;i++ ) { nArr[i] = ( chArr[i] - 48 ); Pre[0][i] = nArr[i]; } for ( k = 1;k <= 15;k++ ) { for ( i = 0; i < 10;i++ ) { sta[i] = 0; } if ( k == 1 ) { for ( i = 0;i < lenth;i++ ) { sta[ nArr[i] ]++; } } else { for ( i = 0;i < nInvAlen;i++ ) { sta[ nInvArr[i] ]++; } } int j = 0; for ( i = 0 , j = 0;i < 10;i++ ) { if ( 0 < sta[i]&&sta[i] < 10 ) { nInvArr[j] = sta[i]; j++; nInvArr[j] = i; j++; } else if ( 10 <= sta[i] ) { nInvArr[j] = sta[i] / 10; j++; nInvArr[j] = sta[i] % 10; j++; nInvArr[j] = i; j++; } } Prelen[k] = nInvAlen = j; for ( i = 0; i <nInvAlen;i++ ) { Pre[k][i] = nInvArr[i]; } bool flag(1); int m = ( Prelen[k-1] < nInvAlen ) ? nInvAlen: Prelen[k-1]; for ( i = 0;i < m;i++ ) { if ( Pre[k-1][i] != nInvArr[i] ){ flag = 0;break; } } if ( flag && k == 1 ) { for ( i = 0;i < lenth;i++ ) { cout << nArr[i]; } cout <<" is self-inventorying"<<endl; goto loop; } if ( flag && k > 1 ) { for ( i = 0;i < lenth;i++ ) { cout << nArr[i]; } cout <<" is self-inventorying after "<<k-1<<" steps"<<endl; goto loop; } for( j = 0;j < k - 1;j++ ) { flag = 1; m = ( Prelen[j] < nInvAlen ) ? nInvAlen : Prelen[j]; for ( i = 0;i < m;i++ ) { if ( Pre[j][i] != nInvArr[i] ){ flag = 0;break; } } if ( flag ) { for ( i = 0;i < lenth;i++ ) { cout << nArr[i]; } cout <<" enters an inventory loop of length "<<(k-j)<<endl; goto loop; } } } for ( i = 0;i < lenth;i++ ) { cout << nArr[i]; } cout <<" can not be classified after 15 iterations"<<endl; loop:; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator