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?

Posted by mato_no1 at 2011-09-17 10:15:11 on Problem 1026
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define re(i, n) for (int i=0; i<n; i++)
#define re2(i, l, r) for (int i=l; i<r; i++)
const int MAXN = 210;
int n, A[MAXN], C[MAXN], K;
bool F[MAXN];
char ss[MAXN], res[MAXN];
void solve()
{
	int j, s, k0, P;
	re(i, n) F[i] = 0;
	re(i, n) if (!F[i]) {
		F[i] = 1; j = A[i]; s = 1; C[0] = i;
		while (j != i) {F[j] = 1; C[s++] = j; j = A[j];}
		k0 = K % s;
		re(i, s) {
			P = i - k0;
			if (P < 0) P += s;
			res[C[i]] = ss[C[P]];
		}
	}
}
int main()
{
	char ch, len;
	bool SPC = 0;
	while (1) {
		scanf("%d", &n); if (!n) break;
		re(i, n) {scanf("%d", &A[i]); A[i]--;}
		if (SPC) puts(""); else SPC = 1;
		while (1) {
			scanf("%d", &K); if (!K) break;
			ch = getchar(); gets(ss); len = strlen(ss);
			re2(i, len, n) ss[i] = ' '; ss[n] = 0;
			solve();
			re(i, n) putchar(res[i]); 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