HDOJ/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.
题意:
密码必须满足这三个规则:
它必须包含至少一个元音。
它不能包含三个连续的元音或三个辅音。
它不能包含两个连续的相同的字母,除了“EE”或“oo”。
(为了这个问题,元音“A”、“E”、“我”、“O”、和“U”;其他所有的字母都是辅音字母。)注意,这些规则是不完善的;有很多常用的发音的话,是不可接受的。
输入end结束输入~不需要输出。
满足的输出:** is acceptable.
否则输出:** is not acceptable.
import java.util.Scanner;
public class Main{
static String[] vowel = {"a","e","i","o","u"};
static String[] eq = {"aa","bb","cc","dd","ff","gg","hh","ii","jj","kk","ll","mm",
"nn","pp","qq","rr","ss","tt","uu","vv","ww","xx","yy","zz"};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String str=sc.next();
if("end".equals(str)){
return;
}
boolean isAcceptable=true;
int num=-1;
for(int i=0;i<vowel.length;i++){
if(num==-1){
num=str.indexOf(vowel[i]);
}
}
if(num==-1){
System.out.println("<"+str+">"+" is not acceptable.");
continue;
}
for(int i=0;i<eq.length;i++){
if(str.indexOf(eq[i])!=-1){
isAcceptable=false;
break;
}
}
if(!isAcceptable){
System.out.println("<"+str+">"+" is not acceptable.");
continue;
}
for(int i=0;i<str.length()-2;i++){
int Vowel1=0;
int Vowel2=0;
int Vowel3=0;
for(int k=0;k<vowel.length;k++){
if(str.charAt(i)==vowel[k].charAt(0)){
Vowel1=1;
}
}
for(int k=0;k<vowel.length;k++){
if(str.charAt(i+1)==vowel[k].charAt(0)){
Vowel2=1;
}
}
for(int k=0;k<vowel.length;k++){
if(str.charAt(i+2)==vowel[k].charAt(0)){
Vowel3=1;
}
}
if(Vowel1==Vowel2&&Vowel1==Vowel3){
isAcceptable=false;
break;
}
}
if(!isAcceptable){
System.out.println("<"+str+">"+" is not acceptable.");
continue;
}
System.out.println("<"+str+">"+" is acceptable.");
}
}
}
HDOJ/HDU 1039 Easier Done Than Said?(字符串处理~)的更多相关文章
- hdu 1039 Easier Done Than Said? 字符串
Easier Done Than Said? Time Limi ...
- HDU 1039.Easier Done Than Said?-条件判断字符串
Easier Done Than Said? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/O ...
- HDU 1039.Easier Done Than Said?【字符串处理】【8月24】
Easier Done Than Said? Problem Description Password security is a tricky thing. Users prefer simple ...
- 题解报告:hdu 1039 Easier Done Than Said?
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1039 Problem Description Password security is a trick ...
- HDU 1039 -Easier Done Than Said?
水水的 #include <iostream> #include <cstring> using namespace std; ]; bool flag; int vol,v2 ...
- HDOJ(HDU).1412 {A} + {B} (STL SET)
HDOJ(HDU).1412 {A} + {B} (STL SET) 点我挑战题目 题意分析 大水题,会了set直接用set即可. 利用的是set的互异性(同一元素有且仅有一项). #include ...
- HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)
HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...
- HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)
HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和) 点我挑战题目 题意分析 根据数据范围和询问次数的规模,应该不难看出是个数据结构题目,题目比较裸.题中包括以下命令: 1.Add(i ...
- HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)
HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...
随机推荐
- Android - 服务器json数据交互.
一,服务器端 服务器端使用的是Servlet,封装json对象使用的 'json-lib-2.2.2-jdk15.jar,ezmorph-1.0.4.jar,commons-logging-1.1.j ...
- mvc5 + ef6 + autofac搭建项目(四)
在列表页面,点击新增,弹出窗口实现视屏上传,这里存在一个问题,就是大文件上传的问题,iis出于安全问题,有限制,当然这不是大问题,解决也很容易: 见截图: 请忽略视屏文件,看得懂的请装作不懂. 源码 ...
- 案例:latch: cache buffers chains event tuning
前两天对oracle数据库(single instance)进行了迁移升级从10.2.0.4 升到11.2.0.3,有一个项目迁完后第二天,cpu负载升到了130更高(16cpus). 向用户询问后使 ...
- Page.ClientScript.RegisterStartupScript不执行问题
c#后台使用Page.ClientScript.RegisterStartupScript在前台注册一段脚本提示,发现没有效果,寻寻觅觅,终于从度娘处找到了原因: 该页面多次使用到了Page.Clie ...
- 使用Ubuntu 新建vpn过程
1.更新软件源 sudo apt-get update 2.安装pip sudo apt-get install python-pip 3.安装shadowsocks s ...
- ZOJ 1057 Undercut(简单模拟)
Undercut 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=57 题目大意:a card game,two pla ...
- DFS的基础训练清单
HDU 1010 (AC) HDU 1015 (AC) HDU 1016 (AC) HDU 1172 (AC) HDU 1312 (AC) POJ 2362 (AC,1011 ...
- 【清橙A1094】【牛顿迭代法】牛顿迭代法求方程的根
问题描述 给定三次函数f(x)=ax3+bx2+cx+d的4个系数a,b,c,d,以及一个数z,请用牛顿迭代法求出函数f(x)=0在z附近的根,并给出迭代所需要次数. 牛顿迭代法的原理如下(参考下图) ...
- JS-SDK微信支付开发攻略
一.吐槽篇 一个字——坑!两个字——很坑!三个字——非常坑!首先,微信支付接口作为微信开发接口的一部分,竟然有一本书那么厚的官方文档,共36页,更重要的是,这36页还不能把开发的流程说清楚,描述过于分 ...
- 让USB键盘的LED灯听你的!(不干扰使用)
最近在研究一个课题,如何能利用键盘的led灯通道进行有效通信,那么首先要做的就是尝试能否在不影响键盘的情况下控制LED灯(num lock ,caps lock ,scroll lock)的使用. 首 ...