算法分析
模拟
- 1、将原来的密码
pass1
通过转换变成pass2
,若pass1
和pass2
不一样,则表示该密码已被修改,待输出 - 2、若没有密码被修改过,还需要注意数量是
1
个还是多个 - 3、若有密码被修改过,则把修改过的密码按顺序输出
时间复杂度 $O(10 * n)$
参考文献
pat
Java 代码
import java.util.Scanner;
public class Main {
static int N = 1010;
static String[] ans = new String[N];
static int k = 0;
static String change(String s)
{
char[] temp = s.toCharArray();
for(int i = 0;i < temp.length;i ++)
{
char t = s.charAt(i);
if(t == '1') t = '@';
else if(t == '0') t = '%';
else if(t == 'l') t = 'L';
else if(t == 'O') t = 'o';
temp[i] = t;
}
return String.valueOf(temp);
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int res = 0;
for(int i = 0;i < n;i ++)
{
String id = scan.next();
String pass1 = scan.next();
String pass2 = change(pass1);//变换后的密码
if(!pass1.equals(pass2))
{
res ++;
ans[k ++] = id + " " + pass2;
}
}
if(res == 0)
{
int t = n;
System.out.println("There " + (t == 1 ? "is" : "are") + " " + t + " account" + (t == 1 ? "" : "s") + " and no account is modified");
}
else
{
System.out.println(res);
for(int i = 0;i < k;i ++) System.out.println(ans[i]);
}
}
}