PAT (Basic Level) Practise (中文)1039. 到底买不买(20)
来源:互联网 发布:淘宝怎么改店铺名 编辑:程序博客网 时间:2024/06/08 17:19
1039. 到底买不买(20)
时间限制
100 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
小红想买些珠子做一串自己喜欢的珠串。卖珠子的摊主有很多串五颜六色的珠串,但是不肯把任何一串拆散了卖。于是小红要你帮忙判断一下,某串珠子里是否包含了全部自己想要的珠子?如果是,那么告诉她有多少多余的珠子;如果不是,那么告诉她缺了多少珠子。
为方便起见,我们用[0-9]、[a-z]、[A-Z]范围内的字符来表示颜色。例如在图1中,第3串是小红想做的珠串;那么第1串可以买,因为包含了全部她想要的珠子,还多了8颗不需要的珠子;第2串不能买,因为没有黑色珠子,并且少了一颗红色的珠子。
图 1
输入格式:
每个输入包含1个测试用例。每个测试用例分别在2行中先后给出摊主的珠串和小红想做的珠串,两串都不超过1000个珠子。
输出格式:
如果可以买,则在一行中输出“Yes”以及有多少多余的珠子;如果不可以买,则在一行中输出“No”以及缺了多少珠子。其间以1个空格分隔。
输入样例1:ppRYYGrrYBR2258YrR8RrY输出样例1:
Yes 8输入样例2:
ppRYYGrrYB225YrR8RrY输出样例2:
No 2
#include <cstdio>#include <cstring>const int maxn=1005;char s1[maxn],s2[maxn];int Hash[80]={0},miss=0;int change(char c){ if(c>='0'&&c<='9') return c-'0'; else if(c>='a'&&c<='z') return c-'a'+10; else if(c>='A'&&c<='Z') return c-'A'+36;}int main(){ gets(s1); gets(s2); int len1=strlen(s1); int len2=strlen(s2); for(int i=0;i<len1;i++){ int id=change(s1[i]); Hash[id]++; } for(int i=0;i<len2;i++){ int id=change(s2[i]); Hash[id]--; if(Hash[id]<0) miss++; } if(miss>0) printf("No %d",miss); else printf("Yes %d",len1-len2); return 0;}
阅读全文
0 0
- PAT (Basic Level) Practise (中文)1039. 到底买不买(20)
- PAT (Basic Level) Practise (中文)1039. 到底买不买(20)
- PAT (Basic Level) Practise (中文)1039. 到底买不买(20) C语言
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)--1001
- PAT (Basic Level) Practise (中文)
- PAT (Basic Level) Practise (中文)1001
- PAT (Basic Level) Practise (中文)1002
- PAT (Basic Level) Practise (中文) 1007
- PAT (Basic Level) Practise (中文)1004. 成绩排名 (20)
- PAT (Basic Level) Practise (中文)1009. 说反话 (20)
- PAT (Basic Level) Practise (中文)1012. 数字分类 (20)
- PAT (Basic Level) Practise (中文)1013. 数素数 (20)
- PAT (Basic Level) Practise (中文)1019. 数字黑洞 (20)
- PAT (Basic Level) Practise (中文)1027. 打印沙漏(20)
- PAT (Basic Level) Practise (中文)1028. 人口普查(20)
- PAT (Basic Level) Practise (中文)1029. 旧键盘(20)
- 栈帧与函数调用过程分析
- windows修改pip源
- iOS 简易图片无线轮播器的打造
- jQuery 与 Zepto 的区别
- 如何关闭运行在某端口的的进程,例如 :8080端口
- PAT (Basic Level) Practise (中文)1039. 到底买不买(20)
- 图搜索基础
- 度量学习 (Metric Learning)
- C++实现String类
- win8.1cmd常用命令提示符
- 访问网站时后一个页面被前一个页面阻塞、后台页面阻塞前台页面的解决
- ftp上传图片为空,不为空打开没法查看
- iterable,iterator和sequence
- VS C工程二【打开VC6++工程:错误1 error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏】