#include<stdio.h>
#include<vector>
#include<string>
#include<fstream>
#include<algorithm>//include count
#include<iostream>
using namespace std;
vector<string>v;
vector<string>::iterator it;
bool cmp(string s1,string s2)
{
if(s1.length()<s2.length())return true;
int c1=count(s1.begin(),s1.end(),'1');
int c2=count(s2.begin(),s2.end(),'1');
if(c1<c2)return true;
if(s1<s2)return true;
}
int main()
{
ifstream cin("C.txt");
string s;
int i=0;
while(cin>>s)
i++,v.push_back(s);
for(it=v.begin();it!=v.end();it++)
cout<<*it<<endl;
return 0;
}
关键语句:sort(v.begin(),v.end(),cmp);//sort的vector 排序