7-17 字符串排序

本题要求编写程序,读入5个字符串,按由小到大的顺序输出。

输入格式:
输入为由空格分隔的5个非空字符串,每个字符串不包括空格、制表符、换行符等空白字符,长度小于80。

输出格式:
按照以下格式输出排序后的结果:

After sorted:
每行一个字符串
输入样例:
red yellow blue black white
输出样例:
After sorted:
black
blue
red
white
yellow

ACCODE

#include 

using namespace std;

int main(){
    vector<string> s;
    for(int i=0;i<5;i++){
        string c;
        cin>>c;
        s.push_back(c);
    }
    sort(s.begin(),s.end());
    cout<< "After sorted:" <<endl;
    for(int j=0;j<4;j++){
        cout<<s[j]<<endl;
    }
    cout<<s[4];
    return 0;
}


你可能感兴趣的:(PTA_c++,c++,算法,开发语言)