杭电ACM OJ 1039 Easier Done Than Said? 水(但是很好玩的一道题,考察逻辑思维)
来源:互联网 发布:淘宝绿森数码怎么样 编辑:程序博客网 时间:2024/05/27 00:23
Easier Done Than Said?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 14426 Accepted Submission(s): 6986
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.
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
atvptouibontreszoggaxwiinqeephouctuhend
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.
翻译:给你一个字符串作为密码。需要满足3个条件
1.至少包含一个元音(a e i o u)2.不能包含3个连续的元音或者辅音3.除了ee,oo外不能包含连续出现两个相同的字母
做法:
1.至少包含一个元音(a e i o u)2.不能包含3个连续的元音或者辅音,设置一个yCount和fCount的变量来保存,优雅完美!3.除了ee,oo外不能包含连续出现两个相同的字母,维护上一个变量进行比较,优雅完美!
代码:
package ACM1000_1099;public class EasierDoneThanSaid1039 { // TODO: 2017/12/5 1.至少包含一个元音(a e i o u) // TODO: 2017/12/5 2.不能包含3个连续的元音或者辅音,当有元或辅来个变量保存个数 // TODO: 2017/12/5 3.除了ee,oo外不能包含连续出现两个相同的字母,也是一样,维护上一个 void calculate() { char[][] a = { {'a'}, {'t','v'}, {'p','t','o','u','i'}, {'b','o','n','t','r','e','s'}, {'z','o','g','g','a','x'}, {'w','i','i','n','q'}, {'e','e','p'}, {'h','o','u','c','t','u','h'}, }; int height = a.length; boolean haveAEIOU; int yCount; int fCount; char current; for (int i = 0; i < height; i ++) { haveAEIOU = false; yCount = 0; fCount = 0; current = '%'; for (int j = 0; j < a[i].length; j ++) { //如果有元音 设为true if (a[i][j] == 'a' || a[i][j] == 'e' || a[i][j] == 'i' ||a[i][j] == 'o' || a[i][j] == 'u') { haveAEIOU = true; //fCount不为0代表你刚存的是辅音,而且没到3 if (fCount != 0) { fCount = 0; } yCount ++; if (yCount == 3) { System.out.println("不能3个连续元音"); break; } } else { if (yCount != 0) { yCount = 0; } fCount ++; if (fCount == 3) { System.out.println("不能3个连续辅音"); break; } } //保存上一个字符 if (a[i][j] == current && current != 'e' && current != 'o') { System.out.println("不能2个连续一样且不是ee,oo"); break; } current = a[i][j]; if (j == a[i].length - 1) { if (!haveAEIOU) { System.out.println("不能没有元音"); } else { System.out.println("符合条件"); } } } } } public static void main(final String[] args) throws Exception { EasierDoneThanSaid1039 e = new EasierDoneThanSaid1039(); e.calculate(); }}
阅读全文
0 0
- 杭电ACM OJ 1039 Easier Done Than Said? 水(但是很好玩的一道题,考察逻辑思维)
- 杭电ACM HDOJ 1039 Easier Done Than Said?
- 杭电1039 Easier Done Than Said?
- Easier Done Than Said? 【杭电-1039】 附题
- hdoj 1039 Easier Done Than Said?(水水的)
- Easier Done Than Said?杭电ACM1039
- 杭电OJ——1039 Easier Done Than Said?(水题)
- 杭电 HDU 1039 Easier Done Than Said?
- 杭电1039 之 Easier Done Than Said?
- Easier Done Than Said?(杭电oj1039)
- Easier Done Than Said?(hdu 1039)
- HDU杭电 1039 Easier Done Than Said?(字符串问题)
- POJ 1575 && HDU 1039 Easier Done Than Said?(水~)
- hdu 1039 Easier Done Than Said?(简单题)
- 1039 Easier Done Than Said?
- 杭电ACM1039——Easier Done Than Said?
- HDU ACM 1039 Easier Done Than Said? 水题
- ACM--元辅音--HDOJ 1039--Easier Done Than Said?--字符串
- jQuery标准的AJAX模板
- OpenStack公共组件oslo之十四——pbr
- ehcache缓存
- 实验报告——Fanster RCNN训练project后的输电线路
- leetcode 398. Random Pick Index
- 杭电ACM OJ 1039 Easier Done Than Said? 水(但是很好玩的一道题,考察逻辑思维)
- ajax 跳入error的一些原因
- static修饰内部类
- Spring日志 common.logging 和log4j结合使用
- LeetCode 3. Longest Substring Without Repeating Characters (C语言)
- Unreal教学(11)——物体交互(Object Interaction with Blueprints)
- 云计算和云服务之间需要注意哪些
- AIS TDMA模块总体设计
- SAP采购订单抬头、行项目屏幕增强的两种方法