PAT_A1092#To Buy or Not to Buy
Source:
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 isNo
, 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 isNo
, 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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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甲级——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 ...
随机推荐
- upc组队赛12 Janitor Troubles【求最大四边形面积】
Janitor Troubles Problem Description While working a night shift at the university as a janitor, you ...
- python学习笔记:接口开发——PythonWEB框架之Flask
Flask是一个使用 Python 编写的轻量级 Web 应用框架,安装命令如下 pip install flask 一.服务端接口是怎么开发的? 1.启动一个服务 2.接收到客户端传过来的数据3.登 ...
- 10.Jmeter 快速入门教程 -- 用Jmeter测试你的EJB
有时候,需要对EJB进行性能基准测试,这对开发非常有帮助. 有很多种方法可以这么做, 当然我们这里介绍Apache's Jmeter 来进行实验测试. 非常不幸的是, Jmeter没有提供一个现成的测 ...
- activiti7查询历史数据
package com.zcc.activiti02; import org.activiti.engine.HistoryService;import org.activiti.engine.Pro ...
- nginx 配置反向代理和静态资源
https://unit.nginx.org/integration/ 与NGINX集成 在NGINX后面安装单元 将NGINX配置为静态Web服务器,并在Unit前面配置反向代理. NGINX直接从 ...
- ubuntu中搭建基本的开发环境
1.搭建基本开发环境: sudo apt-get install build-essential 2.安装语法.词法分析器 sudo apt-get install bison flex 3.安装C函 ...
- pytest---参数化
import pytest @pytest.mark.parametrize('test_input,expected',[('3+5',8), ('2-1',1),('7*5',30)])def t ...
- tinkphp5.0目录结构说明
tinkphp5.0目录结构说明 project 应用部署目录 ├─application 应用目录(可设置) │ ├─common 公共模块目录(可更改) │ ├─index 模块目录(可更改) │ ...
- js 连等操作,,
奥术大师 var hu = { a : , c : , name : }; (function (){ var ccc = bbb = aaa = hu; })() console.log(bbb)* ...
- rest framework之过滤组件
一.普通过滤 (一)get_queryset get_queryset方法是GenericAPIView提供的一个方法,旨在返回queryset数据集,而过滤就是要在这个方法返回数据集之前对数据进行筛 ...