poj1092. 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 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
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
map<char,int> beads;
int main(){
//freopen("C:INPUT.txt", "r", stdin);
string s1;
cin>>s1;
int i;
for(i=;i<s1.length();i++){
beads[s1[i]]++;
}
string s2;
cin>>s2;
int count=;
for(i=;i<s2.length();i++){
if(!beads[s2[i]]){
count++;
continue;
}
beads[s2[i]]--;
}
if(count){
printf("No %d\n",count);
}
else{
printf("Yes %d\n",s1.length()-s2.length());
}
return ;
}
poj1092. To Buy or Not to Buy (20)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- PAT_A1092#To Buy or Not to Buy
Source: PAT A1092 To Buy or Not to Buy (20 分) Description: Eva would like to make a string of beads ...
- 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 ...
- 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 ...
- PAT Advanced 1092 To Buy or Not to Buy (20) [Hash散列]
题目 Eva would like to make a string of beads with her favorite colors so she went to a small shop to ...
随机推荐
- python(二):可变参数
python中的函数定义: def func(参数, 默认参数, 可变参数) ... 可变参数有两种定义方式: def func(*args): ... 调用方式为func(arg1, arg2, a ...
- SQL的发展史
在20世纪60年代,网状数据库系统(如CODASYL)和分层数据库系统(如IMS TM)是用于自动化银行业务.记帐和订单处理系统的一流技术,这些系统是由于商业大型计算机的引入才启用的.而SQL是在70 ...
- 从一个xaml文件获取xaml内容,遍历寻找对象
- Django之博客系统:增加评论
3既然是博客,那肯定就有留言评论系统.在这一章就来建立一个评论系统. 1 创建一个模型来保存评论 2 创建一个表单来提交评论并且验证输入的数据 3 添加一个视图函数来处理表单和保存新的评论到数据库 4 ...
- 实现简易Web服务器(c语言)
任务: (1)实现服务器与客户端间的通信. (2)可以实现HTTP请求中的GET方法. (3)提供静态网页浏览功能,如可浏览:HTML页面,无格式文本,常见图像格式等. (4)提供可以传递参数的动态网 ...
- Git分支管理命令
1. 创建新分支 1)创建新仓库 git init git add README.md git commit -m "readme.md" git remote add origi ...
- BS总结篇
学习Web开发差不多三个月了,这个阶段的学习给自己带来的更多的是视觉的盛宴.从CS的世界一下子来到了BS的地盘,心中除了惊喜还是惊喜.在这里还是希望自己对这三月所学的东西做一个阶段性的总结. 话不多说 ...
- 服务器部署php项目
windows服务器 首先打开开始菜单,点击运行. 然后输入mstsc,确定 输入你的服务器IP,点击连接 这里选择 是 然后就到了登录界面,输入用户名和密码就可以了 linux服 ...
- loj #6261 一个人的高三楼 FFT + 组合数递推
\(\color{#0066ff}{ 题目描述 }\) 一天的学习快要结束了,高三楼在晚自习的时候恢复了宁静. 不过,\(HSD\) 桑还有一些作业没有完成,他需要在这个晚自习写完.比如这道数学题: ...
- google ---gson字符串数组用GSON解析然后用逗号隔开拼接,去掉最后一个逗号
public static void main(String[] args) { String ss= "[{\"type\":\"0\",\&quo ...