当前位置:网站首页>牛客 HJ20 密码验证合格程序
牛客 HJ20 密码验证合格程序
2022-07-31 15:58:00 【顧棟】
描述
密码要求:
1.长度超过8位
2.包括大小写字母.数字.其它符号,以上四种至少三种
3.不能有长度大于2的包含公共元素的子串重复 (注:其他符号不含空格或换行)
数据范围:输入的字符串长度满足 1 ≤ n ≤ 100 1 \le n \le 100 1≤n≤100
输入描述:
一组字符串。
输出描述:
如果符合要求输出:OK,否则输出NG
示例1
输入:
021Abc9000
021Abc9Abc1
021ABC9000
021$bc9000
输出:
OK
NG
NG
OK
java实现
- 主要是对条件三进行操作,通过将字符串从拆分成两部分。若大部分中还拥有小部分,说明短字符串重复存在。
package nowcoder.x2x;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class HJ020 {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input;
while (null != (input = reader.readLine())) {
if (input.length() < 9) {
System.out.println("NG");
continue;
}
char[] chars = input.toCharArray();
int a1 = 0, b1 = 0, c1 = 0, d1 = 0;
int n = 0;
for (char c : chars) {
if (c >= 'A' && c <= 'Z') {
a1 = 1;
} else if (c >= 'a' && c <= 'z') {
b1 = 1;
} else if (c >= '0' && c <= '9') {
c1 = 1;
} else if (c == ' ' || c == '\n') {
break;
} else {
d1 = 1;
}
}
if (a1 + b1 + c1 + d1 < 3) {
System.out.println("NG");
continue;
}
boolean flag = false;
// 将字符串从拆分成两部分。若大部分中还拥有小部分,说明短字符串重复存在。
for (int i = 3; i < input.length(); i++) {
if (input.substring(i).contains(input.substring(i - 3, i))) {
System.out.println("NG");
flag = true;
// 跳出for,提高效率
break;
}
}
if (flag) {
continue;
}
System.out.println("OK");
}
}
}
边栏推荐
- 01 Encounter typescript, build environment
- Kubernetes common commands
- radiobutton的使用
- Unity中实现点选RenderTexture中的3D模型
- form 表单提交后,使页面不跳转[通俗易懂]
- Insert into data table to insert data
- Website vulnerability repair service provider's analysis of unauthorized vulnerability
- Deployment应用生命周期与Pod健康检查
- tooltips使用教程(鼠标悬停时显示提示)
- 双边滤波加速「建议收藏」
猜你喜欢
随机推荐
mysql black window ~ build database and build table
Unity 之 图集属性详解和代码示例 -- 拓展一键自动打包图集工具
update data table update
Website vulnerability repair service provider's analysis of unauthorized vulnerability
ML.NET related resources
Precautions and solutions when SIGABRT error is reported
Bilateral filtering acceleration "recommended collection"
Delete table data or clear table
【Meetup预告】OpenMLDB+OneFlow:链接特征工程到模型训练,加速机器学习模型开发
gerrit中如何切换远程服务器
贪吃蛇项目(简单)
Matlab matrix basic operations (definition, operation)
LeetCode_733_图像渲染
【TypeScript】深入学习TypeScript类型操作
[Meetup Preview] OpenMLDB+OneFlow: Link feature engineering to model training to accelerate machine learning model development
Kubernetes common commands
研发过程中的文档管理与工具
多主复制下处理写冲突(4)-多主复制拓扑
使用 GraphiQL 可视化 GraphQL 架构
OPPO在FaaS领域的探索与思考