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 ...
随机推荐
- MySQL基础之 排序与限制,聚合
排序与限制 ORDER BY 作用:取出按照某个字段进行排序后的记录结果集. 配合:常与DESC 和ASC一块使用:默认是ASC,表示升序.DESC表示降序 LIMIT 作用:用于显示数据的一部分记 ...
- MySQL数据库的安装与基本操作
实验要求: 1.安装mysql源码包,并做相关的配置和优化路径,启动服务. 步骤: 1)先查询MySQL软件的安装情况,如果有建议将其卸载, 2)安装光盘自带的ncurses-devel包. 3)My ...
- SecureCRT Win免安装版本,简单好用
SecureCRT是一款支持SSH(SSH1和SSH2)的终端仿真程序,简单地说是Windows下登录UNIX或Linux服务器主机的软件. 这个简单好用,程序员必备. 下载地址:SecureCRT. ...
- Nowcoder 提高组练习赛-R7
Nowcoder 提高组练习赛-R7 https://www.nowcoder.com/acm/contest/179#question 中间空了两场,因为实在是太难了... 第五场的第二题好像还比较 ...
- Moleskine智能笔+专用本:写完随时传到手机
http://www.totiot.com/61805.html Moleskine公司生产的速写本和速写板一直是涂鸦爱好者和速记员们的首选.该公司还联合Adobe. Livescribe. Ever ...
- MP实战系列(十一)之封装方法详解(续一)
之前写的封装方法详解,比较简要. 今天我主要讲增加和删除及其修改.查的话得单独再详讲. 增删改查,无论是Java或者C#等等,凡是对数据库操作的都离不开这四个. 一.增加方法讲解 MyBatis Pl ...
- Springmvc常见问题
问题一:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userCont ...
- redis集群搭建及连接(阿里云)
阿里云上面装redis集群基本被虐死,主要问题就是私有IP和公有IP. 下面分享成功搭建的步骤: 两台测试服务器,分别为:127.0.0.1,127.0.0.2.每分服务器有3个节点. 1.127.0 ...
- TCP和UDP套接字编程 (java实现)
在了解网络编程之前,我们先了解一下什么叫套接字 套接字即指同一台主机内应用层和运输层之间的接口 由于这个套接字是建立在网络上建立网络应用的可编程接口 因此也将套接字称为应用程序和网络之间的应用程序编程 ...
- 第16章 STM32中断应用概览
第16章 STM32中断应用概览 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/fi ...