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:为什么run time error 啊?求救!!大虾帮忙!!

Posted by cpp050300448135 at 2005-05-11 02:30:52 on Problem 1026
In Reply To:Re:为什么run time error 啊?求救!!大虾帮忙!! Posted by:cpp050300448135 at 2005-05-11 02:27:27
这是第一个最短得程序,但是效率不高,因为其中用了二重循环……而且比如,1995那个数据,我是硬循环出来得……显然不行……
#include<iostream>
#include<string>
using namespace std;
string reset(int *array, string str, int num)
{
	string result;
	result.resize(num, ' ');
	str.resize(num, ' ');
	for(int i=0; i<num; i++)
		result[array[i]-1]=str[i];
	return result;
}
void main()
{
	int * array, num, k;
	string str;
	while(1)
	{
		cin>>num;
		if(num==0) break;
			array=new int[num];
		for(int i=0; i<num; i++)
				cin>>array[i];
		for(;;)
		{
			cin>>k;
			if(k==0) break;
			cin.ignore(1,'\n');
			getline(cin, str);
			for(i=0; i<k; i++)
				str=reset(array, str, num);
			cout<<str;
		}
		if(k==0) cin>>num;
		if(num==0) break;
	}
}

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