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 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 2:
No 2
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <stack>
#include <vector>
#include <queue>
#include <set>
#define LL long long
using namespace std;
const int MAX = 2e3 + ; char s1[MAX], s2[MAX];
map <char, int> mp1;
map <char, int> mp2;
map <char, int> :: iterator iter;
int cnt = ; int main()
{
// freopen("Date1.txt", "r", stdin);
scanf("%s%s", &s1, &s2);
int len1 = strlen(s1), len2 = strlen(s2);
for (int i = ; i < len1; ++ i)
mp1[s1[i]] ++;
for (int i = ; i < len2; ++ i)
mp2[s2[i]] ++; for (iter = mp2.begin(); iter != mp2.end(); ++ iter)
{
if (mp1.find(iter->first) == mp1.end())
cnt += iter->second;
else if (mp1[iter->first] < iter->second)
cnt += iter->second - mp1[iter->first];
}
if (cnt == )
printf("Yes %d\n", len1 - len2);
else
printf("No %d\n", cnt);
return ;
}
pat 1092 To Buy or Not to Buy(20 分)的更多相关文章
- PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642
PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642 题目描述: With the 2010 FIFA World Cu ...
- PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642
PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642 题目描述: People in Mars represent the c ...
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642
PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...
- PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642
PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642 题目描述: Given a non-negative integer N ...
- PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642
PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642 题目描述: Calculate a+b and output the sum i ...
- PAT甲级:1124 Raffle for Weibo Followers (20分)
PAT甲级:1124 Raffle for Weibo Followers (20分) 题干 John got a full mark on PAT. He was so happy that he ...
- PAT乙级:1087 有多少不同的值 (20分)
PAT乙级:1087 有多少不同的值 (20分) 当自然数 n 依次取 1.2.3.--.N 时,算式 ⌊n/2⌋+⌊n/3⌋+⌊n/5⌋ 有多少个不同的值?(注:⌊x⌋ 为取整函数,表示不超过 x ...
- PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) (找最值)
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...
- 【PAT】B1037 在霍格沃茨找零钱(20 分)
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int ...
- PAT B1008 数组元素循环右移问题 (20 分)
一个数组A中存有N(>)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥)个位置,即将A中的数据由(A0A1⋯AN−1)变换为(AN−M⋯AN−1A ...
随机推荐
- Cocos2d-x 学习笔记(19) Control Invocation
[Cocos2d-x 学习笔记 目录链接] 1. 简介 control为其子类提供了touch回调函数,当子类触发EventType相关事件时,会调用相关的回调函数. control对象接收到的事件类 ...
- s32k144 bootloader
s32k144 bootloader升级 mcu : s32k144 can_tool : kvaser 摘要:实现can升级app程序,现在网上大多是CAN_FD升级bootloade ...
- POJ 3259 Wormholes(Bellman-Ford)
题目网址:http://poj.org/problem?id=3259 题目: Wormholes Time Limit: 2000MS Memory Limit: 65536K Total Su ...
- 12.Nginx代理与负载均衡
1.什么是代理? 代为办理 --> 代理 2.Nginx正向代理.反向代理 正向代理: --> 上网 | 路由器替代 反向代理: --> 正向与反向代理的区别: 区别在于形式上服务的 ...
- webpack——npm -i 与npm install -s与-d的区别
在 package.json 文件里面的[devDependencies]和[dependencies]对象有什么区别呢? devDependencies 里面的插件只用于开发环境,不用于生产环境, ...
- Mysql分表的一个考虑
今天看到一篇博客,讲述的是Mysql的分表方案,内容比较简单,不过有个思路倒是挺好的,记录下,后续分表可以参考 作者主要是说到两种分表,一个是取模,另一个是范围分表 取模:比如用户ID%10,分10张 ...
- LeetCode686——Repeated String Match
题目:Given two strings A and B, find the minimum number of times A has to be repeated such that B is a ...
- Ubuntu 16.04下配置 Nginx 与 Node.js 以及服务的部署
第一步:安装nginx sudo apt-get update sudo apt-get install nginx 如果遇到依赖问题,尝试执行sudo apt-get -f install命令 第二 ...
- pycharm的使用(day03复习整理)
pycharm的使用 file --> settings --> editor -->general --> change font size .... file --> ...
- Creator 2.2.0 终于等来了这款Shader组件神器!一招搞定Effect特效
先看下视频演示: ShaderHelper2支持Creator 2.2.0 视频录完后才想起,还没在微信小游戏中测试,赶紧试试,下面是在微信开发者工具中的截图. 径向模糊 探照灯 提供了一个Shade ...