[JAVA]1035 Password (20分)

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int num = scan.nextInt();//定义账号数量
		String[][] account = new String[num][2];//定义账号和密码的字符串
		int cnt = 0;//需要修改密码的数量
		String[][] result = new String[num][2];//储存被修改后的账号密码
		//定义账号和密码
		for(int i = 0; i < account.length; i++) {
			account[i][0] = scan.next();//定义账号
			account[i][1] = scan.next();//定义密码
		}
		scan.close();
		//将密码打散成字符数组进行判断
		for(int i = 0; i< account.length; i++) {
			boolean flag = false;//定义flag来判断密码是否被修改
			char[] ch = account[i][1].toCharArray();
			//对字符进行遍历。找到需要修改的字母,如果进入了switch则flag变成true
			for (int j = 0; j < ch.length; j++) {
				switch(ch[j]) {
				case '1':
					ch[j] = '@';
					flag = true;
					break;
				case '0':
					ch[j] = '%';
					flag = true;
					break;
				case'l':
					ch[j] = 'L';
					flag = true;
					break;
				case'O':
					ch[j] = 'o';
					flag = true;
					break;
				}
			}
			if (flag == true) {
				account[i][1] = String.valueOf(ch);//将字符数组转化为字符串数组
				result[cnt][0] = account[i][0];//将结果赋值到输出的字符串
				result[cnt][1] = account[i][1];
				cnt++;
			}
		}
		
		//遍历完了数组开始输出结果
		if(num == 1 && cnt == 0) {
			System.out.println("There is 1 account and no account is modified");
		}else if (num != 1 && cnt == 0){
			System.out.println("There are " + num + " account and no account is modified");
		}else {
			System.out.println(cnt);
			for(int i = 0; i < cnt; i++) {
				System.out.println(result[i][0] + " " + result[i][1]);
			}
		}
		
	}
}
发布了11 篇原创文章 · 获赞 0 · 访问量 174

猜你喜欢

转载自blog.csdn.net/Bryce_Loski/article/details/103639894