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

AC 了 用选择排序就好了啊

Posted by 382784268 at 2009-02-23 23:35:30 on Problem 1674
#include<iostream>
using namespace std;
int main()
{
	int d;
	cin>>d;
	while(d--)
	{
		int n;
		int* p;
		cin>>n;
		p=new int[n];
		int i,j;
		for(i=0;i<n;i++)
		  cin>>p[i];
		int s=0;
		for(i=0;i<n;i++)
		{
			int min=p[i];
			int k;
			for(j=i;j<n;j++)
			{
				if(p[j]<min)
				{
					min=p[j];
					k=j;
				}
			}
			if(min!=p[i])
			{
				int t=p[i];
				p[i]=min;
				p[k]=t;
				s++;
			}
		}
		cout<<s<<endl;
	}
	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