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 <stdio.h> int main() { long t,n,i,j,temp,sum,count=1,a[1005]; scanf("%d",&t); while (t--) { sum=0; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); for (i=0;i<n;i++)//从后向前 { for (j=n-1;j>i;j--) { if (a[j]<a[j-1]) { temp=a[j]; a[j]=a[j-1]; a[j-1]=temp; sum++; } } } printf ("Scenario #%d:\n%d\n\n",count++,sum); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator