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 ...
随机推荐
- SQL SERVER 提供了一些时间函数:
SQL SERVER 提供了一些时间函数:取当前时间:select getdate()取前一个月的时间:SELECT DATEADD(MONTH,-1,GETDATE()) 月份减一个月取年份:SEL ...
- MasterPage + UpdatePanel + FileUpload
上传文件在母版页与Ajax的UpdatePanel的环境进行.由于在母版内使用Ajax,建议使用AjaxControlToolkit.dll组件,去微软官网下载后,并拉入BIN目录中. 然后去web. ...
- [CentOS7] 安装sogou输入法
CentOS7 下的默认输入法不是很好用,于是还是用sogou输入法 由于官网只有Ubuntu版本的sogou输入法安装包,于是先下载下来再说,博主用的版本在这里(密:ph13): 接下来解压data ...
- 实现简易Web服务器(c语言)
任务: (1)实现服务器与客户端间的通信. (2)可以实现HTTP请求中的GET方法. (3)提供静态网页浏览功能,如可浏览:HTML页面,无格式文本,常见图像格式等. (4)提供可以传递参数的动态网 ...
- [Django笔记] views.py 深入学习
views.py 是django MTV 中的主要逻辑层,相当于MVC中的 Controller 以下的实例都基于这样一个路由表: urlpatterns = [ url(r'^(index)?$', ...
- ASP.NET-GridView之导出excel或word
在CS阶段我们涉及到表格的导出,再Web开发同样可以实现,而且实现形式多种多样.以下面的例子说明表格导出到excel和word 这里用到了一个后台方法输出流形成***文件的的公共方法 DEMO < ...
- Django 实现的分页类
后台实现的一个分页类: from django.utils.safestring import mark_safe class Page: def __init__(self, current_pag ...
- 老男孩Day3作业:工资管理系统
作业需求: 1.从info.txt文件中读取员工及其工资信息,最后将修改或增加的员工工资信息也写入原info.txt文件. 2.能增查改员工工资 3.增.改员工工资用空格分隔 4.实现退出功能 1)编 ...
- P2245 星际导航 瓶颈路
\(\color{#0066ff}{ 题目描述 }\) sideman 做好了回到 \(\text{Gliese}\) 星球的硬件准备,但是 \(\text{sideman}\) 的导航系统还没有完全 ...
- UESTC 1437
LCA模板题 随便找的倍增模板... #include<bits/stdc++.h> using namespace std; const int maxn = 1e5+11; int t ...