POJ 1575 Easier Done Than Said?(내 수제의 길 - 삼중 표기)

Easier Done Than Said?
Time Limit: 1000MS
 
Memory Limit: 10000K
Total Submissions: 3387
 
Accepted: 1873
Description
Password security is a tricky thing. Users prefer simple passwords that are easy to remember (like buddy), but such passwords are often insecure. Some sites use random computer-generated passwords (like xvtpzyo), but users have a hard time remembering them and sometimes leave them written on notes stuck to their computer. One potential solution is to generate "pronounceable"passwords that are relatively secure but still easy to remember. 
FnordCom is developing such a password generator. You work in the quality control department, and it's your job to test the generator and make sure that the passwords are acceptable. To be acceptable, a password must satisfy these three rules: 
It must contain at least one vowel. 
It cannot contain three consecutive vowels or three consecutive consonants. 
It cannot contain two consecutive occurrences of the same letter, except for 'ee' or 'oo'. 
(For the purposes of this problem, the vowels are 'a', 'e', 'i', 'o', and 'u'; all other letters are consonants.) Note that these rules are not perfect; there are many common/pronounceable words that are not acceptable. 
Input
The input consists of one or more potential passwords, one per line, followed by a line containing only the word 'end' that signals the end of the file. Each password is at least one and at most twenty letters long and consists only of lowercase letters.
Output
For each password, output whether or not it is acceptable, using the precise format shown in the example.
Sample Input
a
tv
ptoui
bontres
zoggax
wiinq
eep
houctuh
end

Sample Output
<a> is acceptable.
<tv> is not acceptable.
<ptoui> is not acceptable.
<bontres> is not acceptable.
<zoggax> is not acceptable.
<wiinq> is not acceptable.
<eep> is acceptable.
<houctuh> is acceptable.

Source
Mid-Central USA 2000
문제에서 제시한 문자열을 판단하려면 다음과 같은 세 가지 요구에 부합해야 한다. 이 문자열은 AC라고 생각하고, 그렇지 않으면 not AC라고 생각한다.
1) 문자열에 모음이 없으면 안 된다. 즉, a, e, i, o, u
2) 문자열에는 세 개의 모음이나 자음 연속이 있을 수 없습니다.
3) 문자열에는 "ee"와 "oo"를 제외한 두 개의 연속적인 문자가 있을 수 없습니다.
세 가지 표기를 운용하여 각각 세 가지 상황을 표기하다.모든 문자 읽기에 대해 판단하고 조건에 부합되지 않는 것이 있으면 순환을 종료합니다.
참고 사항:
1) 명확한 규정이 없는 문제에서 이런 다중 표기는 매우 번거롭기 때문에 반드시 여러 번 사고방식을 잘 알고 인코딩해야 한다
코드(1AC):
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>

using namespace std;

char availdou[5] = "eo";
char str[30];
int words[26];

int main(void){
    int vowelflag = 0;
    int douflag;
    char douch;
    int tripleflag;
    int len, i;

    for (i = 0; i < 26; i++){
        if ('a' + i == 'a' ||'a' + i == 'e' || 'a' + i == 'i' || 'a' + i == 'o' || 'a' + i == 'u'){
            words[i] = 1;
        }

        else{
            words[i] = 0;
        }
    }
    while (scanf("%s", str), strcmp(str, "end") != 0){
        vowelflag = 1;
        douflag = tripleflag = 0;
        douch = '\0';
        len = strlen(str);
        for (i = 0; i < len; i++){
            if (words[str[i] - 'a'] == 1){
                vowelflag = 0;
                if (tripleflag <= 0){
                    tripleflag = 1;
                }
                else if (tripleflag <= 2){
                    tripleflag ++;
                }
                //printf("%d: triple1:%d
", i, tripleflag); if (tripleflag == 3){ break; } if (douch == str[i]){ if (!(douch == 'e' || douch == 'o')){ douflag = 1; break; } } douch = str[i]; } else if (words[str[i] - 'a'] == 0){ if (tripleflag >= 0){ tripleflag = -1; } else if (tripleflag >= -2){ tripleflag --; } //printf("%d: triple2:%d
", i, tripleflag); if (tripleflag == -3){ break; } if (douch == str[i]){ douflag = 1; break; } douch = str[i]; } } if (tripleflag == 3 || tripleflag == -3 || douflag || vowelflag){ printf("<%s> is not acceptable.
", str); } else{ printf("<%s> is acceptable.
", str); } } return 0; }

좋은 웹페이지 즐겨찾기