[字符串]Very easy

Input

The test start with n which means that there are n cases.

The first line of each case gives two number p,q:the threshold and the size of excepted-word set.

The next line will give q words that you should ignore.

The next two lines are two document.

The document contains only words and all letters are lowercase.

The words are separated by blank space.

Output

If the two given documents are similar,print ’Yes’,or print ‘No’.

Sample Input

20.8 3i am ai am a boyi am a boy0.8 3i am ai am a boyi am a girl

Sample Output

YesNo

HINT

Source


第一次用Java做acm。

输入输出使用Scanner,配合String的split。非常方便

package A;
import java.util.*;
//import java.math.*;

public class Main {

	public static void main(String[] arvs)
	{
		Scanner a = new Scanner(System.in);
		int T = a.nextInt();
		while ((T--) > 0)
		{
			if (!a.hasNextDouble()) break;
			double p0 = a.nextDouble();
			int n = a.nextInt();
			HashSet<String> filter = new HashSet<String>();
			HashMap<String, Integer> hash1 = new HashMap<String,Integer>();
			HashMap<String, Integer> hash2 = new HashMap<String,Integer>();
			for (int i=0;i<n;i++)
			{
				String f = a.next(); 
				filter.add(f);
			}
			String line,words[];
			while ((line = a.nextLine()).equals(""));
			words = line.split(" ");
			for (String w:words)
			{
				if (filter.contains(w))
					continue;
				if (hash1.containsKey(w))
					hash1.put(w, hash1.get(w)+1);
				else
					hash1.put(w, 1);
			}
			
			double fenmu1 = 0;
			for (int frequence:hash1.values())
			{
				fenmu1 += frequence*frequence;
			}
			fenmu1 = Math.sqrt(fenmu1);
			
			while ((line = a.nextLine()).equals(""));
			words = line.split(" ");
			
			int common = 0;
			for (String w:words)
			{
				if (filter.contains(w))
					continue;
				if (hash1.containsKey(w))
				{
					common += hash1.get(w);
				}
				
				if (hash2.containsKey(w))
					hash2.put(w, hash2.get(w)+1);
				else
					hash2.put(w, 1);
			}
				
			double fenmu2 = 0;
			for (int frequence:hash2.values())
			{
				fenmu2 += frequence*frequence;
			}
			fenmu2 = Math.sqrt(fenmu2);
			
			double p = (double)common/(fenmu1*fenmu2);
			if (p < p0)
				System.out.println("No");
			else
				System.out.println("Yes");
		}
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值