1092. To Buy or Not to Buy (20)-map
给出两个字符串,判断第二个字符串中的字符是否都出现在第一个中。
是,则输出Yes,以及多余的字符的个数。
否,则输出No,以及缺失的个数。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
const int maxn=+;
const int maxbeads=;
int numshop[maxbeads];
int numeva[maxbeads];
int vis[maxbeads];
int main()
{
char shop[maxn],eva[maxn];
scanf("%s %s",shop,eva);
int len1=strlen(shop);
int len2=strlen(eva);
char ch;
memset(numshop,,sizeof(numshop));
memset(numeva,,sizeof(numeva));
memset(vis,,sizeof(vis));
for(int i=;i<len1;i++){
ch=shop[i];
if(''<=ch&&ch<=''){
numshop[ch-'']++;
}
else if('a'<=ch&&ch<='z'){
numshop[ch-'a'+]++;
}
else if('A'<=ch&&ch<='Z'){
numshop[ch-'A'+]++;
} }
for(int i=;i<len2;i++){
ch=eva[i];
if(''<=ch&&ch<=''){
numeva[ch-'']++;
vis[ch-'']=;
}
else if('a'<=ch&&ch<='z'){
numeva[ch-'a'+]++;
vis[ch-'a'+]=;
}
else if('A'<=ch&&ch<='Z'){
numeva[ch-'A'+]++;
vis[ch-'A'+]=;
} }
bool flag=true;
int left=,miss=;
for(int i=;i<maxbeads;i++){
if(!vis[i]){
left+=numshop[i];
continue;
}
if(numshop[i]>=numeva[i]){
left+=numshop[i]-numeva[i];
}
else{
miss+=numeva[i]-numshop[i];
flag=false;
}
}
if(flag)
printf("Yes %d",left);
else
printf("No %d",miss);
return ;
}
1092. To Buy or Not to Buy (20)-map的更多相关文章
- 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 ...
- 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 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 ...
随机推荐
- Hadoop HBase概念学习系列之HBase里的HRegion(五)
首先,要区分,HRegion服务器包含两大部分:HLog部分和HRegion部分 HBase里的HRegion服务器 HBase里的HRegion 当表的大小超过设置值的时候,HBase会自动将表划 ...
- sql语句查询月份的数据
在实际项目中,经常需要按月查询数据,在这里把我用到的sql整理一下,以便日后查看. 例如,查询当月的数据 ),addtime,)),) 查询结果: 查询上月的数据,需要用另一个sql函数,datead ...
- beta冲刺————第四天(4/5)
完善的具体内容: 前端:以下的功能还未完全实现 (1)点击收藏可以收藏入收藏夹 (2)分享操作,意见反馈 后端: 寻找文章来源,像数据库中增添了150篇的新文章.(我们的文章都要求自己内部人员看过,所 ...
- 一篇关于介绍php的几个user 认证相关的几个包
http://kodeinfo.com/post/laravel-authentication-packages LARAVEL AUTHENTICATION PACKAGES By Imran Iq ...
- [python]如何理解uiautomator里面的 instance 及使用场景
通过uiautomatorviewer打开之后,需要通过对某个控件进行操作,但在当前界面中该控件所有属性无法唯一(其它控件属性也是一样),这个时候就需要借助实例(instance)来进行区分,inst ...
- JavaScript中数组slice和splice的对比小结
前言 今天重温了一下Javascript,看到了数组的方法,其中有两个比较相似的方法——splice和splice,看着很像,就是多了一个p,但是用法却相当不一样. 在使用中,可以通过选择一个具有强语 ...
- Swift Package Manager(一)初探
一句话:Swift Package Manager(swift包管理器,简称:SPM)就是在swift开发中用来替代CocoaPod的:在swift开发中,SPM完全可以替代CocoaPod的功能,并 ...
- Mapreduce运行过程分析(基于Hadoop2.4)——(二)
4.3 Map类 创建Map类和map函数.map函数是org.apache.hadoop.mapreduce.Mapper类中的定义的,当处理每一个键值对的时候,都要调用一次map方法,用户须 ...
- Kafka学习之路 (一)Kafka的简介
一.简介 1.1 概述 Kafka是最初由Linkedin公司开发,是一个分布式.分区的.多副本的.多订阅者,基于zookeeper协调的分布式日志系统(也可以当做MQ系统),常见可以用于web/ng ...
- 关于ST-Link下载STM32程序的使用
ST-Link非常好用,既可以像JLINK那样在软件中直接下载,,也可以下载Hex文件, 自己买的这种,,,, 其实就是SWD下载模式 安装驱动 所有用到的 链接:http://pan.baidu.c ...