当前位置: 首页 > news >正文

牛客:HJ20 密码验证合格程序[华为机考][字符串]

学习要点

  1. 利用容器本身的功能来为解题提供服务
  2. string.find
  3. string.substr
  4. 范围for
  5. string::npos

题目链接

        密码验证合格程序_牛客题霸_牛客网

题目描述

解法:字符串操作

#include <bits/stdc++.h>
#include <cctype>
#include <iostream>
using namespace std;int main() {// 接收字符串vector<string> my_print;string line_str;while(getline(cin,line_str)){bool X = false; bool x = false; bool number = false; bool ch = false;int n = line_str.size();if(n < 8){my_print.push_back("NG");continue;}for(auto &i:line_str){if(islower(i)){x = true;}else if(isupper(i)){X = true;}else if(i>='0' && i<='9'){number = true;}else {ch = true;}}int count =0;if(X) count++;if(x) count++;if(number) count++;if(ch) count++;if(count <3){my_print.push_back("NG");continue;}for(int i =0;i<n;i++){if((i+4) >= n){my_print.push_back("OK");break;}string tmp_str = line_str.substr(i,3);int pos = line_str.find(tmp_str,i+3);if(pos != string::npos){my_print.push_back("NG");// cout << 1 << endl;break;}}}for(auto& str:my_print){cout << str << endl;}}
// 64 位输出请用 printf("%lld")

http://www.lryc.cn/news/589430.html

相关文章:

  • 一般芯片电气特性中Flash参数达到其最大值的条件是什么?
  • 【人工智能99问】激活函数有哪些,如何选择使用哪个激活函数?(5/99)
  • 全新 Python 项目托管到 Gitee 私有仓库完整流程(带详细命令注释)
  • 【PTA数据结构 | C语言版】构造二叉树
  • 软件质量概述
  • 使用 pdb 来 debug 调试 python 程序
  • I3C通信驱动开发注意事项
  • Linux715 磁盘管理:逻辑卷
  • golang二级缓存示例
  • 随机奖励能提升Qwen数学表现?本质是数据污染
  • NuGet01-安装及使用
  • Linux下编译海思WS63 SDK全攻略
  • 关于Linux下Cursor的使用
  • 如何设计实现开发自助重启工具-01-设计篇
  • 代码随想录八股文训练营总结
  • lesson14:Python的推导式
  • 2025-07-15 李沐深度学习6——Softmax回归
  • 项目:简单学生成绩管理系统设计
  • Nginx配置反向代理
  • 深入解析:磁盘级文件与内存级(被打开)文件的本质区别与联系
  • 脚手架新建Vue2/Vue3项目时,项目文件内容的区别
  • k8s环境使用Operator部署Seaweedfs集群(上)
  • 同济医院R语言训练营第三期开讲!上交大张维拓老师主讲
  • ubuntu22.04谷歌浏览器中文输入法bug
  • ASP .NET Core 8结合JWT轻松实现身份验证和授权
  • ESLint 配置错误:ReferenceError: prettier is not defined 解决方案
  • Vue 常用的 ESLint 规则集
  • 卫星通信链路预算之六:输出回退
  • web前端渡一大师课 01 事件循环
  • 网络基础协议综合实验