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 ...
随机推荐
- Vector3函数理解-计算两向量之间的角度
1.已知两个向量dirA,dirB.Vector3 dirA = new Vector3(-1,1,0); Vector3 dirB = new Vector3(-1,1,1);2.使向量处于同一个平 ...
- PL/SQL通过修改配置文件的方式实现数据库的连接
http://jingyan.baidu.com/article/c74d600080632a0f6a595d80.html
- Linux命令详解-cd
Linux cd 命令可以说是Linux中最基本的命令语句,其他的命令语句要进行操作,都是建立在使用 cd 命令上的. 所以,学习Linux 常用命令,首先就要学好 cd 命令的使用方法技巧. ...
- WebService是什么?以及工作原理
WebService 就是一个应用程序,向外界暴露出公开的API使别人其能在WEB对其进行远程调用,具有跨平台和跨语言的等特点,采用Internet的Http协议进行客户端与服务器之间的交互 由XML ...
- 将本地代码提交到gitlub
第一步:建立git仓库 cd到本地项目根路径下面,执行git命令:git init $ git init Initialized empty Git repository in D:/my_wor ...
- Prism开发人员指南5-WPF开发 文档翻译(纯汉语版)
2014四月 Prism以示例和文档的形式帮助你更简单的设计丰富灵活易维护的WPF程序.其中使用的设计模式体现了一些重要的设计原则,例如分离关注点和松耦合,Prism帮助你利用松耦合组件设 ...
- linux下vim对于意外退出的文档的再次开启
转载的: 1.对于同一个文件如果上次已经打开,而未关闭的情况下,又打开该文件进行编辑时,会出现如下提醒: 这是由于已经打开但未闭关的文件,会在其目录下出现一个.swp的文件,由于是属于隐藏文件,可以用 ...
- 原创:Scala学习笔记(不断更新)
Scala是一种函数式语言和面向对象语言结合的新语言,本笔记中就零散记下学习scala的一些心得,主要侧重函数式编程方面. 1. 以递归为核心控制结构. 实现循环处理的方式有三种:goto,for/w ...
- Helix Server流媒体服务器架设教程(附Helix Server11.01下载)
现在D版的远古影视系统很流行,也很实用,但是在这之前,很多人都是用共享,或者是使用Helix Server留媒体来做电影服务器~ 虽然Helix Server流媒体服有点落伍了,不过我相信它还是有用武 ...
- 【占位】HihoCoder 1160 : 攻城略地(并查集好题)
攻城略地 时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 A.B两国间发生战争了,B国要在最短时间内对A国发动攻击.已知A国共有n个城市(城市编号1, 2, …, n),城 ...