Saturday, July 12, 2014

UVa - 10327 - Flip Sort

#include <iostream>
using namespace std;

int main(){
    int t, n[1003], ans, temp;
    while(cin >> t){
        for(int i = 0; i < t; i++)cin >> n[i];
        ans = 0;
        for(int i = 0; i < t; i++)
            for(int j = 0; j < t-1; j++)
                if(n[j] > n[j+1]){
                    temp = n[j];
                    n[j] = n[j+1];
                    n[j+1] = temp;
                    ans++;
                }
        cout << "Minimum exchange operations : " << ans << endl;
    }
    return 0;
}

No comments:

Post a Comment