[蓝桥杯] 试题 算法训练 Anagrams问题

// http://lx.lanqiao.cn/problem.page?gpid=T223

Scanner in = new Scanner(System.in);

String a = in.nextLine().toLowerCase();
String b = in.nextLine().toLowerCase();
int[] alp = new int[26];

for (char ch : a.toCharArray())
    alp[ch - 'a']++;
for (char ch : b.toCharArray())
    alp[ch - 'a']--;

boolean ret = true;
for (int i : alp) {
    if (i != 0) {
        ret = false;
        break;
    }
}

System.out.println(ret ? "Y" : "N");

发表评论