AncientCipher/강소현 (rev. 1.1)
Status ¶
Problem | 2159 | User | talin0528 |
Memory | 2988K | Time | 3829MS |
Language | Java | Result | Accepted |
Source ¶
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
char[] c = sc.nextLine().toCharArray();
char[] p = sc.nextLine().toCharArray();
if(compare(c,p))
System.out.println("YES");
else
System.out.println("NO");
}
private static boolean compare(char[] c, char[] p) {
int[] cSpread = new int[26];
int[] pSpread = new int[26];
boolean[] check = new boolean[26];
for(int i=0; i<c.length; i++){
cSpread[c[i]-65]++;
pSpread[p[i]-65]++;
}
for(int i=0; i<cSpread.length; i++)
if(!find(cSpread,pSpread[i],check))
return false;
return true;
}
private static boolean find(int[] cSpread, int pWord, boolean[] check) {
for(int i=0; i<cSpread.length;i++)
if(!check[i] && cSpread[i] == pWord){
check[i] = true;
return true;
}
return false;
}
}