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 分)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. PAT乙级:1087 有多少不同的值 (20分)

    PAT乙级:1087 有多少不同的值 (20分) 当自然数 n 依次取 1.2.3.--.N 时,算式 ⌊n/2⌋+⌊n/3⌋+⌊n/5⌋ 有多少个不同的值?(注:⌊x⌋ 为取整函数,表示不超过 x ...

  8. 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 ...

  9. 【PAT】B1037 在霍格沃茨找零钱(20 分)

    #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int ...

  10. PAT B1008 数组元素循环右移问题 (20 分)

    一个数组A中存有N(>)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥)个位置,即将A中的数据由(A​0​​A​1​​⋯A​N−1​​)变换为(A​N−M​​⋯A​N−1​​A ...

随机推荐

  1. Ajax:后台jquery实现ajax无刷新删除数据及demo

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA8gAAAFSCAIAAAChUmFZAAAgAElEQVR4nO29z4scWZbn2/+Hb30zi8

  2. PHP array_reverse

    1.函数的作用:将数组中的元素顺序反转 2.函数的参数: @params array $array 需要反转顺序的数组 @params $preversed_key  数值索引是否保持不变,非数值索引 ...

  3. [洛谷P3613]睡觉困难综合症

    写码30min,调码3h的题.. 好在最后查出来了 , , n, x, y, z); 改成了 , , n, mark[x], y, z); 然后$40\rightarrow 100$ #include ...

  4. postgresql被注入之后

    本来只是贪便宜买了个一年特价的阿里云服务器,做做测试什么的,结果不知道哪一天开始阿里云安全中心就开始给我发什么安全提示类的信息,一开始我并不在意,因为这些都是套路,不过是想让我升级购买高防盾罢了,反正 ...

  5. Javascript对this对象的理解

    在JavaScript中this表示函数运行的时候自动生成的一个内部对象,只能在函数内部使用,下面是一个简单的例子: function test(){ alert(this == window); } ...

  6. vue 列表的排序过渡 shuffle遇到的问题

    内部的实现,Vue 使用了一个叫 FLIP 简单的动画队列使用 transforms 将元素从之前的位置平滑过渡新的位置 需要注意的是使用 FLIP 过渡的元素不能设置为 display: inlin ...

  7. 阿里六面,挂在hrg,我真的不甘心!

    前言最近跟一位朋友聊天,福报场-阿里是大部分程序员的梦想.这位老哥梦想进入阿里很久了,连续两年面试阿里不同bu,有几次是技术面挂,最冤的一次是技术6面了,连P10大老板都面了,但是挂在了hrg. 我以 ...

  8. 10、pytest -- skip和xfail标记

    目录 1. 跳过测试用例的执行 1.1. @pytest.mark.skip装饰器 1.2. pytest.skip方法 1.3. @pytest.mark.skipif装饰器 1.4. pytest ...

  9. SVD分解

    首先,有y = AX,将A看作是对X的线性变换 但是,如果有AX = λX,也就是,A对X的线性变换,就是令X的长度为原来的λ倍数. *说起线性变换,A肯定要是方阵,而且各列线性无关.(回想一下,A各 ...

  10. MYSQL结构修改

    mysql改表结构主要是5大操作 ADD 添加字段 MODIFY 修改字段类型 CHANGE 修改字段名(也可以修改字段名) DROP 删除字段 RENAME 修改表名 ADD添加新字段:(新字段默认 ...