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 ...
随机推荐
- 启动项目时,Mysql的连接问题
1.com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection ...
- npm yarn bower (前端必会的工具)
https://qunitjs.com/ https://www.cnblogs.com/shytong/p/5417789.html
- 为什么重写equals还要重写hashcode
参考回答: HashMap中,如果要比较key是否相等,要同时使用这两个函数!因为自定义的类的hashcode()方法继承于Object类,其hashcode码为默认的内存地址,这样即便有相同含义的两 ...
- angular-file-upload插件的使用简单介绍
参考博客: https://www.cnblogs.com/jarson-7426/p/5191156.html angular-file-upload 最近一段时间用了一下angular-file- ...
- FrameWork内核解析之WindowManagerService(一)中篇
阿里P7Android高级架构进阶视频免费学习请点击:https://space.bilibili.com/474380680 1.WMS概述 WMS是系统的其他服务,无论对于应用开发还是Framew ...
- python基础【第八篇】
day06笔记 1.小数据池 is 与 ==的区别 is :判断两边的内存地址是否相同 ==:判断两边的值是否相同 python中的驻留机制: 数字: -5 ~ 256 字符串: 3.6 乘法 ...
- python+tushare获取上市公司财务报表:资产负债表
接口:balancesheet 描述:获取上市公司资产负债表 积分:用户需要至少500积分才可以调取,具体请参阅本文最下方积分获取办法 注:tushare包下载和初始化教程,请查阅我之前的文章 提示: ...
- ActionEnter cannot be resolved to a type
2014-6-13 23:50:57 org.apache.catalina.core.StandardWrapperValve invoke严重: Servlet.service() for ser ...
- CF1158C
题意:有排列p, 令\(nxt_i\)为\(p_i\)右侧第一个大于\(p_i\)的数的位置,若不存在则\(nxt_i=n+1\) 现在整个p和nxt的一部分丢失了,请根据剩余的nxt,构造出一个符合 ...
- 【java】记录一下java的常用用法
1.二维数组 public static void main(String[] args) { //定义 int a[][] = {{1,2,3},{4,5,6},{7,8,9}}; int [][] ...