Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- using namespace std;
- int n;
- string arr[1001];
- bool comp(string a, string b){
- if(a.size()!=b.size())
- return a.size()<b.size();
- else {
- int x=0,y=0;
- for(int i=0; i<a.size(); i++) {
- if(a[i]>=49 && a[i]<=57) {
- x+=a[i]-48;
- }
- }
- for(int i=0; i<b.size(); i++) {
- if(b[i]>=49 && b[i]<=57) {
- y+=b[i]-48;
- }
- }
- if(x == y) {
- if(a.compare(b)<0)
- return true;
- return false;
- }
- return x<y;
- }
- }
- int main() {
- cin>>n;
- for(int i=0; i<n; i++) {
- cin>>arr[i];
- }
- sort(arr, arr+n, comp);
- for(int i=0; i<n; i++) {
- cout<<arr[i]<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement