问题 1417 --按1的个数排序(完善程序)

1417: 按1的个数排序(完善程序)★★

时间限制: 1 Sec  内存限制: 128 MB
提交: 1661  解决: 1165
[提交][状态][命题人:]

题目描述

有一些数字字串,将其按1的个数的多少的顺序进行输出,若1的个数相同,则按ASCII顺序从小到大输出

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
vector<string> arr;//字符串向量 
bool cmp(string a, string b)
{
    int ca=count(a.begin(),a.end(),'1');
    ______(1)___________ 
    if(ca!=cb)
    return ca<cb;
    ______(2)___________ 
}
int main()
{
    string pp;
    while(cin>>pp)
    {
        arr.push_back(pp);
    }
    sort(arr.begin(),arr.end(),cmp);
    for(int i=0;i<arr.size();i++)
    {
        ______(3)__________
    }
    return 0;
}


输入

每行输入一个数字字串

输出

输出排列结果
样例输入
Copy
10011111
00001101
1010101
1
0
1100
样例输出
Copy
0
1
1100
00001101
1010101
10011111

提示

来源

 

[提交][状态]