zoukankan      html  css  js  c++  java
  • hdu 1039 Easier Done Than Said?

    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.

     细节问题,第一个代码就是找不出错误在哪里?

    #include<stdio.h>
    #include<string.h>
      int main ()
        {
        	char s[25];
        	int i,sum,k;
           while(gets(s))
             {
             	if(strcmp(s,"end")==0)  break;
             	i=0;
             	sum=0;
             	k=1;
              while(s[i]!='')
             	{
             	  if(s[i]=='a'||s[i]=='e'||s[i]=='o'||s[i]=='u'||s[i]=='i')
             	     {
             	     	sum++; 
             	     }
    			     
    			  if(s[i]=='a'||s[i]=='e'||s[i]=='o'||s[i]=='u'||s[i]=='i')
    			    {
    			    	if(s[i+1]=='a'||s[i+1]=='e'||s[i+1]=='o'||s[i+1]=='u'||s[i+1]=='i'||s[i+1]!='')
    			    	  {
    			    	  	if(s[i+2]=='a'||s[i+2]=='e'||s[i+2]=='o'||s[i+2]=='u'||s[i+2]=='i'||s[i+2]!='')
    			    	  	   {
    			    	  	   	k=0;
    			    	  	    i++;
    			    	  	    continue;
    			    	  	   }
    			    	  	   
    			    	  }
    			    }
    			      
    			  if(!(s[i]=='a'||s[i]=='e'||s[i]=='o'||s[i]=='u'||s[i]=='i'))
    			    {
    			    	if(!(s[i+1]=='a'||s[i+1]=='e'||s[i+1]=='o'||s[i+1]=='u'||s[i+1]=='i')||s[i+1]!='')
    			    	  {
    			    	  	if(!(s[i+2]=='a'||s[i+2]=='e'||s[i+2]=='o'||s[i+2]=='u'||s[i+2]=='i')||s[i+2]!='')
    			    	  	 {
    			    	  	 	k=0;
    			    	  	    i++;
    			    	  	    continue;
    			    	  	   
    			    	  	 }  
    			    	  }
    			    }
    			   if(s[i]==s[i+1]&&s[i]!='e'&&s[i]!='o'&&s[i+1]!='')
    			       {
    			       	k=0;
    			       	i++;
    			       	continue;
    			       }
    			    i++;
             	}
                    if(sum>=1&&k==1)   
                       {
                       	printf("<%s> is acceptable.
    ",s);
                       }
                     else
                        printf("<%s> is not acceptable
    ",s);
             }
             
            return 0;
        }
    /*#include<stdio.h>
    #include<string.h>
      int number_v(char *s)
        {   int i;
            int sum;
             i=0;
             sum=0;
        	while(s[i]!='')
        	  {
        	  	if(s[i]=='a'||s[i]=='e'||s[i]=='o'||s[i]=='u'||s[i]=='i')
        	  	  sum++;
        	  	  i++;
        	  }
           return sum;
        }
       int is_v(char c)
          {
          	if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
                return 1;
            return 0;
          }
       int is_three(char *s)
         {  int i;
    	    int len;
    	    int t1,t2;
    	      t1=t2=0;
               i=0;
               
            
             len=strlen(s);
         	for(i=0;i<len-2;i++)
         	  {
         	  	if(is_v(s[i])&&is_v(s[i+1])&&is_v(s[i+2]))
         	  	    t1=1;
         	  	if(!is_v(s[i])&&!is_v(s[i+1])&&!is_v(s[i+2]))
         	  	    t1=1;
         	  	if(s[i]==s[i+1]&&s[i+1]!='e'&&s[i+1]!='o')
         	  	    t2=1;
         	  }
         	  if(!t2&&(s[len-1]==s[len-2]&&s[len-2]!='e'&&s[len-2]!='o'))
         	        t2=1;
         	if(!t1&&!t2)     return 1;
         	    return 0;
         }
       
        int main()
           {
           	  char s[25];
           	  while(gets(s))
           	    {
           	    	if(strcmp(s,"end")==0)   break;
           	    	
           	    	if(number_v(s)&&is_three(s))
           	    	    printf("<%s> is acceptable.
    ",s);
           	    	else
           	    	    printf("<%s> is not acceptable.
    ",s);
           	    }
           	return 0;
           }*/

  • 相关阅读:
    基于傅里叶变换的音频重采样算法 (附完整c代码)
    自动曝光修复算法 附完整C代码
    3D Lut 电影级调色算法 附完整C代码
    之于图片主色调提取算法
    并发中的各种锁
    算法---BitMap
    高级数据结构---堆树和堆排序
    高级数据结构---赫(哈)夫曼树及java代码实现
    域名和服务器绑定及https协议更换
    高级数据结构---B树和B+树及mysql索引分析
  • 原文地址:https://www.cnblogs.com/jhcelue/p/7210822.html
Copyright © 2011-2022 走看看