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 ...
随机推荐
- 理解CNN中的通道 channel
在深度学习的算法学习中,都会提到 channels 这个概念.在一般的深度学习框架的 conv2d 中,如 tensorflow .mxnet ,channels 都是必填的一个参数. channel ...
- kuangbin专题16I(kmp)
题目链接: https://vjudge.net/contest/70325#problem/I 题意: 求多个字符串的最长公共子串, 有多个则输出字典序最小的. 思路: 这里的字符串长度固定为 60 ...
- Jmeter-逻辑控制器之Foreach
ForEach 作用:用来遍历当前元素的所有可执行场景:在用户自定义变量中读取一系列相关的变量,该控制器下的采样器或控制器都会被执行一次或多次,每次读取不同的变量值: 输入变量前缀:在其中输入需要遍历 ...
- 查看ip常见命令...
1.获取ip Unix用户可以在命令提示符中输入ifconfig来获取. 使用Windows的用户,请尝试使用 ipconfig 命令.
- 轻量级编辑器透彻指南--Notepad++
Notepad++是Windows环境下的一款编辑器.比起VSCode等现代编辑器,Notepad++同样具备很多功能.Notepad++一个特点就是轻巧,方便在Windows环境中使用,且编辑功能强 ...
- opencv第二课,使用cmake编译OpenCV,并添加opencv_contrib模块
一.下载安装cmake 想要在Windows平台下生成OpenCV的解决方案,我们需要一个名为cmake的开源软件,可以在camke的官网:http://www.cmake.org/上下载到 或者点击 ...
- 3D电影转2D普通电影,电脑上看
下了一些电影,打开发现是左右两个一样的画面,什么情况?原来这就是传说中的3D,怎么像正常电影一样的看呢?第一反应去搜3D眼镜,价钱倒是不贵,但是不应急呀,肿么办?以下是观看方法: 一.看电脑上有QQ影 ...
- freemarker ! 用法
${(user.name)!""} 请注意,是打了()的 也就是它会先判断user是不是为null 在判断user.name 是不是为null
- android:id 中区别。。
一. android:id="@android:id/tabhost" 是调用系统内部的ID 和代码中 mTabContent = (FrameLayout) findView ...
- C#工具类之字典扩展类
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using S ...