zoukankan      html  css  js  c++  java
  • HDU 1039.Easier Done Than Said?-条件判断字符串

    Easier Done Than Said?

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 16543    Accepted Submission(s): 7846


    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.
     
    Source
     

    代码:

     1 #include<stdio.h>
     2 #include<string.h>
     3 int main(){
     4     char a[100];
     5     int i,num,flag,len;
     6     int b[100];
     7     while(~scanf("%s",&a)&&strcmp("end",a)){
     8         for(i=0;i<100;i++)
     9             b[i]=0;
    10             num=0;
    11             flag=1;
    12             len=strlen(a);
    13         for(i=0;i<len;i++){
    14            if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u'){
    15                 b[i]=1;
    16                 num+=1;
    17            }
    18            else
    19                 b[i]=2;
    20         }
    21         for(i=2;i<len;i++){
    22                 if(b[i]==b[i-1]&&b[i-1]==b[i-2]){
    23                     flag=0;
    24                     break;
    25                 }
    26         }
    27         for(i=1;i<len;i++){
    28                 if(a[i]==a[i-1]&&a[i]!='e'&&a[i]!='o'){
    29                     flag=0;
    30                     break;
    31                 }
    32         }
    33         if(num==0||flag==0)
    34             printf("<%s> is not acceptable.
    ",a);
    35         else
    36             printf("<%s> is acceptable.
    ",a);
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    each和foreach的区别
    apply和call的用法
    js小知识点
    关于react的一些疑问点
    c语言字符动画的实现
    解决'chromedriver' executable needs to be in PATH问题!
    二叉树的创建和遍历
    dns和dhcp
    编写一个application程序实现如下功能:接受命令行中给出的一个字符串,先将字符串原样输出,然后判断该穿的第一个字母是否为大写,若是大写则统计该串中大写字母的个数,并将所有大写字母输出。
    学生成绩管理系统究极版
  • 原文地址:https://www.cnblogs.com/ZERO-/p/9740505.html
Copyright © 2011-2022 走看看