Description
Input
Output
Sample Input
4 4 2 8 0 3 10 0 1 2 3 4 5 6 7 8 9 6 -42 23 6 28 -100 65537 5 0 0 0 0 0
Sample Output
Scenario #1: 3 Scenario #2: 0 Scenario #3: 5 Scenario #4: 0
1 #include<iostream> 2 #include<vector> 3 using namespace std; 4 int main() 5 { 6 int N; 7 cin >> N; 8 static int ci = 1; 9 while (N) 10 { 11 int M; 12 cin >> M; 13 vector<int> vet(M); 14 for (int i = 0; i < M; i++) 15 { 16 cin >> vet[i]; 17 } 18 int count = 0; 19 for (int i = 0; i<M - 1; i++) 20 { 21 for (int j = M - 1; j >i; j--) 22 { 23 if (vet[j] < vet[j - 1]) 24 { 25 swap(vet[j], vet[j - 1]); 26 count++; 27 } 28 } 29 } 30 31 cout << "Scenario #" << ci << ":" << endl; 32 cout<<count << endl; 33 cout << endl; 34 ci++; 35 N--; 36 } 37 system("pause"); 38 return 0; 39 }
原文:http://www.cnblogs.com/wujufengyun/p/7064623.html