Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

无语了~!自己测试N组数据都没有WA..但在POJ上总是WA...请高手门999!!!

Posted by inowfordream at 2009-02-02 16:49:49 on Problem 1026
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator