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<iostream>
using namespace std;
int trans(char c){
if(c >= '' && c <= '')
return c - '';
else if(c >= 'a' && c <= 'z')
return c - 'a' + ;
else return c - 'A' + ;
}
int main(){
char shop[], Eva[];
int hashTB[] = {,};
int flag = ;
scanf("%s %s", shop, Eva);
for(int i = ; shop[i] != '\0'; i++)
hashTB[trans(shop[i])]++;
for(int i = ; Eva[i] != '\0'; i++){
hashTB[trans(Eva[i])]--;
if(hashTB[trans(Eva[i])] < )
flag = ;
}
int ans = ;
if(flag == ){
for(int i = ; i < ; i++)
if(hashTB[i] < )
ans += hashTB[i];
printf("No %d", ans * -);
}else{
for(int i = ; i < ; i++)
ans += hashTB[i];
printf("Yes %d", ans);
}
cin >> Eva;
return ;
}

总结:

1、本题大意:比较店家和EVa的珠子,如果店家的珠子比Eva所需的还要多,那就输出多的个数。如果店家缺少Eva所需的某几种珠子,那么输出所缺的个数。

2、如果有多余的珠子,可以直接输出两串珠子的长度差,而不必统计累加。

A1092. To Buy or Not to Buy的更多相关文章

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

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

  3. PAT1092:To Buy or Not to Buy

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

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

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

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

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

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

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

随机推荐

  1. [UWP 自定义控件]了解模板化控件(5.1):TemplatePart vs. VisualState

    1. TemplatePart vs. VisualState 在前面两篇文章中分别使用了TemplatePart及VisualState的方式实现了相同的功能,其中明显VisualState的方式更 ...

  2. spring cloud服务提供与调用示例

    本文创建方式采用intellij IDEA  创建项目 1.创建基于Eureka的注册中心. 在打开项目中右键,选择new 选择moudle 然后下一步 输入要创建的项目的信息 选择web下面的web ...

  3. HTTP Error 500.22 - Internal Server Error 错误解决方案

    1. 首先进入IIS ,配置IIS 应用程序池的.Net Framework版本 2. 点击左侧应用程序池,再单机右侧设置,选择版本 3. 设置为经典模式 如若遇到以下错误: 解决方案:删除confi ...

  4. Linux下"负载均衡+高可用"集群的考虑点 以及 高可用方案说明(Keepalive/Heartbeat)

    当下Linux运维技术越来越受到企业的关注和追捧, 在某些企业, 尤其是牵涉到电子商务和电子广告类的网站,通常会要求作负载均衡和高可用的Linux集群方案.那么如何实施Llinux集群架构,才能既有效 ...

  5. Visual Studio2013的安装过程及练习测试

    一.安装环境: 支持安装的操作系统版本:Windows XP,Windows7,Windows8,Windows10. CPU大小:Intel(R)Core(TM)i5-4210U CPU @1.7G ...

  6. scenario testing

    我们的APP“吃了么”是专为爱美食的人打造的,典型的用户自然是那些喜欢美食的“吃货”们,当然也可以为想要快速找到周边餐馆的童鞋提供便利.还有一种典型的用户就是喜欢自己烹调食物的人. 我们整理出来了下面 ...

  7. C++编写四则运算生成程序

    1.计划方案 按照预定计划,在时限为一周时,完成该程序所需时间大致如下表: PSP2.1 Personal Software Process Stages Time Planning 计划 · Est ...

  8. rabbitMq与spring boot搭配实现监听

    在我前面有一篇博客说到了rabbitMq实现与zk类似的watch功能,但是那一篇博客没有代码实例,后面自己补了一个demo,便于理解.demo中主要利用spring boot的配置方式, 一.消费者 ...

  9. week3-构造一个简单的linux系统

    潘恒  原创作品转载请注明出处  <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.gdb跟踪调试内核 ...

  10. 网络:LVS负载均衡原理

    LB集群的架构和原理很简单,就是当用户的请求过来时,会直接分发到Director Server上,然后它把用户的请求根据设置好的调度算法,智能均衡地分发到后端真正服务器(real server)上.为 ...