【PAT】【Advanced Level】1092. To Buy or Not to Buy (20)
来源:互联网 发布:淘宝商城女棉鞋 编辑:程序博客网 时间:2024/06/05 14:08
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 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:ppRYYGrrYBR2258YrR8RrYSample Output 1:
Yes 8Sample Input 2:
ppRYYGrrYB225YrR8RrYSample Output 1:
No 2
https://www.patest.cn/contests/pat-a-practise/1092
思路:
map映射个数,然后逐位判断
CODE:
#include<iostream>#include<map>#include<cstring>#include<string>using namespace std;map<char,int> ma;int main(){string a,b;cin>>a>>b;for (int i=0;i<a.length();i++){if (ma[a[i]]==0)ma[a[i]]=1;elsema[a[i]]++;}int l=0;for (int i=0;i<b.length();i++)if (ma[b[i]]==0)l++;elsema[b[i]]--;if (l==0){cout<<"Yes "<<a.length()-b.length();}elsecout<<"No "<<l;return 0;}
- PAT (Advanced Level) 1092. To Buy or Not to Buy (20) 哈希
- 1092. To Buy or Not to Buy (20)【水题】——PAT (Advanced Level) Practise
- 【PAT】【Advanced Level】1092. To Buy or Not to Buy (20)
- PAT-PAT (Advanced Level) Practise To Buy or Not to Buy(20) 【一星级】
- PAT (Advanced Level) Practise 1092 To Buy or Not to Buy (20)
- PAT (Advanced Level) Practise 1092 To Buy or Not to Buy (20)
- Pat(Advanced Level)Practice--1092(To Buy or Not to Buy)
- PAT A 1092. To Buy or Not to Buy (20)
- PAT 1092. To Buy or Not to Buy (20)
- pat 1092. To Buy or Not to Buy (20)
- PAT 1092. To Buy or Not to Buy (20)
- 【PAT】1092. To Buy or Not to Buy (20)
- PAT 1092. To Buy or Not to Buy (20)
- PAT-A 1092. To Buy or Not to Buy (20)
- PAT-A-1092. To Buy or Not to Buy (20)
- Pat(A) 1092. To Buy or Not to Buy (20)
- PAT 1092. To Buy or Not to Buy
- PAT 1092. To Buy or Not to Buy(STL)
- 移动开发webapp开发常用meta设置(手机浏览器全屏模式 html5)
- 栈的基本操作
- Socket 通信流程
- C# 匿名对象(匿名类型)、var、动态类型 dynamic
- git 拉新分支、分支关联、合并分支、分支删除
- 【PAT】【Advanced Level】1092. To Buy or Not to Buy (20)
- RxJava的一些标志符号学习(一)
- Python学习笔记 9
- butterKnife注解不起作用问题
- MD5加密String
- redis集群搭建
- Tomcat端口号修改
- LED的流水灯实验
- First