1081 检查密码 (15 分)
题目链接
https://pintia.cn/problem-sets/994805260223102976/problems/994805261217153024
C++版答案
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N;
scanf("%d",&N);
for(int i=0; i<N; i++)
{
string s;
cin>>s;
bool alpha_flag=false,digit_flag=false,point_flag=false,other_flag=false;
if(s.size()<6)
{
printf("Your password is tai duan le.\n");
continue;
}
for(int j=0; j<s.size(); j++)
{
if(s[j]=='.')
point_flag=true;
else if((s[j] >= 'a' && s[j] <= 'z')||(s[j] >= 'A' && s[j] <= 'Z'))
alpha_flag=true;
else if(s[j] >= '0' && s[j] <= '9')
digit_flag=true;
else
other_flag=true;
}
if(other_flag)
printf("Your password is tai luan le.\n");
else if(!digit_flag)
printf("Your password needs shu zi.\n");
else if(!alpha_flag)
printf("Your password needs zi mu.\n");
else
printf("Your password is wan mei.\n");
}
return 0;
}
Java版答案
package test;
import java.util.Scanner;
public class Check {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int N = s.nextInt();
s.nextLine();
while(N-- >0) {
String password = s.nextLine();
if(password.length()<6) {
System.out.println("Your password is tai duan le.");
continue;
}
if(!password.matches("[a-zA-Z0-9.]+")) {
System.out.println("Your password is tai luan le.");
continue;
}
if(!password.matches(".*[0-9].*")) {
System.out.println("Your password needs shu zi.");
continue;
}
if(!password.matches(".*[a-zA-Z].*")) {
System.out.println("Your password needs zi mu.");
continue;
}
System.out.println("Your password is wan mei.");
}
}
}
|