zoukankan      html  css  js  c++  java
  • 字符串水题(hdoj1049)

    Problem 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.
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 using namespace std;
     5 char b[5]={'a','e','i','o','u'},c[21]={'b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z'};
     6 char d[]={'a','i','u','b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z'};
     7 char a[21];
     8 int len;
     9 int vowels()
    10 {
    11     int i,k,j;
    12     int flag;
    13     for(i=0;i<len-2;i++)
    14     {
    15         flag=0;
    16         for(j=0;j<3;j++)
    17         {
    18             for(k=0;k<5;k++)
    19             {
    20                 if(a[i+j]==b[k])
    21                 {
    22                     flag++;
    23                     break;
    24                 }
    25             }
    26         }
    27         if(flag==3)
    28             return 0;
    29     }
    30     return 1;
    31 }
    32 int consonants()
    33 {
    34     int i,k,j;
    35     int flag;
    36     for(i=0;i<len-2;i++)
    37     {
    38         flag=0;
    39         for(j=0;j<3;j++)
    40         {
    41             for(k=0;k<21;k++)
    42             {
    43                 if(a[i+j]==c[k])
    44                 {
    45                     flag++;
    46                     break;
    47                 }
    48             }
    49         }
    50         if(flag==3)
    51             return 0;
    52     }
    53     return 1;
    54 }
    55 int consecutive_occurrences()
    56 {
    57     int i,j,k;
    58     bool flag;
    59     for(i=0;i<len-1;i++)
    60     {
    61         flag=0;
    62         if(a[i]==a[i+1])
    63         {
    64             for(j=0;j<24;j++)
    65                 if(a[i]==d[j])
    66                 {
    67                     flag=1;
    68                     break;
    69                 }
    70         }
    71         if(flag)
    72             return 0;
    73     }
    74     return 1;
    75 }
    76 int main()
    77 {
    78     char b[4]="end";
    79     while(cin>>a)
    80     {
    81         getchar();
    82         if(strcmp(a,b)==0)
    83             break;
    84         len=strlen(a);
    85         int k=0;
    86         if((strchr(a,'a')!=NULL)||(strchr(a,'e')!=NULL)||(strchr(a,'i')!=NULL)||(strchr(a,'o')!=NULL)||(strchr(a,'u')!=NULL))
    87             k++;
    88         if(vowels()&&consonants())
    89             k++;
    90         if(consecutive_occurrences ())
    91             k++;
    92         if(k==3)
    93             cout<<'<'<<a<<'>'<<" is acceptable."<<endl;
    94         else
    95             cout<<'<'<<a<<'>'<<" is not acceptable."<<endl;
    96         memset(a,0,sizeof(a));
    97     }
    98 }
  • 相关阅读:
    线段树时间分治
    CDQ分治
    并查集练习
    hihocoder 1513 小Hi的烦恼 (bitset优化)
    线段树维护哈希
    使用swift语言进行IOS应用开发
    用jquery+Asp.Net实现省市二级联动
    苹果IOS与谷歌 android系统的UI设计原则
    优秀设计师应当知道的20大UI设计原则
    JQuery Easy Ui dataGrid 数据表格
  • 原文地址:https://www.cnblogs.com/a1225234/p/4545285.html
Copyright © 2011-2022 走看看