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 ...
随机推荐
- 利用window10的Linux子系统实现docker的安装使用
先参照 此博客 点这里 我在执行 apt installdocker.io 命令时,不能正确的安装 docker client 所以我找了下面的命令,然后执行 docker version 成功了 辅 ...
- 死磕 java线程系列之线程池深入解析——生命周期
(手机横屏看源码更方便) 注:java源码分析部分如无特殊说明均基于 java8 版本. 注:线程池源码部分如无特殊说明均指ThreadPoolExecutor类. 简介 上一章我们一起重温了下线程的 ...
- 百万年薪python之路 -- MySQL数据库之 用户权限
MySQL用户授权 (来自于https://www.cnblogs.com/dong-/p/9667787.html) 一. 对新用户的增删改 1. 增加用户 : ①. 指定某一个用户使用某一个ip登 ...
- SQL common keywords examples and tricks
Case Sensitive Check 1. Return names contain upper case Select id, name from A where name<>low ...
- Robot Framework——对时间操作的datetime库常用关键字
1.对固定日期进行操作,增加或减去单位时间或者时间段 2.对两个时间段进行操作 3.对时间格式转化,获取时间戳 4.从完整时间中取指定年月日等 5.对时间类型进行格式化 6.获取当前时间或者指定时区时 ...
- JSP HTML 各种 乱码 解决方法|jsp include html乱码|include 乱码|MyEclipse 中文乱码
笔者花了一整天研究这个问题 .最终解决了所有的中文乱码问题. 不用 写 过滤器,不用改 tomcat 的配置文件 笔者使用的 软件是 MyEclipse2013 professional 版 JSP ...
- Java基础(二十五)Java IO(2)文件File类
File类是一个与流无关的类.File类的对象可以获取文件及其文件所在的目录.文件的长度等信息. 1.File对象的常用构造方法. (1)File(String pathname) File file ...
- 设计模式C++描述----04.观察者(Observer)模式
一. 概述 Observer 模式要解决的问题为:建立一个一(Subject)对多(Observer)的依赖关系,并且做到当“一”变化的时候,依赖这个“一”的多也能够同步改变. Sbuject 相当于 ...
- centos转ubuntu常见问题总结:
1.vmtools的安装 https://blog.csdn.net/weixin_41762173/article/details/79480832 2.镜像源替换 https://opsx.ali ...
- ElasticSearch head插件安装与配置
下载 下载地址:https://github.com/mobz/elasticsearch-head 安装 1. 下载到本地 git clone 2. 安装 grunt npm install -g ...