1092. To Buy or Not to Buy (20)
Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner of the shop would only sell the strings in whole pieces. Hence Eva must check whether a string in the shop contains all the beads she needs. She now comes to you for help: if the answer is "Yes", please tell her the number of extra beads she has to buy; or if the answer is "No", please tell her the number of beads missing from the string.
For the sake of simplicity, let's use the characters in the ranges [0-9], [a-z], and [A-Z] to represent the colors. For example, the 3rd string in Figure 1 is the one that Eva would like to make. Then the 1st string is okay since it contains all the necessary beads with 8 extra ones; yet the 2nd one is not since there is no black bead and one less red bead.

Figure 1
Input Specification:
Each input file contains one test case. Each case gives in two lines the strings of no more than 1000 beads which belong to the shop owner and Eva, respectively.
Output Specification:
For each test case, print your answer in one line. If the answer is "Yes", then also output the number of extra beads Eva has to buy; or if the answer is "No", then also output the number of beads missing from the string. There must be exactly 1 space between the answer and the number.
Sample Input 1:
ppRYYGrrYBR2258 YrR8RrY
Sample Output 1:
Yes 8
Sample Input 2:
ppRYYGrrYB225 YrR8RrY
Sample Output 1:
No 2
#include<stdio.h>
#include<string.h>
#include<math.h>
char a[1010],b[1010];
int c[200],d[200],e[200];
int main()
{
int i,j,l1,l2,s=0;
scanf("%s%s",a,b);
memset(c,0,sizeof(c));
memset(d,0,sizeof(d));
memset(e,0,sizeof(e));
l1=strlen(a);
l2=strlen(b);
for(i=0;i<l2;i++)
{
c[b[i]]++;
}
for(i=0;i<l1;i++)
{
d[a[i]]++;
}
for(i=0;i<l2;i++)
{
if(c[b[i]]>d[b[i]]&&e[b[i]]==0)
{
s+=c[b[i]]-d[b[i]];
}
e[b[i]]=1;
}
if(s==0)
{
printf("Yes %d\n",l1-l2);
}
else
{
printf("No %d\n",s);
}
return 0;
}
1092. To Buy or Not to Buy (20)的更多相关文章
- 1092 To Buy or Not to Buy (20 分)
1092 To Buy or Not to Buy (20 分) Eva would like to make a string of beads with her favorite colors s ...
- pat 1092 To Buy or Not to Buy(20 分)
1092 To Buy or Not to Buy(20 分) Eva would like to make a string of beads with her favorite colors so ...
- PAT 1092 To Buy or Not to Buy
1092 To Buy or Not to Buy (20 分) Eva would like to make a string of beads with her favorite colors ...
- poj1092. To Buy or Not to Buy (20)
1092. To Buy or Not to Buy (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- PAT1092:To Buy or Not to Buy
1092. To Buy or Not to Buy (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- PAT_A1092#To Buy or Not to Buy
Source: PAT A1092 To Buy or Not to Buy (20 分) Description: Eva would like to make a string of beads ...
- PAT (Advanced Level) Practise - 1092. To Buy or Not to Buy (20)
http://www.patest.cn/contests/pat-a-practise/1092 Eva would like to make a string of beads with her ...
- PAT Advanced 1092 To Buy or Not to Buy (20) [Hash散列]
题目 Eva would like to make a string of beads with her favorite colors so she went to a small shop to ...
- PAT (Advanced Level) 1092. To Buy or Not to Buy (20)
简单题. #include<cstdio> #include<cstring> ; char s1[maxn],s2[maxn]; ]; ]; int main() { sca ...
随机推荐
- TextView里的文 html
一.[Android实例]实现TextView里的文字有不同颜色 转eoe:http://www.eoeandroid.com/thread-4496-1-1.html import android. ...
- 如何正确的使用Lerp In Unity
摘要 本文探讨如何用lerp实现近似的匀速旋转,当然如果运用本文给出的方法,使用slerp则可以实现匀速旋转,并指出Unity官方lerp示例代码的一些缺陷. 现有问题 比如四元数Lerp API: ...
- 同步灵无线锂电鼠G11-580HX独特“五灵键”
http://tieba.baidu.com/p/2130455709 现在鼠标功能越来越强大,游戏鼠标的宏设置,办公鼠标的复制粘贴等.各位有没有给鼠标设置一些好玩.方便.搞怪.有意思的的功能的呢?笔 ...
- 在EXCEL中使用SQL查询
Excel2007及以上版本才有这个功能,2003版本的要么路过学习一下.要么去升级下自己的版本. Microsoft query 用的是 access 语法 如:判断空 oracle ------- ...
- Facebook等使用苹果源生分享
1.Facebook官方的SDK分享 2.ShareSDK,第三方集成的分享方式 3.网页分享方式分享 4.IOS6之后,苹果自己集成了对于F ...
- RC振荡器与有源滤波器1
自我总结,有错误欢迎指出! 一.振荡器原理: 对于正反馈,有如下公式: 讨论: 1.当A*F(jw)=1时 Af→∞(物理意义:自激振荡): 2.在f0上,F(jw)相移为0或2n∏:(因此,在f0处 ...
- linux中django+apache配置
配置apahce通过mod_wsgi访问django代码,最终通过版本说明: Apache/2.0.63 (Unix) DAV/2 mod_wsgi/3.5 Python/2.6.6 下面讲述一波三折 ...
- NOI2002 银河英雄传说
P1196 银河英雄传说 367通过 1.1K提交 题目提供者该用户不存在 标签并查集NOI系列2001(或之前) 难度提高+/省选- 提交该题 讨论 题解 记录 最新讨论 莱因哈特什么鬼? 私人代码 ...
- JS 点击按钮后弹出遮罩层,有关闭按钮
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...
- .NET本质论(4)应用程序对象HttpApplication
当HttpContext对象创建之后,HttpRuntime将随后创建一个用于处理请求的对象,这个对象的类型为HttpApplication. 在ASP.NET内部,HttpRuntime管理一个定 ...