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

已经错了37的飘过,求打救。

Posted by dlrj2012 at 2012-07-20 17:48:06 on Problem 1026
#include <iostream>
#include <stdio.h>
using namespace std;

int key[205];  //存储钥匙
int count[205];  //计算循环次数
int count1[205];  //在K次机密后的循环次数
char info[210];
char transfer[210];

int main()
{
	int number;
	int times;
	int i;

	while(scanf("%d",&number)!=EOF && number )
	{
		for ( i = 0; i < number; ++i )
			cin >> key[i];

		for ( i = 0; i < number; ++i )
		{
			if ( key[i] == i+1 )
				count[i] = 1;
			else
			{
				count[i] = 2;
				int post = key[i]-1;
				while( key[post] != i+1 )
				{
					count[i]++;
					post = key[post]-1;
				}
			}
		} //计算循环周期


		while (scanf("%d%*c", &times) > 0 && times)
		{	
			for ( i = 0; i < 205; i++ )
				info[i]= ' ';
			gets(info);
			for(i=0;i<=number;i++)
			{
				 if(info[i]==10 || info[i]==0) info[i]=' ';
			}
			
			for ( i = 0; i < number; ++i )
					count1[i] = times % count[i];


			for ( i = 0; i < number; ++i )
			{			
				char now = info[i];
				int post = key[i] - 1;
				int ok = count1[i];
				if ( ok == 0  )
					transfer[i] = now;
				else
				{
					while( ok )
					{
						transfer[post] = now;
						post = key[post] - 1;
						ok--;
					}
				}
			}



		//	transfer[number]='\0';
			printf("%s\n",transfer);
		}
		cout << endl;
	}

	//system("pause");
	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