zjut1204
Code
#include<iostream>
#include<set>
#include<string>
#include<algorithm>
using namespace std;
struct comp
{
bool operator () (const string &s1,const string &s2)
{
if(s1.length()!=s2.length()) return s1.length()<s2.length();
int c1=count(s1.begin(),s1.end(),'1');
int c2=count(s2.begin(),s2.end(),'1');
if(c1!=c2) return c1<c2;
return s1<s2;
}
};
int main()
{
multiset<string,comp>ms;
string s;
while(cin>>s){
ms.insert(s);
}
multiset<string,comp>::iterator it;
for(it=ms.begin();it!=ms.end();it++)
cout<<*(it)<<endl;
return 0;
}
posted on
2009-05-10 22:35
pandy
阅读(
212)
评论()
编辑
收藏
举报