提交时间:2023-11-14 13:17:56
运行 ID: 110295
# include <bits/stdc++.h> using namespace std ; struct s01 { long long g1 ; string str ; } ; s01 a [114514] ; long long chk ( string s ) { long long cnt ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { if ( s [i] == '1' ) { cnt ++ ; } } return cnt ; } bool cmp ( s01 a , s01 b ) { if ( a . str . size ( ) != b . str . size ( ) ) { return a . str . size ( ) < b . str . size ( ) ; } else if ( a . g1 != b . g1 ) { return a . g1 < b . g1 ; } else { return a . str < b . str ; } } int main ( ) { long long n ; cin >> n ; for ( long long i = 1 ; i <= n ; i ++ ) { cin >> a [i] . str ; a [i] . g1 = chk ( a [i] . str ) ; } sort ( a + 1 , a + n + 1 , cmp ) ; for ( long long i = 1 ; i <= n ; i ++ ) { cout << a [i] . str ; cout << endl ; } return 0 ; }