Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <algorithm>
- using namespace std;
- pair <int , int > p[500000];
- int main (){
- int n;
- cin >> n;
- for (int i = 0; i < n; i++){
- int x, sum = 0;
- cin >> x;
- int e = x;
- while (e != 0){
- sum+=e %10;
- e/=10;
- }
- p[i].first= sum;
- p[i].second = x;
- }
- sort(p, p + n);
- for (int i = 0; i < n; i++){
- cout << p[i].second << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement