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 |
无语了~!自己测试N组数据都没有WA..但在POJ上总是WA...请高手门999!!!#include <iostream> #include <string> using namespace std ; int timelimit( int a[] , int m ) { int num = 1 ; int o = a[m] ; while ( 1 ) { if ( o == m ) break ; num++ ; o = a[o] ; } return num ; //返回周期次数 } int main() { int a[201] ; char b[202] ; char c[202] ; int n , i , k , j , m ; int length ; int time ; int q ; cin >> n ; while ( n ) { for ( i = 0 ; i < n ; i++ ) { cin >> a[i] ; } //初始化a[201] for ( i = 0 ; i < n ; i++ ) { a[i]-- ; } cout << endl ; for ( i = 0 ; i <= 201 ; i++ ) { b[i] = '\0' ; } //初始化b[202] for ( i = 0 ; i < 201 ; i++ ) { c[i] = ' ' ; } //初始化c[202] c[201] = '\0' ; cin >> k ; while ( k ) { gets(b-1) ; length = strlen( b ) ; for ( m = 0 ; m < length ; m++ ) { time = timelimit( a , m ) ; time = k % time ; if ( time ) { q = a[m] ; for ( i = 1 ; i < time ; i++ ) { q = a[q] ; } c[q] = b[m] ; } else c[m] = b[m] ; } for ( j = 0 ; j < n ; j++ ) { cout << c[j] ; } cout << endl ; for ( i = 0 ; i <= length ; i++ ) //初始化 { b[i] = '\0' ; c[i] = ' ' ; } c[length+1] = '\0' ; cin >> k ; } cout << endl ; cin >> 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