原题:
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());
}
}
}
}