Advertisement
Farjana_akter

Untitled

Feb 8th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int t,i,j,l,temp,count=0,k,a[150],n;
  7. cin>>t;
  8. for(l=1;l<=t;l++)
  9. {
  10. cin>>n;
  11. count=0;
  12. for(i=1;i<=n;i++)
  13. cin>>a[i];
  14. for(i=1;i<=n;i++)
  15. {
  16. if(a[i]!=i)
  17. {
  18. for(j=i+1;j<=n;j++)
  19. {
  20. if(a[j]==i)
  21. {
  22. temp=a[j];
  23. a[j]=a[i];
  24. a[i]=temp;
  25. count++;
  26. }
  27. }
  28. }
  29. }
  30. cout<<"Case "<<l<<": "<<count<<endl;
  31. }
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement