PAT_A1092#To Buy or Not to Buy
Source:
Description:
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 isNo, 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 isNo, 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 2:
No 2
Keys:
Code:
/*
Data: 2019-07-21 19:14:54
Problem: PAT_A1092#To Buy or Not to Buy
AC: 10:50 题目大意:
给定字符串S和T,S是否包含T的所有元素
若包含,则返回多余字符个数
若不包含,则返回缺失字符个数 */ #include<cstdio>
#include<string>
#include<iostream>
using namespace std;
char mp[]={}; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif string s,t;
int cnt=;
cin >> s >> t;
for(int i=; i<s.size(); i++)
mp[s[i]]++;
for(int i=; i<t.size(); i++)
{
mp[t[i]]--;
if(mp[t[i]]<)
cnt++;
}
if(cnt > )
printf("No %d\n", cnt);
else
printf("Yes %d\n", s.size()-t.size()); return ;
}
PAT_A1092#To Buy or Not to Buy的更多相关文章
- 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 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- A1092. To Buy or Not to Buy
Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy ...
- 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甲级——A1092 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 ...
随机推荐
- msfpayload的用法
daniel@daniel-mint ~/msf/metasploit-framework $ ruby msfpayload windows/exec CMD=calc.exe C WARNING: ...
- linux下安装JMeter(小白教程)
用windows平台测试时,会受到网络条件的影响,导致测试结果不够准确,尤其是高并发的情况下,需要能够精准的测试请求的响应时长,对于网络的要求更加苛刻.在这样的情况下,可以考虑在linux服务器端安装 ...
- cmd 运行 java 文件
在安装好jdk 并配置好环境变量的情况下 原因一:没有指定class文件的路径 例如HI是变异好的class文件,并且在d:/RJAZB里面 如果写成 Java HI 则会报错 正确做法 java ...
- UVA1595_Symmetry
给出平面上n个点,问你能不能找到一个竖线让他们对称 这道题后面发现真的不难,又不止一种方法 我当时写的很挫,死脑筋的就找一个点的对称点存不存在,用结构体存点信息,在排序用find找,,然后不知道一堆w ...
- 线程组,action to be taken after a sampler error
continue:继续运行后面的请求 start next thread loop:后面的请求不执行,重新循环执行 stop thread:停止所有线程(等待正在执行的线程执行完后,失败的请求后面的 ...
- mongo import excle
mongoimport --host 192.*******.** --db ** --collection ** --type csv --headerline --file /*****.cs ...
- LeetCode Array Easy 1. Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- js 禁止右击保存图片,禁止拖拽图片
禁止鼠标右键保存图片 <img src="" oncontextmenu="return false;"> 禁止鼠标拖动图片 <img src ...
- Android中XML的命名空间、自定义属性
命名空间(namespace) XML 命名空间提供避免元素命名冲突的方法. 举个例子,A学校有名学生叫做林小明,B学校也有名学生叫林小明,那我们如何识别这两名拥有相同名字的同学呢?这时候命名空间就派 ...
- ios执行失去焦点,不执行点击事件
原因:由于JavaScript为单线程,同一时间只能执行处理一个事件.“blur优先于click执行”.而在本示例中,由于blur处理程序,会将对下拉框展示区隐藏,所以导致其后续click事件并不会执 ...
