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

MC0248 密码判断器(判断强弱密码)

原题链接<----

islower 小写字母判断
isupper 大写字母判断
isdigit 数字判断

题目:
小码哥在是一位密码领域的初学者,有一天他的老师给他了一串密码,要他判断这个密码是否是强密码,老师和他说强密码就是需要同时达到以下要求:
1.密码长度大于6。
2.密码中同时包括了大小写字母和数字。
3.并且数字和数字之间不能相连。

样例1
输入:
They12wwweqwe

输出:
False

样例 2
输入:
They1wwweqwe

输出:
True

#include <iostream>
#include <algorithm>
#include <cstring>
#include <string.h>
using namespace std;bool cmp(string x)
{return x.size()>6;
}bool cmp1(string x) //判断是否存在小写字母
{for(char it:x){if(islower(it)){return true;}}return false;	
}bool cmp2(string x) //是否存在大写字母
{for(char it:x){if(isupper(it)){return true;}}return false;	
}bool cmp3(string x) //判断是否存在数字
{for(char it:x){if(isdigit(it)){return true;}}return false;	
}bool cmp4(string x) //判断数字之间是否相连
{for(int i=0;i<x.size()-1;i++){if(isdigit(x[i]) && isdigit(x[i+1])){return false;}}	return true;
}int main()
{string str; getline(cin,str);if(cmp(str) && cmp1(str) && cmp2(str) && cmp3(str) &&cmp4(str)){printf("True\n");}else{printf("False\n");}return 0;
}

运行结果:
在这里插入图片描述

AI:

#include <iostream>  
#include <string>  
#include <cctype>  bool isLongEnough(const std::string& password) {  return password.length() > 6;  
}  bool hasLowerCase(const std::string& password) {  for (char c : password) {  if (std::islower(c)) {  return true;  }  }  return false;  
}  bool hasUpperCase(const std::string& password) {  for (char c : password) {  if (std::isupper(c)) {  return true;  }  }  return false;  
}  bool hasDigits(const std::string& password) {  for (char c : password) {  if (std::isdigit(c)) {  return true;  }  }  return false;  
}  bool hasConsecutiveDigits(const std::string& password) {  for (size_t i = 0; i < password.length() - 1; ++i) {  if (std::isdigit(password[i]) && std::isdigit(password[i + 1])) {  return true;  }  }  return false;  
}  bool isStrongPassword(const std::string& password) {  return isLongEnough(password) &&  hasLowerCase(password) &&  hasUpperCase(password) &&  hasDigits(password) &&  !hasConsecutiveDigits(password);  
}  int main() {  std::string password;  std::cout << "请输入密码: ";  std::cin >> password;  if (isStrongPassword(password)) {  std::cout << "这是一个强密码。" << std::endl;  } else {  std::cout << "这不是一个强密码。" << std::endl;  }  return 0;  
}
http://www.lryc.cn/news/326573.html

相关文章:

  • vue3+threejs新手从零开发卡牌游戏(十六):初始化对方手牌
  • 网页无插件视频播放器,支持录像、截图、音视频播放,多路播放等,提供源码下载
  • Openstack创建和操作实例,实现与外部网络通信
  • dubbo 源码系列之-集群三板斧---负载均衡(二)
  • 【一周一篇小题解】洛谷P1035级数求和
  • 2024-03-26 AIGC-大模型学习路线
  • QGraphicsView的使用,view坐标,scene坐标,item坐标
  • from_pretrained 做了啥
  • 2024/03/27(C++·day3)
  • Multimodal Chain-of-Thought Reasoning in Language Models阅读笔记
  • C语言例4-15:从键盘输入一个整数,求其绝对值并输出。
  • 【Linux】调试器-gdb的使用说明(调试器的配置,指令说明,调试过程说明)
  • Oracle AI Vector Search Multi-Vector Similarity Search 即多向量相似度检索学习笔记
  • 白板手推公式性质 AR模型 时间序列分析
  • 零基础学python之高级编程(6)---Python中进程的Queue 和进程锁,以及进程池的创建 (包含详细注释代码)
  • 184. 部门工资最高的员工
  • 插值表达式、Vue指令、指令补充
  • qiankun实现基座、子应用样式隔离
  • C语言从入门到实战----数据在内存中的存储
  • 接口关联和requests库
  • Python编程基础 001 开篇:为什么要学习编程
  • AQS源码分析
  • 应对Locked勒索病毒威胁:你的数据安全准备好了吗?
  • 周末分享一篇关于html和http的文章吧
  • Frechet分布
  • vue3全局引入element-plus使用Message教程
  • 时序预测 | Matlab实现BiTCN-BiLSTM双向时间卷积神经网络结合双向长短期记忆神经网络时间序列预测
  • 基于 Linux 的更新版 MaxPatrol VM 可扫描 Windows
  • 【软件开发】给Ubuntu 18.04虚拟机安装最新的Python 3.12.2
  • 鸿蒙NXET实战:高德地图定位SDK【获取Key+获取定位数据】(二)