现在的位置: 首页 > 综合 > 正文

codechef December Challenge 2012 Granama Recipes 大水题

2013年04月08日 ⁄ 综合 ⁄ 共 2994字 ⁄ 字号 评论关闭
文章目录

Granama Recipes

Problem code: GRANAMA

Chef has learned a new technique for comparing two recipes. A recipe contains a list of ingredients in increasing order of the times they will be processed. An ingredient is represented by a letter 'a'-'z'. The
i-th letter in a recipe denotes the i-th ingredient. An ingredient can be used multiple times in a recipe.

The technique is as follows. Compare two recipes by comparing their respective lists. If the sets of ingredients used in both recipes are equal and each ingredient is used the same number of times in both of them (processing order does not matter), they
are declared as granama recipes. ("granama" is the Chef-ian word for "similar".)

Chef took two recipes he invented yesterday. He wanted to compare them using the technique. Unfortunately, Chef forgot to keep track of the number of times each ingredient has been used in a recipe. He only compared the ingredients but NOT their frequencies.
More precisely, Chef considers two recipes as granama if there are no ingredients which are used in one recipe and not used in the other recipe.

Your task is to report whether Chef has correctly classified the two recipes (as granama or not granama) although he forgot to keep track of the frequencies.

Input

The first line of the input contains a single integer T denoting the number of test cases. The description for
T test cases follows. Each test case consists of a single line containing two space-separated strings
R and S denoting the two recipes.

Output

For each test case, output a single line containing "YES" (quotes for clarity) if Chef correctly classified the two recipes as granama or not granama. Otherwise, output a single line containing "NO" (quotes for clarity) if Chef declared two recipes as granama
when they actually are not.

Constraints

1 ≤ T ≤ 100
1 ≤ |R|, |S| ≤ 1000

Example

Input:

3
alex axle
paradise diapers
alice bob

Output:

YES
NO
YES

Explanation:

Example case 1: Chef declared them as granama recipes. They are actually granama because the sets of ingredients and the number of times each ingredient has been used are equal. The Chef got it right!

Example case 2: Chef declared them as granama recipes because both sets of ingredients are equal. But they are NOT granama since ingredient 'a' has been used twice in the first recipe but only once in the second. The Chef was incorrect!

Example case 3: Chef declare them as not granama. They are not granama as the sets of ingredients are different. Hence, the Chef was right!

本题难点  :读题   呜呜。。。。。。

题意:  输入cas 后  输入2个字符串 每个字符表示一种配料    这些配料组成了一个食谱

问2个食谱是否相同  

已知标准判断方法是  :如果2种食谱中的配料均相同且出现次数相同 则认为食谱相同

但是由于厨师太笨(我自己认为 嘻嘻)  查不出次数来 他认为只要配料相同就是食谱相同

问厨师的检验方法是否和标准判断方法判断的结果一样  是输出YES 否则输出NO

思路   直接模拟

#include<stdio.h>
#include<map>
#include<string.h>
using namespace std;
int main()
{
	int i,k,cas,flag1,flag2;
	map<char,int>mp1;
	map<char,int>mp2;
	char s1[1005],s2[1005];
	scanf("%d",&cas);
	while(cas--)
	{
		mp1.clear();
		mp2.clear();
		scanf("%s %s",s1,s2);
		int len=strlen(s1);
		for(i=0;i<len;i++)
			mp1[s1[i]]++;
		len=strlen(s2);
		for(i=0;i<len;i++)
			mp2[s2[i]]++;
		flag1=flag2=0;
		for(i='a';i<='z';i++)
		{
			  
              if(mp1.find(i)==mp1.end()&&mp2.find(i)==mp2.end()) continue;
			  else if((mp1.find(i)==mp1.end()&&mp2.find(i)!=mp2.end())||(mp1.find(i)!=mp1.end()&&mp2.find(i)==mp2.end()))
			  {flag1=1;break;}//flag1表示字母不同
			  else 
			  {
				  if(mp1[i]!=mp2[i])  {flag2=1;}//flag2 表示次数不同
			  }
		}
		if(flag1==1) printf("YES\n");
		else if(flag2==0) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

抱歉!评论已关闭.