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

这两个几乎一样的程序有什么错误啊

Posted by yizer at 2009-03-23 01:33:56 on Problem 1026
{
PKU 1026
Author : Yizer
State : AC
}
Program pku1026;
Var
 n,k,j,i:longint;
 a,up:array[0..200]of longint;
 loop:array[0..200,0..200]of longint;
 s,ans:string;

BEGIN
 while true do
  begin
   readln(n);
   if n=0 then
    break;
   fillchar(a,sizeof(a),0);
   for i:=1 to n do
    read(a[i]);
   readln;
   fillchar(loop,sizeof(loop),0);
   for i:=1 to n do
    loop[i,0]:=i;
   for i:=1 to n do
    for j:=1 to n do
     Begin
      loop[i,j]:=a[loop[i,j-1]];
      if loop[i,j]=loop[i,0] then
       begin
        up[i]:=j;
        break;
       end;
     End;
   while true do
    begin
     read(k);
     if k=0 then
      Begin
       readln;
       break;
      End;
     readln(s);
     delete(s,1,1);
     while length(s)<n do
      s:=s+' ';
     ans:=s;
     for i:=1 to n do
      ans[loop[i,k mod up[i]]]:=s[i];
     writeln(ans);
    End;
    writeln;
   End;
END.


/*
PKU 1026
Author : Yizer
State : WA
*/
#include <iostream>
using namespace std;

int main()
{
	freopen("data.in","r",stdin);
	char line[256];
	int n;
	while (gets(line),sscanf(line,"%d",&n),n)
	{
		int a[201] = {0};
		for (int i=1;i<=n;i++)
			scanf("%d",a+i);
		
		getchar();
		int loop[201][201] = {0};
		int up[201] = {0};
		for (int i=1;i<=n;i++)
			loop[i][0] = i;
		for (int i=1;i<=n;i++)
			for (int j=1;j<=n;j++)
			{
				loop[i][j] = a[loop[i][j-1]];
				if (loop[i][j]==loop[i][0])
				{
					up[i] = j;
					break;
				}
			}
		while (gets(line),strcmp(line,"0"))
		{
			int k;
			char str[256],ans[256];
			sscanf(line,"%d %[^\n]\n",&k,str);
			int len = strlen(str);
			while (len<n) 
				str[len++] = ' ';
			str[len] = '\0';
			strcpy(ans,str);
			for (int i=1;i<=n;i++)
				ans[loop[i][k%up[i]]-1] = str[i-1];
			puts(ans);
		}
		puts("");
	}
	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