Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
110145 朱悦晨 01串排序 C++ 通过 100 2 MS 3380 KB 594 2023-11-12 17:34:19

Tests(4/4):


#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; }


测评信息: