1081

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    // write your code here
        Scanner sc=new Scanner(System.in);
        int num=sc.nextInt();
        String[] psd=new String[num];
        for (int i=0;i<num;i++){
            psd[i]=sc.nextLine();
        }
        char[][] c=new char[num][80];
        //将每一个输入的密码作为字符型数组存储到数组c中
        for (int i=0;i<num;i++){
            c[i]=psd[i].toCharArray();
        }
        for (int i=0;i<num;i++){
            realPass(c[i]);
        }
    }
    public static void realPass(char[] arr){
        if (arr.length<6){
            System.out.println("Your password is tai duan le.");

        }else{
            for (int i=0;i<arr.length;i++){
                if ((arr[i]>=65&&arr[i]<=90)||(arr[i]>=97&&arr[i]<=122)){
                   for (int j=0;j<arr.length;j++){
                        if ((int)arr[j]>=0&&(int)arr[j]<=9){
                            for (int k=0;k<arr.length;k++){
                                if ((arr[i]>=65&&arr[i]<=90)||(arr[i]>=97&&arr[i]<=122)||(arr[k]=='.')||(int)arr[j]>=0&&(int)arr[j]<=9){
                                    System.out.println("Your password is wan mei.");
                                }else{
                                    System.out.println("Your password is tai luan le.");
                                }
                            }
                        }else{
                            System.out.println("Your password needs shu zi.");
                            break bgm;
                        }
                    }
                }else{
                    System.out.println("Your password needs zi mu.");
                    break;
                }
            }
        }

    }
}

这么写不行,凌乱不堪,还不对。

package com.company;

import java.util.Scanner;

public class Main {
    static boolean flag1=false,flag2=false,flag3=false;
    public static void main(String[] args) {
    // write your code here
        Scanner sc=new Scanner(System.in);
        int num=Integer.parseInt(sc.nextLine());
        String[] psd=new String[num];

        for (int i=0;i<psd.length;i++){
            psd[i]=sc.nextLine();
        }
        char[][] c=new char[num][80];
        //将每一个输入的密码作为字符型数组存储到数组c中
        for (int i=0;i<num;i++){
            c[i]=psd[i].toCharArray();
        }






        for (int i=0;i<num;i++) {
            for (int j=0;j<c[i].length;j++){

                if (c[i].length<6){
                    System.out.println("Your password is tai duan le.");
                    break;
                }else{
                    judge(c[i][j]);
                    if (flag3){
                    System.out.println("Your password is tai luan le.");
                        break;
                    }else{
                        if (flag1&&flag2){
                            System.out.println("Your password is wan mei.");
                            break;
                        }else if (flag1&&!flag2){
                            System.out.println("Your password needs zi mu.");
                            break;
                        }else if (!flag1&&flag2){
                            System.out.println("Your password needs shu zi.");
                            break;
                        }
                    }
                }
            }



        }
    }

    public static  void judge(char ch){


        if (ch>='0'&&ch<='9'){
            flag1=true;
        }
        if (ch>='a'&&ch<='z'||ch>='A'&&ch<='Z'){
            flag2=true;
        }
        else if (ch!='.'){
            flag3=true;
        }
    }
}

好些了,但逻辑还是不对,知道思路,但是写不出来,对api不熟悉啊

package com.company;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        input.nextLine();
        String password=null;
        for (int i = 0; i < n; i++) {

            password = input.nextLine();
        }
        for (int i = 0; i < n; i++) {
            boolean neednum = true, needletter = true, luan = false;
            if (password.length() < 6) {
                System.out.println("Your password is tai duan le.");
                continue;
            } else {
                for (int j = 0; j < password.length(); j++) {
                    if (!Character.isLetterOrDigit(password.charAt(j)) && password.charAt(j) != '.') {
                        luan = true;
                        break;
                    } else if (Character.isDigit(password.charAt(j))) {
                        neednum = false;
                    } else if (Character.isLetter(password.charAt(j))) {
                        needletter = false;
                    }

                }
                if (luan) {
                    System.out.println("Your password is tai luan le.");
                    continue;

                } else if (neednum) {
                    System.out.println("Your password needs shu zi.");
                    continue;
                } else if (needletter) {
                    System.out.println("Your password needs zi mu.");
                    continue;
                } else {
                    System.out.println("Your password is wan mei.");
                }

            }

        }

        input.close();

    }

}

 以上都有问题,果然还是要新建个字符串数组输入,然后再一个个的判断密码是哪些问题,满分,不过讲真这一题真的好难,判断的逻辑也不简单呢。主要思路就是循环判断每个字符串有没有数字,有没有字母,有没有'.',还是挺难的,要好好消化下。

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        input.nextLine();
        String[] password=new String[n];
        for (int i = 0; i < n; i++) {
            password[i] = input.nextLine();
        }
        for (int i = 0; i < n; i++) {
            boolean neednum = true, needletter = true, luan = false;
            if (password[i].length() < 6) {
                System.out.println("Your password is tai duan le.");
                continue;
            } else {
                for (int j = 0; j < password[i].length(); j++) {
                    if (!Character.isLetterOrDigit(password[i].charAt(j)) && password[i].charAt(j) != '.') {
                        luan = true;
                        break;
                    } else if (Character.isDigit(password[i].charAt(j))) {
                        neednum = false;
                    } else if (Character.isLetter(password[i].charAt(j))) {
                        needletter = false;
                    }
                }
                if (luan) {
                    System.out.println("Your password is tai luan le.");
                } else if (neednum) {
                    System.out.println("Your password needs shu zi.");
                } else if (needletter) {
                    System.out.println("Your password needs zi mu.");
                } else {
                    System.out.println("Your password is wan mei.");
                }
            }
        }
        input.close();
    }
}

 

posted @ 2018-10-08 20:49  博客园机器人  阅读(204)  评论(0)    收藏  举报