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 ...
随机推荐
- 面试d090305知识点准备01
1.1 类成员访问[jL1] 权限 1.2 写个双线程,计算50内的奇偶数 1.3 打印等腰三角形 1.4 运算符优先级 括号,非正负和自增减(右到左),乘除加减,等于不等于,逻辑与和或,然后 ...
- Eclipse下tomcat输出路径配置
在Eclipse下配置server为Tomcat(一般为Tomcat 6.X),双击server面板中的Tomcat v6.0 Server,出现的Server Locations配置有三个选项: 1 ...
- Retina显示屏-揭秘移动端的视觉稿通常会设计为传统PC的2倍
一.Retina显示屏简介 retina:一种具备超高像素密度的液晶屏,同样大小的屏幕上显示的像素点由1个变为多个,如在同样带下的屏幕上,苹果设备的retina显示屏中,像素点1个变为4个. reti ...
- POJ1033 Defragment
题目来源:http://poj.org/problem?id=1033 题目大意: 某操作系统的文件系统中,所有的磁盘空间被分为N个大小相等的cluster,编号1至N.每个文件占用一个或多个clus ...
- 一个经典的PHP文件上传类
需求分析如下: (1)支持单个文件上传 (2)支持多个文件上传 (3)可以指定保存位置 可以设置上传文件允许的大小和类型 可以选择重命名和保留原名 <!-- 设计一个经典文件上传类 需求分析 ( ...
- spring boot之 Bean的初始化和销毁(4)
原文:https://blog.csdn.net/z3133464733/article/details/79189699 -------------------------------------- ...
- ST的MCU系列
一 STM32F1(M3)系列: 超值型系列STM32F100- 24 MHz最高主频 带马达控制和CEC功能 基本型系列STM32F101 - 36 MHz最高主频,具有高达1M字节的片上闪存 U ...
- js dairy
//留言js逻辑 $(document).ready( function() { $("#post_btn").click( function() { var comment = ...
- Storm概念学习系列之什么是实时流计算?
不多说,直接上干货! 什么是实时流计算? 1.实时流计算背景 2.实时计算应用场景 3.实时计算处理流程 4.实时计算框架 什么是实时流计算? 所谓实时流计算,就是近几年由于数据得到广泛应用之后 ...
- nginx开启HSTS让浏览器强制跳转HTTPS访问
在上一篇文章中我们已经实现了本地node服务使用https访问了,看上一篇文章 效果可以看如下: 但是如果我们现在使用http来访问的话,访问不了.如下图所示: 因此我现在首先要做的是使用nginx配 ...