HDU5007-Post Robot

题目链接


题意:出现Apple、iPod、iPhone、iPad时输出MAI MAI MAI!,出现Sony,输出SONY DAFA IS GOOD!

思路:水题,直接暴力求解

代码:

#include 
#include 
#include 
#include 
#include 

using namespace std;

int main() {
    string s;
    while (cin >> s) {
        int l = s.length();
        for (int i = 0; i < l; i++) {

            string a = s.substr(i, 4);
            if (a == "iPod" || a == "iPad") {
                printf("MAI MAI MAI!\n"); 
            }
            else if (a == "Sony") {
                printf("SONY DAFA IS GOOD!\n"); 
            }

            string b = s.substr(i, 5);
            if (b == "Apple") {
                printf("MAI MAI MAI!\n"); 
            }

            string c = s.substr(i, 6);
            if (c == "iPhone") {
                printf("MAI MAI MAI!\n"); 
            }
        }
    }
    return 0;
}


你可能感兴趣的:(搜索-暴力-枚举,数据结构-字符串)