第14届浙江大学程序设计竞赛 I. ?(>_o)! (ZOJ 3775)

来源:互联网 发布:7u分享网络赚一元 编辑:程序博客网 时间:2024/06/04 23:49

【来源】

ZOJ 3775 ?(>_o)!

【分析】

模拟题。忽略题目中的废话,提取出两个关键点,一是对“_”的处理,一是对“!”的处理。

【源码】

#include <iostream>#include <string>#include <cstdio>using namespace std;int main(){    int T;    cin >> T;    getchar();    while (T--){        string s;        string out = "";        getline(cin, s);        for (int i = 0; i < s.size(); ++i){            if (s[i] == '_'){                out += s;            }            if (s[i] == '!'){                out += "Hello, world!";            }        }        if (s == out){            cout << "Yes" << endl;        }        else{            cout << "No" << endl;        }    }    //system("pause");    return 0;}

【点评】

另一种思路:

归纳起来,"Yes"的情况只有两种:"Hello, world!"或者一个不含"!"且仅含一个"_"的字符串。但是这种思路会判定答案错误。目前不知道是什么原因。欢迎留言探讨。

0 0