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 ...
随机推荐
- Origin软件作图留白过多问题解决
解决空白过大方法:1.Tools——>Options2.Page——>Copy page setting——>Margin默认是Page,下拉菜单选Border,Clip Borde ...
- Java 注解指导手册 – 终极向导
原文链接 原文作者:Dani Buiza 译者:Toien Liu 校对:深海 编者的话:注解是java的一个主要特性且每个java开发者都应该知道如何使用它. 我们已经在Java Code Gee ...
- Shell 自定义函数
语法: function fname() { 程序段} 例子: #!/bin/bash ## 定义函数,分子除以分母,算利润.占有率等## 参数1:分子## 参数2:分母 function divfu ...
- linux下{}的用法
在touch {a,b}.txt时,同时创建了a.txt,b.txt两个文件 而touch {1..10}.txt,同时创建了10个txt文件,从1.txt到10.txt 在linux通配符中,{n, ...
- 蓝盾第三代AI防火墙分析
蓝盾第三代AI防火墙是国内首个“AI-Enabled”的防火墙.有别于市场上第一代特征识别.第二代应用识别防火墙.传统安全网关,需要依赖于签名和特征库技术对威胁进行检查,效率较低且存在大量误报漏报,特 ...
- Java堆、栈和常量池以及相关String的详细讲解(转)
一:在JAVA中,有六个不同的地方可以存储数据: 1. 寄存器(register). 这是最快的存储区,因为它位于不同于其他存储区的地方——处理器内部.但是寄存器的数量极其有限,所以寄存器由编译器根据 ...
- 2017.2.9日总结--外网IP和内网IP
Linux自己不能通过自己的外网访问自己必须通过内网访问自己
- python基础之函数名称空间与作用域
- ng $scope与$rootScope的关系
$scope与$rootScope的关系:①不同的控制器之间 是无法直接共享数据②$scope是$rootScope的子作用域对象$scope的id是随着控制器的加载顺序依次递增,$rootScope ...
- 如何突破JAVA程序员三年的门槛
第一阶段:三年 我认为三年对于程序员来说是第一个门槛,这个阶段将会淘汰掉一批不适合写代码的人.这一阶段,我们走出校园,迈入社会,成为一名程序员,正式从书本 上的内容迈向真正的企业级开发.我们知道如何团 ...