目录

AtCoder B 212

AtCoder

djw | 04 Aug 2021

题目大意

题目会给一个4位的密码,判断是强密码还是弱密码

如果是弱密码:1. 四个数字都一样 2.前三位按顺序排 eg.123 (9后面是0)

解题思路

先拿到每一个数位上的数字,直接判断(因为可能出现的情况很少)

复杂度:O(1)

代码

import java.util.*;
public class Main {
    public static void main (String [] args){
        Scanner in=new Scanner(System.in);
        int X = in.nextInt();
        String ans = "Strong";
        int x1 = X / 1000;
        int x2 = (X % 1000) / 100;
        int x3 = (X % 100) / 10;
        int x4 = X % 10;
        if(x1 == x2 && x2 == x3 && x3 == x4 ) ans = "Weak";
        if (x1 + 1 == x2 || (x1 == 9 && x2 == 0)){
            if (x2 + 1 == x3 || (x2 == 9 && x3 == 0)){
                if (x3 + 1 == x4 || (x3 == 9 && x4 == 0)){
                    ans = "Weak";
                }
            }
        }
        System.out.println(ans);  
    } 
}

评论区