HDU1039 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): 7822    Accepted Submission(s): 3863

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

Mid-Central USA 2000

用java写得很不熟练,缝缝补补地才勉强通过。很多地方没有C自由。

import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner cin = new Scanner(System.in);
		final String str1 = " is acceptable.", str2 = " is not acceptable.";
		String str;
		while(true){
			str = cin.next();
			if(str.equals("end")) break;
			System.out.print('<' + str +'>');
			if(check(str)) System.out.println(str1);
			else System.out.println(str2);
		}
	}

	public static boolean check(String str){
		int a = 0, b = 0, c = 0;
		boolean ok = false; char ch;
		for(int i = 0; i < str.length(); ++i){
			ch = str.charAt(i);
			if(isVowel(ch)){
				ok = true; b = 0;
				if(++a == 3) return false;
			}else{
				a = 0;
				if(++b == 3) return false;
			}
			if(i != 0 && ch == str.charAt(i-1) && ch != 'e' && ch != 'o')
				return false;
		}
		return ok;
	}

	public static boolean isVowel(char ch){
		if(ch == 'a' || ch == 'e' || ch == 'i'
			 || ch == 'o'|| ch == 'u') return true;
		return false;
	}
}
时间: 2024-10-13 02:23:09

HDU1039 Easier Done Than Said?的相关文章

Easier Done Than Said?(杭电oj1039)

Easier Done Than Said? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8339    Accepted Submission(s): 4093 Problem Description Password security is a tricky thing. Users prefer simple password

ural 1356. Something Easier 哥德巴赫猜想

1356. Something Easier Time limit: 1.0 secondMemory limit: 64 MB “How do physicists define prime numbers? Very easily: prime numbers are the number 2 and all the odd numbers greater than 2. They may show that this definition corresponds to the mathem

Little things that can make your life easier in 2016

作为今年的结束,向你推荐一些工具,可以添加到你的iOS开发工具箱,并可以让你2016年的开发变得更容易.更高效. 使用用户断点的力量 我们使用断点的地方有很多,但我发现大多数朋友只使用常规断点进行调试. 实际上,还有很多你能用的地方,例如你可以把普通断点提升为用户断点,并且在你所有的项目中使用,为什么不这么做呢? 因为你可以在执行代码中创建一个特定的符号断点,例如UIApplicationMain: 看到我做了些什么吗? 现在每当调试任何的项目,我已经不这么做了: 我直接这么处理: 没有额外的步

Easier Done Than Said? 【杭电-1039】

/* Easier Done Than Said? Problem DescriptionPassword 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 xv

Easier Done Than Said? 【杭电-1039】 附题

/* Easier Done Than Said? Problem DescriptionPassword 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 xv

1658: Easier Done Than Said?

1658: Easier Done Than Said? Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 15  Solved: 12[Submit][Status][Web Board] Description Password security is a tricky thing. Users prefer simple passwords that are easy to remember (like buddy), but such passw

hdu 1039 - Easier Done Than Said?

题目:给你一个小写字符串,判断是否安全,安全规则如下: 1.包含元音字母:2.相邻3个元素不能都是元音或辅音:3.连续2个字母相同之能是o或e. 分析:简单题.直接模拟即可. 说明:今天有点累╮(╯▽╰)╭,要学的东西好多( ⊙ o ⊙ )啊! #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #incl

HDU 1039[Easier Done Than Said?] 字符串处理

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1039 题目大意:给一个字符串,看是否符合密码的要求. 规则:1.至少有1个元音字母.2.不能有3个连续的元音字母或辅音字母3.不能有相同的字母连续出现(除了ee,oo) 关键思想:耐心地处理字符串 代码如下: //可优化 #include <iostream> #include <algorithm> #include <string.h> using namespace

使 Excel 规则更容易理解(Oracle Policy Modeling-Make your Excel rules easier to understand)

有以下几种方法可以使 Excel 规则更容易理解. 在 Excel 工作簿中缩短属性名称 您可以使用图例关键字创建在 Excel 中引用属性的缩写方式.可以根据情况指定此缩写形式. 要指定图例关键字,请执行以下操作: a.在 Excel 中,打开声明工作表. b.在属性类型和属性文本列旁边,添加标题“图例关键字”.单击 Oracle Policy Modeling 工具 栏上的图例关键字标题按钮以设置此单元格的样式.注:此列已存在于默认的 Excel 工作表中, 因此,仅当您在某个阶段人工删除了