pat 1035 Password(20) java

原题:

To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L in lowercase), or 0 (zero) from O (o in uppercase). One solution is to replace 1 (one) by @, 0 (zero) by %, l by L, and O by o. Now it is your job to write a program to check the accounts generated by the judge, and to help the juge modify the confusing passwords.

翻译
为了准备PAT,法官有时不得不为用户生成随机密码。问题是,总是有一些令人困惑的密码,因为很难区分1(1)和l(小写l),或0(0)和O(大写O)。一种解决方案是用@代替1(1),用%代替0(0),用L代替l,用o代替O。现在你的工作是编写一个程序来检查法官生成的账户,并帮助法官修改令人困惑的密码。

在这里插入图片描述

import java.util.*;

public class Main{
    public static void main(String[] args){
        //Input Specification:
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        int strInt = Integer.valueOf(str);
        if(strInt<=1000){  // Each case contains a positive integer N (≤1000)
        String strJoin = new String();
        int countChange = 0;
        for(int i=0;i<strInt;i++){
            String strLine =in.nextLine();
            String[] strArr = strLine.split(" ");//以空格为中心拆分,密码进行遍历替换
            if (strArr[0].length()>10||strArr[1].length()>10)continue; //密码或者账户字符长度大于10直接跳出当前循环
            String[] split = strArr[1].split(""); //拆分密码为数组
            String strSave = new String(); //每次输入重新初始化
            for (int j = 0; j < split.length; j++) {  //替换字符
                switch(split[j]){
                    case "1":
                        split[j] = "@";
                        break;
                    case "0":
                        split[j] = "%";
                        break;
                    case "l":
                        split[j] = "L";
                        break;
                    case "O":
                        split[j] = "o";
                        break;
                }
                strSave += split[j];
            }
            if (!strArr[1].equals(strSave)){ //比较值是否相同
                countChange++;
                strJoin += strArr[0]+" "+strSave+"\n";
            }
        }
        if (countChange==0){
            if(strInt==1)
            System.out.print("There is"+" "+str+" "+"account and no account is modified");
            if(strInt>1)
            System.out.print("There are"+" "+str+" "+"accounts and no account is modified");
        }
        else{
        System.out.println(countChange);
        System.out.print(strJoin.trim());
        }
       }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值