安迪的一直有问题 Andy's First Dictionary
  • 板块学术版
  • 楼主Huchangzhi
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/12/21 17:31
  • 上次更新2023/12/21 20:31:02
查看原帖
安迪的一直有问题 Andy's First Dictionary
1031975
Huchangzhi楼主2023/12/21 17:31

安迪的第一个字典 Andy's First Dictionary

题面翻译

输入一个文本,找出所有不同的单词(连续的字母序列),按字典序从小到大输出,单词不区分大小写。

题目描述

PDF

输入格式

输出格式

样例 #1

样例输入 #1

Adventures in Disneyland
Two blondes were going to Disneyland when they came to a fork in the
road. The sign read: "Disneyland Left."
So they went home.

样例输出 #1

a
adventures
blondes
came
disneyland
fork
going
home
in
left
read
road
sign
so
the
they
to
two
went
were
when

我的代码是:

#include <cstdio>
#include <iostream>
#include <set>
#include <string>
#include <sstream>
using namespace std;
int main()
{
    ios::sync_with_stdio(false), cin.tie(0);
    set<string> a;

    string i;
    while (cin >> i)
    {
        string k = "";
        for (char b : i)
        {
            if ((b >= 'A' && b <= 'Z') || (b >= 'a' && b <= 'z'))
            {
                if (b >= 'A' && b <= 'Z')
                {
                    b = b - 'A' + 'a';
                }
                k += b;
            }
        }
        stringstream ss(k);
        a.insert(k);
    }
    for (const string &k : a)
    {
        cout << k << endl;
    }
    return 0;
}
2023/12/21 17:31
加载中...