Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bool Cmp(const string &a, const string &b) {
- int v1, v2, lenam = a.length()-1, lenbm = b.length()-1, i = 0, j = 0;
- bool chv1 = true, chv2 = true;
- while (1) {
- //cout << "i:" << i << " j:" << j << " ";
- v1 = a.at(i);
- v2 = b.at(j);
- //cout << "v1:" << v1 << " v2:" << v2 << endl;
- if (v1 == v2 && (chv1 || chv2)) {
- if (i < lenam) {
- i++;
- chv1 = true;
- } else {
- chv1 = false;
- }
- if (j < lenbm) {
- j++;
- chv2 = true;
- } else {
- chv2 = false;
- }
- } else {
- break;
- }
- }
- return v1 > v2;
- }
- int main() {
- int n;
- cin >> n;
- vector<string> k;
- for (int i = 0; i < n; ++i) {
- string s;
- cin >> s;
- k.push_back(s);
- }
- sort(k.begin(), k.end(), Cmp);
- for (string s : k) cout << s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement