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

同崩溃!!WA哭

Posted by trueshlqsh at 2007-10-19 22:14:42 on Problem 1674
我直接用的选择排序+计数。。还是WA!!!!!想不通。。好心人帮忙看看。。谢谢拉
#include <iostream>
#include <cstdio>
using namespace std;

long t,n;
long data[10011];
long ans;

int main()
{
	long i,temp,j,k;
	
	cin>>t;
	for (i=1;i<=t;i++)
	{
		cin>>n;
		for (i=1;i<=n;i++) scanf("%d",&data[i]);
        ans=0;
        for (i=1;i<=n;i++)
        if (data[i]!=i)
        {
			for (j=i+1;j<=n;j++)
			if (data[j]==i) break;
			temp=data[i];
			data[i]=data[j];
			data[j]=temp;
			ans++;
		}
	    cout<<ans<<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