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 ...
 
随机推荐
- mysql 多主
			
原理:多个msyql/mariadb之间可以实时同步,任意节点的操作可以立即同步到其他节点,底层采用galera插件同步,类似rsync,上层mysql相对于galera是透明的,可以实现多节点同时读 ...
 - LInux下设置账号有效时间 以及 修改用户名(同时修改用户组名和家目录)
			
在linux系统中,默认创建的用户的有效期限都是永久的,但有时候,我们需要对某些用户的有效期限做个限定!比如:公司给客户开的ftp账号,用于客户下载新闻稿件的.这个账号是有时间限制的,因为是付费的.合 ...
 - javascript DOM操作中的insertAdjacentHTML方法
			
插入HTML内容与文本内容以前用的是innerHTML与innerText方法,今天看到insertAdjacentHTML和 insertAdjacentText两个API,特地学习一下: inse ...
 - 路由嵌套 active
			
http://www.jb51.net/article/102574.htm; https://segmentfault.com/q/1010000008950255 <el-menu :def ...
 - 软件工程M1/M2总结及阅读作业总结
			
一.软件工程M1/M2总结 写下这篇总结的时候,我们的软件项目尚未完工.虽然尝试申请了延期答辩,但最终未能成功.这意味着,我们的项目能否正常发布已经处于了一个微妙的状态.可能可以,也可能不可以.只能尽 ...
 - [福大软工] Z班——Alpha现场答辩情况汇总
			
Alpha现场答辩 小组互评(文字版) 各组对于 麻瓜制造者 的评价与建议 队伍名 评价与建议 *** 界面较友好,安全性不足,功能基本完整.希望能留下卖家的联系方式而不是在APP上直接联系,APP上 ...
 - Java正则解析HTML一例
			
import java.util.regex.Matcher;import java.util.regex.Pattern; public class Test { static String tes ...
 - SQLSERVER 2014 SP1 的服务器 日志文件无法收缩的处理
			
1. 公司一台服务器 日子会文件到了 100g+ 但是无法收缩 2. 根据同事的经验进行验证 dbcc loginfo 单独看改数据库的 dbcc loginfo("CWBASEGS60&q ...
 - Jquery  ajax load(),get(),post()
			
//load()用来加载html文档中的代码片段,添加到指定元素内部 //如果只加部分选定的元素可以.load("url 选择器") <!DOCTYPE html>&l ...
 - BFC——块级格式化上下文
			
BFC(块级格式化上下文) 一.BFC是什么? 从样式上看,具有BFC的容器和普通的容器没有区别.从功能上看,具有BFC的容器可以看作是隔离了的容器,容器里面的元素不会影响到外面的元素,并且BFC具有 ...