Source:

PAT A1092 To Buy or Not to Buy (20 分)

Description:

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

Keys:

Code:

 /*
Data: 2019-07-21 19:14:54
Problem: PAT_A1092#To Buy or Not to Buy
AC: 10:50 题目大意:
给定字符串S和T,S是否包含T的所有元素
若包含,则返回多余字符个数
若不包含,则返回缺失字符个数 */ #include<cstdio>
#include<string>
#include<iostream>
using namespace std;
char mp[]={}; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif string s,t;
int cnt=;
cin >> s >> t;
for(int i=; i<s.size(); i++)
mp[s[i]]++;
for(int i=; i<t.size(); i++)
{
mp[t[i]]--;
if(mp[t[i]]<)
cnt++;
}
if(cnt > )
printf("No %d\n", cnt);
else
printf("Yes %d\n", s.size()-t.size()); return ;
}

PAT_A1092#To Buy or Not to Buy的更多相关文章

  1. PAT1092:To Buy or Not to Buy

    1092. To Buy or Not to Buy (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

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

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

  4. poj1092. To Buy or Not to Buy (20)

    1092. To Buy or Not to Buy (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

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

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

  7. A1092. To Buy or Not to Buy

    Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy ...

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

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

随机推荐

  1. 为什么对象被new 以后在执行dup操作?

    为什么对象被new 以后在执行dup操作? 今天有个朋友问我,为什么一个new一个对象的指令在new后面紧跟的是dup操作?他说搜了可能找到的 搜索引擎都找不到答案,包括翻了<<深入JAV ...

  2. DPL, CPL及RPL之间的关系

    DPL: Descriptor Privilege Level 1) GDT/LDT表中的描述符 GDT/LDT表中的描述符,描述的是一段内存. 其中的DPL代表着GDT/LDT中的描述符描述的内存段 ...

  3. python3_列表(修改,添加和删除元素操作)

    前言:列表的定义:列表是由一系列按特定顺序排列的元素组成.即列表是一个有序集合. 1.修改列表元素 由前言知列表是一个有序集合,因此在修改列表元素时我们需指定列表名和要修改的元素的索引,再指定该元素的 ...

  4. upc组队赛2 Super-palindrome【暴力枚举】

    Super-palindrome 题目描述 You are given a string that is consisted of lowercase English alphabet. You ar ...

  5. 嵌入式C语言4.4 C语言内存空间的使用-多级指针

    多级指针 int **p; 存访地址的地址空间

  6. 【痛定思痛】TCP 三次握手学习

    前言:今天滴滴面试失败,痛定思痛,好好复习面试中最惨淡的计算机网络部分 面试中,面试官问我TCP与UDP最大的区别是什么,答:TCP可靠,UDP不可靠,一个面向有连接,一个面向无连接,一个快一个慢:追 ...

  7. Linux下的解压缩

    Linux下常见的压缩包格式有5种:zip tar.gz tar.bz2 tar.xz tar.Z 其中tar是种打包格式,gz和bz2等后缀才是指代压缩方式:gzip和bzip2 filename. ...

  8. 纯css设置元素过渡效果

    1.首先,先设置一个div,待会我们使用css3给这个div设置过渡效果. 2.然后给div设置宽高和背景,这里我就设置成200像素,深粉色. 3.接着开始设置transition属性,通过这个属性就 ...

  9. Python之字符串搜索和替换

    简单直接使用 str.replace() text="zzy is a beautiful boy" print(text.replace("boy",&quo ...

  10. JNI Hello World

    1.什么是JNI:               JNI(Java Native Interface):java本地开发接口               JNI是一个协议,这个协议用来沟通java代码和 ...