299
小水题一个,增加点题量用
//============================================================================ // Name : 299.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <cstdio> #include <algorithm> using namespace std; int a[100]; int n, ans, N; int main() { freopen("a.txt", "r", stdin); scanf("%d", &N); while(N--){ scanf("%d", &n); for(int i = 0;i < n;i++){ scanf("%d", &a[i]); } ans = 0; for(int i = n-1;i >= 0;i--){ for(int j = 0;j < i;j++){ if(a[j] > a[j+1]){ swap(a[j], a[j+1]); ans++; } } } printf("Optimal train swapping takes %d swaps.\n", ans); } return 0; }