Uva1339 Ancient Cipher

题目链接:Uva1339 Ancient Cipher


水题一道,题目描述很复杂,其实只要统计句子中的单词数目是不是对应相等就好了。


import java.util.*;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		String enc_mess=new String();
		String ori_mess=new String();
		char[] enc_chars=null;
		char[] ori_chars=null;
		int[] alpha1=new int[26];
		int[] alpha2=new int[26];
		while(in.hasNext())
		{
			enc_mess=in.next();
			if(enc_mess.length()==0) break;
			enc_chars=enc_mess.toCharArray();
			ori_mess=in.next();
			ori_chars=ori_mess.toCharArray();
			Arrays.fill(alpha1,0);
			Arrays.fill(alpha2,0);
			for(int i=0;i<enc_chars.length;i++)
			{
				alpha1[enc_chars[i]-'A']++;
				alpha2[ori_chars[i]-'A']++;
			}
			Arrays.sort(alpha1);
			Arrays.sort(alpha2);
			int flag=0;
			for(int i=0;i<alpha1.length;i++)
				if(alpha1[i]!=alpha2[i])
				{
					flag=1;
					break;
				}
			if(flag==0)
				System.out.println("YES");
			else
				System.out.println("NO");
		}
	}

}


你可能感兴趣的:(Uva1339 Ancient Cipher)