HDU2689

简单模拟

View Code
 1 #include<stdio.h>
 2 #include<algorithm>
 3 using namespace std;
 4 int main(){
 5     int a[ 1001 ];
 6     int cnt;
 7     int n;
 8     while( scanf("%d",&n)!=EOF ){
 9         for( int i=0;i<n;i++ )
10             scanf("%d",&a[ i ]);
11         cnt=0;
12         for( int i=0;i<n-1;i++ ){
13             for( int j=i;j<n;j++ ){
14                 if( a[ i ]>a[ j ]){
15                     cnt++;
16                     swap( a[ i ],a[ j ] );
17                 }
18             }
19         }
20         printf("%d\n",cnt);
21     }
22     return 0;
23 }
keep moving...
原文地址:https://www.cnblogs.com/xxx0624/p/2883336.html