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

What's wrong with this code?? Why WA??

Posted by farzades at 2008-09-30 19:29:56 on Problem 1026
#include <stdio.h>
#include <map>
using namespace std;
#define MAX 202
int main()
{
	int i , j , k , n , c[MAX] , d[MAX] , e[MAX][MAX];
	char a[MAX] , b[MAX];
	map<int, int> m;
	map<int, int>::iterator it;	
	while(scanf("%d" ,&n) && n)
	{
		m.clear();
		for(i = 0;i < n;i++)
			scanf("%d" ,&c[i]);
		int count = 0 ,t;
		for(i = 0;i < n;i++)
		{
			count = 1;
			e[i][0] = t = c[i];
			for(j = 1;t != i + 1;j++)
			{
				count++;
				e[i][j] = t = c[t - 1];
			}
			d[i] = count;
			m[count] = count;
		}
		long int num = 1;
		for(it = m.begin();it != m.end();it++)
			num *= it->second;
		while(scanf("%d" ,&k) && k)
		{
			k %= num;
			scanf("%c");
			gets(a);			
			
			for(i = 0;i < n;i++)
				b[i] = ' ';
			for(i = 0;a[i] != '\0';i++)								
				b[((k % d[i] == 0) ? t = i : t = e[i][(k % d[i] - 1)] - 1 ,t)] = a[i];			
			puts(b);	
		}
		printf("\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