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

Re:还真是郁闷,把cout改为printf才勉强不TLE了,唉~

Posted by conanhjj at 2008-07-21 20:24:23 on Problem 1026
In Reply To:还真是郁闷,把cout改为printf才勉强不TLE了,唉~ Posted by:winboycool at 2007-04-26 01:36:36
#include <stdio.h>
#include <string.h>
#define N 300
//Variables Declarations
	int pos[N],times;
	char ch[N];
int main()
{
	int n,k;
	while(true)
	{
		int chlen;
		char ch_temp[N];
		scanf("%d",&n);
		if(!n) break;	//如果n=0 退出
		for(int i=1;i<=n;++i)
		{scanf("%d", &pos[i]);}	
		times=-1;
		for(int i=1;i<=n;++i)
		{
			int j,temp;
			j=pos[i];
			temp=1;
			while(j!=i)
			{
				j=pos[j];
				++temp;	
			}
			if(times < temp) times=temp;
		}
		while(true)
		{
			scanf("%d",&k);
			if(!k) break;	//如果k=0 block结束 
			for(int j=0;j<N;++j)
			{ch_temp[j]='\0';}			
			k=k%times;
			if(k==0)  k=times;
			getchar();
			gets(ch);
			chlen=strlen(ch);
			if(chlen<n)	//增加' ' 
			{
				for(int	i=chlen;i<n;++i)
				{ch[i]=' ';}
			}
			ch[n]=0;
			for(int i=1;i<=k;++i)
			{
				for(int j=0;j<n;++j)
				{
					ch_temp[pos[j+1]-1]=ch[j];
				}	
				strcpy(ch,ch_temp);
			}

			printf("%s\n\n",ch);
		}
	}
	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