字符串排序


7-8 字符串排序(20 分)

本題要求編寫程序,讀入5個字符串,按由小到大的順序輸出。

輸入格式:

輸入為由空格分隔的5個非空字符串,每個字符串不包括空格、制表符、換行符等空白字符,長度小於80。

輸出格式:

按照以下格式輸出排序后的結果:

After sorted:
每行一個字符串

輸入樣例:

red yellow blue green white

輸出樣例:

After sorted:
blue
green
red
white
yellow
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int a,b,c;
    string s[5];
    for(a=0;a<5;a++)
    {
        cin>>s[a];
    }
    sort(s,s+5);
    for(a=0;a<5;a++)
    {
        cout<<s[a]<<endl;
    }
    return 0;
 } 

注釋:C++的sort排序;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM