View Code of Problem 143

#include <bits/stdc++.h>
using namespace std;
 
struct Zda{
    string data;
    int len;
}zda[105];
 
bool cmp(Zda a, Zda b){
    return a.len < b.len;
}
int n,m;
int nixu(string s){
 
    int sum = 0;
    for(int i= 0; i< n; i++){
        for(int j = i+1; j<n; j++){
            if(s[i]>s[j]){
                sum++;
            }
        }
    }
 
    return sum;
}
 
int main(){
 
    
    while(cin>>n>>m){
            for(int i = 0; i<m; i++){
        cin>>zda[i].data;
        zda[i].len =nixu(zda[i].data);
    }
 
    stable_sort(zda, zda+m, cmp);
 
    for(int i = 0; i<m; i++){
        cout<<zda[i].data<<endl;
        
    }
    }
 
 
 
    return 0;
}
/*
Main.cc:2:25: bits/stdc++.h: No such file or directory
Main.cc:6: error: `string' does not name a type
Main.cc:14: error: `string' was not declared in this scope
Main.cc:14: error: expected `,' or `;' before '{' token
Main.cc: In function `int main()':
Main.cc:31: error: `cin' undeclared (first use this function)
Main.cc:31: error: (Each undeclared identifier is reported only once for each function it appears in.)
Main.cc:33: error: 'struct Zda' has no member named 'data'
Main.cc:34: error: 'struct Zda' has no member named 'data'
Main.cc:34: error: `nixu' cannot be used as a function
Main.cc:37: error: `stable_sort' undeclared (first use this function)
Main.cc:40: error: `cout' undeclared (first use this function)
Main.cc:40: error: 'struct Zda' has no member named 'data'
Main.cc:40: error: `endl' undeclared (first use this function)
*/

Double click to view unformatted code.


Back to problem 143