U E D R , A S I H C RSS

Ancient Cipher/강소현

Status

Problem2159Usertalin0528
Memory2988KTime3829MS
LanguageJavaResultAccepted

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;
	}
}

Trial and Error

  • 문제 이해를 잘못했었음 ㅠㅠ

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:28
Processing time 0.0101 sec