提交时间:2023-11-12 17:34:19

运行 ID: 110145

#include <bits/stdc++.h> using namespace std; string s[100000]; int ha(string s) { int cnt = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == '1') { cnt++; } } return cnt; } bool cmp(string a, string b) { if (a.size() != b.size()) { return a.size() < b.size(); } int x, y; x = ha(a); y = ha(b); if (x != y) { return x < y; } return a < b; } int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> s[i]; } sort(s, s + n + 1, cmp); for (int i = 1; i <= n; i++) { cout << s[i] << endl; } return 0; }