提交时间:2023-11-11 10:54:20

运行 ID: 109802

#include<iostream> #include<string> #include<algorithm> using namespace std; struct Str{ string s; int siz, o; void input(){ cin >> s; siz = s.size(); o = 0; for(int i = 0; i < siz; i++){ o += s[i] - '0'; } } } st[60]; bool cmp(Str a, Str b){ if(a.siz == b.siz){ if(a.o == b.o){ return a.s < b.s; } return a.o < b.o; } return a.siz < b.siz; } int main(){ // freopen("strand.in", "r", stdin); // freopen("strand.out", "w", stdin); int n; cin >> n; for(int i = 0; i < n; i++){ st[i].input(); } sort(st, st + n, cmp); for(int i = 0; i < n; i++){ cout << st[i].s << endl; } return 0; }