harrypotter0's blog

By harrypotter0, history, 7 years ago, In English

Sample Input 0

6 31415926535897932384626433832795 1 3 10 3 5

Sample Output 0

1 3 3 5 10 31415926535897932384626433832795

my solution

include <bits/stdc++.h>

using namespace std; int main() { long long int n,i,a,s=0,m ; string str[201202]; cin>>n; for(i=0;i<n;i++) cin>>str[i]; sort(str,str+n); for(i=0;i<n;i++) { cout<<str[i]; } return 0; }

But i am getting this as output (attached ) Any help will be highly appreciated :)

  • Vote: I like it
  • -14
  • Vote: I do not like it

»
7 years ago, # |
  Vote: I like it +4 Vote: I do not like it

I guess you are asking about this problem : https://www.hackerrank.com/contests/w29/challenges/big-sorting

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I won't give solution, but just hint: use comparator.

»
7 years ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

you need:

bool cmp(const string& p, const string& q){
    return p.size() < q.size() or p.size() == q.size() and p < q;
}

//and later in your main...

sort(str, str+n, cmp);

good luck. (Y)