设为首页 收藏本站
查看: 1241|回复: 0

[经验分享] codechef December Challenge 2012 Granama Recipes 大水题

[复制链接]

尚未签到

发表于 2015-11-26 08:39:34 | 显示全部楼层 |阅读模式
Granama Recipes
  Problem code: GRANAMA


  • Submit
  • My Submissions
  • All Submissions
  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(&quot;%d&quot;,&cas);
while(cas--)
{
mp1.clear();
mp2.clear();
scanf(&quot;%s %s&quot;,s1,s2);
int len=strlen(s1);
for(i=0;i<len;i++)
mp1[s1]++;
len=strlen(s2);
for(i=0;i<len;i++)
mp2[s2]++;
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!=mp2)  {flag2=1;}//flag2 表示次数不同
}
}
if(flag1==1) printf(&quot;YES\n&quot;);
else if(flag2==0) printf(&quot;YES\n&quot;);
else printf(&quot;NO\n&quot;);
}
return 0;
}

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-143642-1-1.html 上篇帖子: codechef Birthday Candles 题解 下篇帖子: Chef学习之五:Knife bootstrap 一台 Ubuntu EC2 机器
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表