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;
           }*/

  • 相关阅读:
    DLL注入之Appinit_Dlls
    VC下遍历文件夹中的所有文件的几种方法
    Windows下C语言的Socket编程例子(TCP和UDP)
    Windows进程间共享内存通信实例
    window下线程同步之(Mutex(互斥器) )
    如何安装win10和linux [ubuntu14]双系统
    Windows虚拟地址转物理地址(原理+源码实现,附简单小工具)
    Windows驱动中通过MDL实现用户态与核心态共享内存
    C# Label显示多行文本及换行(WinForm/WebForm)
    使用delegate实现简单的查询功能
  • 原文地址:https://www.cnblogs.com/jhcelue/p/7210822.html
Copyright © 2011-2022 走看看