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 freshvictor at 2010-06-16 01:00:12 on Problem 1026
#include <iostream>
using namespace std;
int GetStepByPosi(int *a, int loop, int posi)
{
	int pRst = posi;
	for (int j = 0; j < loop; j++)
	{
		pRst = a[pRst] - 1;
		if (pRst == posi)
			return ++j;
	}
	return 0;
}
int input(int n)
{
	int a[256], loop;
	char inputStr[256], str[256], tempStr[256];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	while (cin >> loop, loop != 0)
	{
		getchar();
		gets_s(inputStr);
		for (int i = 0; i < n; i++)
			str[i] = ' ';
		for (int i = 0; i < (int)strlen(inputStr); i++)
				str[i] = inputStr[i];
		str[n] = '\0';
		strcpy_s(tempStr, str);
		for (int i = 0; i < n; i++)
		{
			int Step = GetStepByPosi(a, n, i);
			int ploop = loop%Step;
			int pRst = i;
			for (int j = 0; j < ploop; j++)
				pRst = a[pRst] - 1;
			str[pRst] = tempStr[i];
		}
		cout << str << endl;
	}


        //我如何没料到原来是这个换行,非加不可
	cout << endl;
	return 1;
}
int main()
{
	int n;
	while (cin >> n, n != 0)
		input(n);
	return 1;
}

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