Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- int m,n,i,j,k,cnt=0,temp;
- cin>>n;
- cin>>m;
- string str[m],temp1;
- int ar[m]= {0};
- for(i=0; i<m; i++)
- {
- cin>>str[i];
- for(j=0; j<n; j++)
- {
- for(k=j+1; k<n; k++)
- {
- if(str[i][j]>str[i][k])
- ar[i]++;
- }
- }
- }
- for(i=0; i<m; i++)
- {
- for(j=0; j<m-i-1; j++)
- {
- if(ar[j]>ar[j+1])
- {
- temp=ar[j];
- ar[j]=ar[j+1];
- ar[j+1]=temp;
- temp1=str[j];
- str[j]=str[j+1];
- str[j+1]=temp1;
- }
- }
- }
- for(i=0; i<m; i++)
- {
- cout<<str[i]<<" "<<ar[i]<<endl;
- }
- }
- }
Add Comment
Please, Sign In to add comment