Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
AC 了 用选择排序就好了啊#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator