题目:给你一个小写字符串,判断是否安全,安全规则如下:
1.包含元音字母;2.相邻3个元素不能都是元音或辅音;3.连续2个字母相同之能是o或e。
分析:简单题。直接模拟即可。
说明:今天有点累╮(╯▽╰)╭,要学的东西好多( ⊙ o ⊙ )啊!
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <cmath> using namespace std; int f(char c) { return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); } char buf[32]; int main() { while (gets(buf) && strcmp(buf, "end")) { int flag = 0; for (int i = 0 ; buf[i] ; ++ i) if (f(buf[i])) flag = 1; for (int i = 2 ; buf[i] ; ++ i) { if (f(buf[i])&&f(buf[i-1])&&f(buf[i-2])) flag = 0; if (!f(buf[i])&&!f(buf[i-1])&&!f(buf[i-2])) flag = 0; } for (int i = 1 ; buf[i] ; ++ i) if (buf[i] == buf[i-1] && buf[i] != 'e' && buf[i] != 'o') flag = 0; if (flag) printf("<%s> is acceptable.\n",buf); else printf("<%s> is not acceptable.\n",buf); } return 0; }
hdu 1039 - Easier Done Than Said?
原文:http://blog.csdn.net/mobius_strip/article/details/43678033