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 1:
- No 2
#include<stdio.h>
#include<string.h>
#include<math.h>
char a[1010],b[1010];
int c[200],d[200],e[200];
int main()
{
int i,j,l1,l2,s=0;
scanf("%s%s",a,b);
memset(c,0,sizeof(c));
memset(d,0,sizeof(d));
memset(e,0,sizeof(e));
l1=strlen(a);
l2=strlen(b);
for(i=0;i<l2;i++)
{
c[b[i]]++;
}
for(i=0;i<l1;i++)
{
d[a[i]]++;
}
for(i=0;i<l2;i++)
{
if(c[b[i]]>d[b[i]]&&e[b[i]]==0)
{
s+=c[b[i]]-d[b[i]];
}
e[b[i]]=1;
}
if(s==0)
{
printf("Yes %d\n",l1-l2);
}
else
{
printf("No %d\n",s);
}
return 0;
}
1092. To Buy or Not to Buy (20)的更多相关文章
- 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 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 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 ...
- 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_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 ...
- 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 ...
- PAT Advanced 1092 To Buy or Not to Buy (20) [Hash散列]
题目 Eva would like to make a string of beads with her favorite colors so she went to a small shop to ...
- PAT (Advanced Level) 1092. To Buy or Not to Buy (20)
简单题. #include<cstdio> #include<cstring> ; char s1[maxn],s2[maxn]; ]; ]; int main() { sca ...
随机推荐
- Markdown 编辑器语法指南
基本技巧 代码 如果你只想高亮语句中的某个函数名或关键字,可以使用 `function_name()` 实现 通常编辑器根据代码片段适配合适的高亮方法,但你也可以用 ``` 包裹一段代码,并指定一种语 ...
- Python批量插入SQL Server数据库
因为要做性能测试,需要大量造数据到数据库中,于是用python写了点代码去实现,批量插入,一共四张表 简单粗暴地插入10万条数据 import pymssql import random __auth ...
- 学习总结 java 异常
package com.hanqi.ec; public class Test1 { public static void main(String[] args) { int a = 10 , b = ...
- ICDM 2007
Language-Independent Set Expansion of Named Entities Using the Web. Chao Wang, Venu Satuluri, Sriniv ...
- java排序练习
public void testSort3(){ List<String> str=new ArrayList<String>(); String st="12345 ...
- github的入门使用
原文 http://www.eoeandroid.com/thread-274556-1-1.html [初识Github]首先让我们大家一起喊一句“Hello Github”.YEAH!就是这样. ...
- Android IOS WebRTC 音视频开发总结(二九)-- 安卓噪声消除交流
Android上的音质一直被大家所困扰和诟病,这里面有很多原因, 下面是最近一位前UC同行发邮件跟我交流的一些记录,供参考,支持原创,文章来自博客园RTC.Blacker,转载请说明出处. 以下文字来 ...
- Large-Scale Named Entity Disambiguation Based on Wikipedia Data
Large-Scale Named Entity Disambiguation Based on Wikipedia Data 基于维基百科数据的大规模命名实体消岐 1.引言 1.1. 概念 实体(e ...
- EasyUI 后台管理系统
基础功能版: 测试地址:http://dev.blueapp.cn/index.php/2014/07/03/101/ 用户名:admin密码:123456 有问题可一起探讨,源码后期将放出 一直未测 ...
- CentOS学习笔记—软件管理程序RPM、YUM
软件管理程序 Linux的软件安装分为源代码编译安装和打包安装.RPM是一种打包安装方式,是由 Red Hat 这家公司开发出来的,后来实在很好用,因此很多 distributions 就使用这个机制 ...