提交时间:2023-11-11 10:08:01

运行 ID: 109725

#include <bits/stdc++.h> using namespace std; string a[55]; bool cmp(string x , string y) { int x1 = x.length(), y1 = y.length(); int x0 = 0, y0 = 0; if(x1 < y1) return true; else if(x1 == y1) { for(int i = 0;i < x1;i++) { if(x[i] == '1') x0++; } for(int i = 0;i < y1;i++) { if(y[i] == '1') y0++; } if(x0 < y0) return true; else if(x0 > y0) return false; else if(x < y) return true; else return false; } return false; } int main() { // freopen("strand.in" , "r" , stdin); // freopen("strand.out", "w" , stdout); int n; cin >> n; for(int i = 1;i <= n;i++) cin >> a[i]; sort(a + 1 , a + n + 1 , cmp); for(int i = 1;i <= n;i++) cout << a[i] << endl; return 0; }