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 ...
随机推荐
- MySQl 截取函数 left(),right(),substring(),substring_index() 的用法
1. 字符串截取:left(str, length) mysql> select left('sqlstudy.com', 3); +-------------------------+ | l ...
- Windows-WAMP搭建与配置
使用 WampServer 整合软件包进行 WAMP 环境搭建 WampServer 是一款由法国人开发的 Apache Web 服务器.PHP 解释器以及 MySQL 数据库的整合软件包.免去了开发 ...
- mybatis plus CRUD
首先我们的项目建立之后我们要建立一个实体类来对应我们的数据裤中的信息 employee import com.baomidou.mybatisplus.annotation.IdType; impor ...
- Openstack组件部署 — Keystone功能介绍与认证实现流程
目录 目录 前文列表 Keystone认证服务 Keystone认证服务中的概念 Keystone的验证过程 简单来说 前文列表 Openstack组件部署 - Overview和前期环境准备 Ope ...
- mysql分表分库 ,读写分离
1.分表 当项目上线后,数据将会几何级的增长,当数据很多的时候,读取性能将会下降,更新表数据的时候也需要更新索引,所以我们需要分表,当数据量再大的时候就需要分库了. a.水平拆分:数据分成多个表 b. ...
- python 模拟双色球输出
编写Python函数:完成一个双色球彩票的模拟生成过程, 其中前六个为红色球,数字范围1-33,不可重复.最后一个为蓝色球 1-16. import random #red_nums是采集红色球的数字 ...
- Scrapy框架: 基本命令
1.创建爬虫项目 scrapy startproject [项目名称] 2.创建爬虫文件 scrapy genspider +文件名+网址 3.运行(crawl) scrapy crawl 爬虫名称 ...
- 使用python解析C代码
我有一个巨大的C文件(~100k行),我需要能够解析.主要是我需要能够从其定义中获取有关每个结构的各个字段的详细信息(如结构中每个字段的字段名称和类型).是否有一个好的(开源,我可以在我的代码中使用) ...
- Maven入门指南11:使用Nexus搭建Maven私服
1 . 私服简介 私服是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构件.有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库:否则,私服请求外部 ...
- css雪碧图(精灵图)与字体图标的介绍以及对比
css雪碧图(精灵图)与字体图标的介绍以及对比 设想一个实际场景:在一个页面为了展示,我们放置了很多独立的小图片,浏览器在显示页面的时候,就需要向服务器就会发送很多请求,来获取并加载这些小图片,但是这 ...