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

大家帮忙看看我的程序,为什么总是wa啊

Posted by LC19863014 at 2008-08-18 07:53:47 on Problem 1026
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
	int num,i,j,cycles,t;
	int squeue[250],cycle[250];
	char s[250],stemp[250];
	while (1)
	{
		scanf("%d",&num);
		if(num==0)
			break;
		for (i=1;i<=num;i++)
			scanf("%d",&squeue[i]);
		for (i=1;i<=num;i++)
		{
			j=1;
			t=i;
			while(squeue[t]!=i)
			{
				t=squeue[t];
				j++;
			}
			cycle[i]=j;
		}
		while (1)
		{
			scanf("%d ",&cycles);
			if(cycles==0)
			{
				printf("\n");
				break;
			}
			memset(s,' ',sizeof(s));
			i=1;
			while (1)
			{
				scanf("%c",&s[i]);
				if(s[i++]=='\n')	
					break;
			}
			s[i-1]=' ';
			s[num+1]='\0';
			memset(stemp,' ',sizeof(stemp));
			for (i=1;i<=num;i++)
			{
				t=cycles%cycle[i]; 
				int temp=i;
				for(j=1;j<=t;j++)
					temp=squeue[temp];
				stemp[temp]=s[i];		
			}
			stemp[num+1]='\0';
			printf("%s\n",stemp+1);
		}
	}
	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