mxdfirst 2022-07-31 09:00 采纳率: 0%
浏览 45

Hello World II 问题

问题遇到的现象和发生背景

Hello World II

Description
现在又有一个人要加入程序员大家庭,他学习上述操作并输出了一行结果,请你检测他输出的“hello world!”是否正确(没有引号)。对他的要求不应该太高,所以你不用管他每一个字母是大写还是小写,只要字母拼写正确,并且 hello 和 world 中间有一个空格,最后有一个英文的感叹号即可。(感叹号后面不允许再有多余字符)


Input
一行字符,表示他的输入


Output
来检测他的输出是否合法,合法输出Yes,否则输出 No。(注意输出时 YesNo 的大小写)


Sample Input 1
HeLLo world!
Sample Output 1
Yes


Sample Input 2
fidg kldf
Sample Output 2
No


Sample Input 3
Helloworld
Sample Output 3
No


Sample Input 4
Hello world!
Sample Output 4
No


Hint
样例1是对的,因为不用在意大小写。样例2的字母拼写有误,样例3中没有空格和感叹号,样例4中空格过多,只能有一个空格。所以 2、3、4样例都是错误的。

问题相关代码,请勿粘贴截图

没做出来,写的太垃圾了,就不放出来了

运行结果及报错内容

与答案不符

我的解答思路和尝试过的方法

判断空格,字母,大小写

我想要达到的结果

如上文output

  • 写回答

4条回答 默认 最新

  • YoungGeeker 2022-07-31 09:43
    关注

    暴力枚举判断即可:
    [C++代码]

    #include <iostream>
    #include <string>
    using namespace std;
     
    int main()
    {
        string s;
        getline(cin, s);
        if (s[0] != 'H' && s[0] != 'h') cout << "No\n";
        else if (s[1] != 'E' && s[1] != 'e') cout << "No\n";
        else if (s[2] != 'L' && s[2] != 'l') cout << "No\n";
        else if (s[3] != 'L' && s[3] != 'l') cout << "No\n";
        else if (s[4] != 'O' && s[4] != 'o') cout << "No\n";
        else if (s[5] != ' ') cout << "No\n";
        else if (s[6] != 'W' && s[6] != 'w') cout << "No\n";
        else if (s[7] != 'O' && s[7] != 'o') cout << "No\n";
        else if (s[8] != 'R' && s[8] != 'r') cout << "No\n";
        else if (s[9] != 'L' && s[9] != 'l') cout << "No\n";
        else if (s[10] != 'D' && s[10] != 'd') cout << "No\n";
        else if (s[11] != '!') cout << "No\n";
        else cout << "Yes\n";
        return 0;
    }
    

    经本人亲测,程序可以跑通。
    如果对你有帮助,还请帮忙点个采纳,谢谢!

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 7月31日

悬赏问题

  • ¥15 需要仿真图,简单的二阶系统实例
  • ¥15 stm32光控照明仿真
  • ¥15 使用人工智能的方法生成满足一定统计参数要求的随机数序列
  • ¥15 SENT协议中相关问题咨询
  • ¥15 URL地址href跳转问题
  • ¥15 mysql数据库备份恢复
  • ¥15 mmdetection mask-rcnn
  • ¥35 Hadoop实训论文成品!标题是云盘开发 价格可私 急
  • ¥25 matlab可以将微分方程的解显示为相图形式吗
  • ¥35 Hadoop实训论文成品!任意标题价格可私急