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 hot at 2005-05-16 23:23:30 on Problem 1026
#include <iostream>
#include <string>
#include <cassert>
#include <cstdlib>

using namespace std;

int main()
{
	int n, loop;
	int i, j;

	cin >> n;
	string message(n, ' ');
	string message2(n, ' ');

	int * num = new int [n];
	int * ntemp = new int [n];
	assert( num != 0 && ntemp != 0);

	for (i = 0; i < n; i++)
		cin >> num[i];

	while(1){
		cin >> loop;
		cin.ignore();
		char c[201];
		cin.getline(c, 200);
		for (i = 0; i < strlen(c); i++)
			message[i] = c[i];
//		getline(cin, message);

		if (loop == 0 && message[0] == '0' && strlen(c) == 1){
			delete [] num;
			delete [] ntemp;
			return 0;
		}

		for (i = 0; i < n; i++){
			ntemp[i] = i + 1;
		}

		for (i = 0; i < loop; i++) {
			for (j = 0; j < n; j++){
				ntemp[j] = num[ntemp[j] - 1];
			}
		}

		for (i = 0; i < n; i++){
			message2[ntemp[i] - 1] = message[i];
		}
		for (i = 0; i < n; i++)
			cout << message2[i];

		cout << endl;

		message = string(n, ' ');
	}
}

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