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 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的更多相关文章
- 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 ...
- 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 ...
- PAT1092:To Buy or Not to Buy
1092. To Buy or Not to Buy (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Ionic 2.0 相关资料
原文发表于我的技术博客 本文汇总了学习 Ionic 2 的相关资料,也算是一个 Ionic Awesome 列表,供大家参考,有需要分享的可以留言. 原文发表于我的技术博客 1. 文档 1.1 Ion ...
- Linux下对文件进行加密备份的操作记录
由于公司之前在阿里云上购买了一些机器,后续IDC建设好后,又将线上业务从阿里云上迁移到IDC机器上了,为了不浪费阿里云上的这几台机器资源,打算将这些机器做成IP SAN共享存储,然后作为IDC数据的一 ...
- 更换Ubuntu源为国内源的操作记录
我们都知道,Ubuntu的官方源对于国内用户来说是比较慢的,可以将它的源换成国内的源(比如阿里源),这样用起来就很快了.下面记录下更换操作: 首先了解下/etc/apt/sources.list文件 ...
- linux系统最小化安装后的初始化脚本
作为运维人员,经常会初始化系统,系统在安装过程中基本都会选择最小化安装,这样安装好的系统里会缺少很多环境. 下面分享一个系统安装后的初始化脚本: #!/bin/bash #系统时最小化安装的,这里要安 ...
- Visual Studio 2013编辑器+SourceTree代码管理工具及扩展工具
Visual Studio 2013: 美国微软公司的编辑开发工具 扩展工具: Resharper:进行深度代码分析,函数深度查询(ctrl+鼠标左): Grunt:是基于Node.js的项目以自动化 ...
- Bing词典案例分析
一.调研评测 Bug 1 : 当鼠标移动到可点击的地方的时候,光标的样子并没有变成手指状而是插入符号状.这影响了用户对按钮是否可用的判断,也会让用户在一定程度上不适应,不利于软件的长期发展. Bug ...
- Linux基础实践
Linux基础实践 1.1 应用安装 要求:掌握软件源的维护方法,配置系统使用软件源镜像.掌握通过软件源来查找,安装,卸载,更新软件的方法 备份原地址列表文件:sudo cp /etc/apt/sou ...
- EL表达式和JSTL标签库
expresion language表达式语言 可以输出表达式的值.跟jsp的表达式脚本一样.计算表达式的值后输出. EL表达式出现的目的是为了使JSP写起来更加简单,让jsp的代码更佳简化. 1. ...
- mybatis批量插入和批量更新
批量插入数据使用的sql语句是: insert into table (aa,bb,cc) values(xx,xx,xx),(oo,oo,oo) mybatis中mapper.xml的代码如下: & ...
- [转帖] ASP ASPX 等知识
asp.asp.net..aspx..ascx..ashx的简单说明 https://www.cnblogs.com/jhcelue/p/6736147.html ASP是动态server页面(Act ...