Ctrl+Z 結束輸入的情況---NOJ1023 ---字符串排序

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
vector <string> st;
bool cmp(const string &s1,const string &s2)
{
    int l1,l2;
    l1=count(s1.begin(),s1.end(),'A');
    l2=count(s2.begin(),s2.end(),'A');
    return l1<l2;
}
int main()
{
    string str;
    while(cin>>str)
        st.push_back(str);
    stable_sort(st.begin(),st.end(),cmp);
    for(int i=0;i<st.size();i++)
    {
        cout<<st[i]<<endl;
    }
    return 0;
}
發佈了141 篇原創文章 · 獲贊 50 · 訪問量 26萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章