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 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
这道题是2015考研机试前的那个PAT的D题 http://www.patest.cn/contests/pat-a-101-125-1-2015-03-14
这道题很简单,所以考试结束后原英文题目放到了A中,中文版的也放到了B中 http://www.cnblogs.com/asinlzm/p/4441575.html
#include<cstdio>
#include<cstring> int main()
{
char str[];
gets(str); int istr=,charnum[]={};
while(str[istr]) charnum[str[istr]]++,istr++; // count beads which belong to the shop owner gets(str);
istr=;
while(str[istr]) charnum[str[istr]]--,istr++; // count beads which Eva need int more=,less=;
for(int i=;i<;i++)
{
if(charnum[i]>) more+=charnum[i];
else if(charnum[i]<) less-=charnum[i];
} if(less) printf("No %d",less);
else printf("Yes %d",more);
return ;
}
PAT (Advanced Level) Practise - 1092. To Buy or Not to Buy (20)的更多相关文章
- PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20)
PAT (Basic Level) Practise (中文)- 1024. 科学计数法 (20) http://www.patest.cn/contests/pat-b-practise/1024 ...
- PAT (Basic Level) Practise (中文)-1032. 挖掘机技术哪家强(20)
PAT (Basic Level) Practise (中文)-1032. 挖掘机技术哪家强(20) http://www.patest.cn/contests/pat-b-practise/1032 ...
- PAT (Basic Level) Practise (中文)-1033. 旧键盘打字(20)
PAT (Basic Level) Practise (中文)-1033. 旧键盘打字(20) http://www.patest.cn/contests/pat-b-practise/1033 旧 ...
- PAT (Advanced Level) Practise - 1094. The Largest Generation (25)
http://www.patest.cn/contests/pat-a-practise/1094 A family hierarchy is usually presented by a pedig ...
- PAT (Advanced Level) Practise 1004 解题报告
GitHub markdownPDF 问题描述 解题思路 代码 提交记录 问题描述 Counting Leaves (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 1600 ...
- PAT (Advanced Level) Practise - 1093. Count PAT's (25)
http://www.patest.cn/contests/pat-a-practise/1093 The string APPAPT contains two PAT's as substrings ...
- PAT (Advanced Level) Practise - 1095. Cars on Campus (30)
http://www.patest.cn/contests/pat-a-practise/1095 Zhejiang University has 6 campuses and a lot of ga ...
- 1079. Total Sales of Supply Chain (25)【树+搜索】——PAT (Advanced Level) Practise
题目信息 1079. Total Sales of Supply Chain (25) 时间限制250 ms 内存限制65536 kB 代码长度限制16000 B A supply chain is ...
- PAT (Advanced Level) Practise - 1099. Build A Binary Search Tree (30)
http://www.patest.cn/contests/pat-a-practise/1099 A Binary Search Tree (BST) is recursively defined ...
随机推荐
- es6的箭头函数转换为普通函数,以及将await/async函数转为普通函数
箭头函数转为普通函数: 1. 安装babel-preset-es2015 npm install babel-preset-es2015 --save-dev 2.在.babelrc文件夹中: & ...
- jquery对象里面的context参数
jquery源码: jQuery = function( selector, context ) { // The jQuery object is actually just the init co ...
- iphone手机QQ浏览器到底部继续上滑出现黑色背景盖住position:fixed的页面元素的问题
真的是试了网上很多种都不行, 最后我html{overflow-x:hidden;}加了这个,去掉就可以了~删除html{overflow-x:hidden;} body{overflow-x:hid ...
- mysql隔离级别与锁,接口并发响应速度的关系(2)
innoDB默认隔离级别 mysql> SELECT @@tx_isolation; +-----------------+ | @@tx_isolation | +-------------- ...
- LL_01
http://www.52pojie.cn/thread-262602-1-1.html C http://www.92jh.cn/forum.php?mod=viewthread&tid=1 ...
- 最大利润-城市A和B
1,问题描述 jack每天同时只能在A和B其中一个城市工作赚钱,假设两个城市间的交通费为m.已知每天在A 和 B 能赚到多少钱,那么jack怎么选择每天工作的城市才能赚到最大利润. 比如 moneyA ...
- Murano Weekly Meeting 2015.07.14
会议时间: 2015.07.14 主持人: Kirill Zaitsev, core from Mirantis 会议摘要: 1.periodic nightly builds,然后通过mailin ...
- 27 个Jupyter Notebook的小提示与技巧
不多说,直接上干货! 见 http://liuchengxu.org/pelican-blog/jupyter-notebook-tips.html
- 解决Spring JdbcTemplate调用queryForObject()方法结果集为空时报异常
JdbcTemplate用的时候发现一个问题:调用queryForObject()方法,如果没有查到东西则会抛一个异常:org.springframework.dao.EmptyResultDataA ...
- 【Linux】让Ubuntu 支持 GBK等字符集,解决中文乱码
对GBK,GB2312,GB18030字符集的支持是UBUNTU中文乱码的罪魁祸首,其实我们可以在保持UTF-8为默认编码的条件下添加对这几个编码的支持,以解决中文乱码问题. 我想这个问题肯定有其他人 ...