Adrita

task 4( ds lab 3) 3rd sem

Jan 22nd, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t;
  6. cin>>t;
  7. while(t--)
  8. {
  9. int m,n,i,j,k,cnt=0,temp;
  10. cin>>n;
  11. cin>>m;
  12. string str[m],temp1;
  13. int ar[m]= {0};
  14. for(i=0; i<m; i++)
  15. {
  16. cin>>str[i];
  17. for(j=0; j<n; j++)
  18. {
  19. for(k=j+1; k<n; k++)
  20. {
  21. if(str[i][j]>str[i][k])
  22. ar[i]++;
  23. }
  24. }
  25. }
  26. for(i=0; i<m; i++)
  27. {
  28. for(j=0; j<m-i-1; j++)
  29. {
  30. if(ar[j]>ar[j+1])
  31. {
  32. temp=ar[j];
  33. ar[j]=ar[j+1];
  34. ar[j+1]=temp;
  35.  
  36. temp1=str[j];
  37. str[j]=str[j+1];
  38. str[j+1]=temp1;
  39. }
  40. }
  41. }
  42. for(i=0; i<m; i++)
  43. {
  44. cout<<str[i]<<" "<<ar[i]<<endl;
  45. }
  46. }
  47.  
  48.  
  49. }
Add Comment
Please, Sign In to add comment