1092 To Buy or Not to Buy
题意:给出两个字符串s1和s2(长度不超过1000),问s1是否包含s2中的所有字符,若包含,则输出Yes,并输出s1中多余的字符个数;若不完全包含,则输出No,并输出缺少的个数。
思路:定义数组int cnt[128],遍历字符串s1,记录各个字符出现的次数,cnt[i]表示i对应的字符出现的次数;然后遍历字符串s2,每访问一个字符,就把对应的cnt[i]减1,当遍历完了之后,若cnt[]均大于等于0,则说明s1含有s2的所有字符,输出Yes,以及strlen(s1)-strlen(s2);否则,说明s1不完全包含s2的所有字符,cnt[]中小于0的绝对值即为缺少的字符个数。
代码:
#include <cstdio> #include <cstring> int main() { //freopen("pat.txt","r",stdin); ],str2[]; scanf("%s",str1); scanf("%s",str2); ]={}; int len1=strlen(str1); ;i<len1;i++) cnt[str1[i]]++; int len2=strlen(str2); ; ;i<len2;i++){ cnt[str2[i]]--; ) miss++; } ) printf("No %d",miss); else printf("Yes %d",len1-len2); ; }
1092 To Buy or Not to Buy的更多相关文章
- 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 ...
- 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 ...
- PAT1092:To Buy or Not to Buy
1092. To Buy or Not to Buy (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- 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_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 ...
随机推荐
- ECS vs. Kubernetes 类似而又不同
C2Container Service (ECS)和Kubernetes (K8s) 都解决了同样的问题:跨越主机集群管理容器.ECS和Kubernetes之间的斗争让我想起了vi和Emacs之间的编 ...
- PHP使用前的了解
PHP简介 PHP 是什么? PHP(全称:PHP:Hypertext Preprocessor,即"PHP:超文本预处理器")是一种通用开源脚本语言. PHP 脚本在服务器上执行 ...
- [JavaScript]对象创建方法
1.使用Object或对象字面量创建对象 (1)使用Object创建对象 var cat= new Object(); cat.name = "Tom"; cat.color= & ...
- SPOJ - LCS2
后缀自动机板子题 https://vjudge.net/problem/28017/origin 找多串的最长公共子串 //#pragma comment(linker, "/stack:2 ...
- 基于mysql的全文索引
支持引擎:mysql的MyISAM存储引擎和Innodb存储引擎(5.6及其以上)支持. 适用类型:char.varchar和text. 新建方法:ALTER TABLE article ADD F ...
- pycharm 设置 默认信息
在pycharm使用过程中,对于每次新建文件的shebang行和关于代码编写者的一些个人信息快捷填写,使用模板的方式比较方便. 方法如下: 1.打开pycharm,选择File-Settings, 2 ...
- hibernate13--缓存
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN&q ...
- Android界面View及ViewGroup学习 《转载》
View及ViewGroup类关系 Android View和ViewGroup从组成架构上看,似乎ViewGroup在View之上,View需要继承ViewGroup,但实际上不是这样的. View ...
- request.setAttribute("username", username);//一定要保存,OGNL才能获取${username}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, ...
- 【python】《利用python进行数据分析》笔记
[第三章]ipython C-a 到行首 C-e 到行尾 %timeit 测量语句时间,%time是一次,%timeit是多次. %pdb是自动调试的开关. %debug中,可以用b 12在第12行设 ...