Untitled
unknown
plain_text
2 years ago
1.2 kB
6
Indexable
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
pair<string, int> a[500000];
string smax(string a, string b){
int la = a.size(), lb = b.size(), m = 0, n = 0;
while((m < la) && (a[m] == '0')) m++;
while((n < lb) && (b[n] == '0')) n++;
la -= m; lb -= n;
if(la > lb) return a;
else if(la < lb) return b;
else{
for(int i = 0; i < la; i++){
if(a[m+i] > b[n+i]) return a;
else if(a[m+i] < b[n+i]) return b;
}
return "=";
}
}
int cmp(pair<string, int> a, pair<string, int> b){
string s = smax(a.first, b.first);
if(s == "=") return a.second < b.second;
else return s == b.first;
}
int main() {
string s, tmp; cin >> s;
int n = 0;
for(int i = 0; i < s.size(); i++){
tmp = "";
while(isdigit(s[i]))
tmp += s[i++];
if(tmp != ""){
a[n] = make_pair(tmp,n);
n++;
}
}
sort(a, a+n, cmp);
for(int i = 0; i < n; i++) cout << a[i].first << " " ;
cout << endl;
return 0;
}Editor is loading...
Leave a Comment