zoukankan      html  css  js  c++  java
  • 1185:单词排序

    传送门:http://ybt.ssoier.cn:8088/problem_show.php?pid=1185

    1185:单词排序


    时间限制: 1000 ms         内存限制: 65536 KB
    提交数: 4366     通过数: 2140

    【题目描述】

    输入一行单词序列,相邻单词之间由1个或多个空格间隔,请按照字典序输出这些单词,要求重复的单词只输出一次。(区分大小写)

    【输入】

    一行单词序列,最少1个单词,最多100个单词,每个单词长度不超过50,单词之间用至少1个空格间隔。数据不含除字母、空格外的其他字符。

    【输出】

    按字典序输出这些单词,重复的单词只输出一次。

    【输入样例】

    She  wants  to go to Peking University to study  Chinese

    【输出样例】

    Chinese
    Peking
    She
    University
    go
    study
    to
    wants
    

    【来源】


    No

    题目出错了,实际上输入的不只一行。

     

    #include<iostream>
    using namespace std;
    int tot=0;
    string a[150];
    int main(){
        while(cin>>a[++tot]);
        tot--;//注意别把最后一个空白读进来。
        for(int i=1;i<tot;i++)
        {
            int tmp=i;
            for(int j=i+1;j<=tot;j++)
                if(a[j]<a[tmp])tmp=j;
            if(tmp!=i)swap(a[i],a[tmp]);
        }
        for(int i=1;i<=tot;i++)
            if(a[i]!=a[i-1])cout<<a[i]<<endl;
    }
  • 相关阅读:
    JSTL&EL
    Response
    HTTP、Request
    Tomcat、Servlet
    单片机概念及应用
    JQuery高级
    Jquery基础
    JavaScript
    HTML、CSS
    跟着文档学习gulp1.2创建任务(task)
  • 原文地址:https://www.cnblogs.com/jzxnl/p/11104900.html
Copyright © 2011-2022 走看看