Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int n,p;
- int y=0;
- int a[101];
- cin>>p;
- for(int b=0;b<p;b++){
- cin>>n;
- for(int i=0;i<n;i++){
- cin>>a[i]; //filling array
- }
- int x=0;
- for(int i=0;i<n-1;++i)
- {
- int j=i;
- for(int c=i;c<n;++c)
- if(a[c]<a[j])
- j=c; //here we find the position which has the min value
- int A=i; int B=j;
- while(A<B)
- {
- int temp=a[A];
- a[A]=a[B];
- a[B]=temp;
- ++A;
- --B;
- }
- x+=j-i+1;
- }
- cout<<"Case #"<<b+1<<": "<<x<<'\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment