可输入内容为0-9,a-z,A-Z。

输入:

第一行输入任意字符串;

第二行输入期望字符串。

输出:

如果第一行包含了所有期望字符串,输出yes和多余字符个数;

如果第一行不能完全包含期望字符串,输出缺失的字符个数。

思路:

记录第一行字符串每种字符个数,用HashTable数组记录;

遍历第二行字符串,遍历一个就在HashTable里对应的元素-1,如果HashTable<0,miss++;

miss>0,则输出no,反之则输出yes。

 #include<cstdio>
#include<cstring>
const int maxn=;
//第一个字符串中每种字符个数,miss为缺少的字符个数
int hashTable[]={},miss=;
//输入的字母和数字转化为HashTable的下标
int change(char c){
if(c>=''&&c<='') return c-'';
if(c>='a'&&c<='z') return c-'a'+;
if(c>='A'&&c<='Z') return c-'A'+;
} int main(){
char wh[maxn],tar[maxn];
scanf("%s",wh);
scanf("%s",tar);
int len1=strlen(wh);
int len2=strlen(tar);
for(int i=;i<len1;i++){//第一串中的每种字符串个数
int id=change(wh[i]);
hashTable[id]++;
}
for(int i=;i<len2;i++){
int id=change(tar[i]);
hashTable[id]--;
if(hashTable[id]<) miss++;
}
if(miss>) printf("No %d\n", miss);
else printf("Yes %d\n", len1-len2);
return ;
}

A1092的更多相关文章

  1. A1092. To Buy or Not to Buy

    Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy ...

  2. PAT甲级——A1092 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 ...

  3. PAT B1039/A1092 到底买不买项链

    小红买些珠子做项链,但是卖家不肯拆散了卖,于是帮忙判断一下,某串珠子是否全部包含自己想要的珠子,如果是告诉她有多少多余的珠子,如果不是,又缺了那些珠子现在为了方便起见用"0-9"& ...

  4. 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 ...

  5. PTA(Basic Level)1039.到底买不买

    小红想买些珠子做一串自己喜欢的珠串.卖珠子的摊主有很多串五颜六色的珠串,但是不肯把任何一串拆散了卖.于是小红要你帮忙判断一下,某串珠子里是否包含了全部自己想要的珠子?如果是,那么告诉她有多少多余的珠子 ...

  6. 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 ...

  7. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

随机推荐

  1. 【Leetcode】【Medium】Reorder List

    Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do thi ...

  2. 最小生成树-Prim算法与Kruskal算法

    一.最小生成树(MST) ①.生成树的代价:设G=(V,E)是一个无向连通网,生成树上各边的权值之和称为该生成树的代价. ②.最小生成树:在图G所有生成树中,代价最小的生成树称为最小生成树. 最小生成 ...

  3. nginx导致的session丢失的解决方法

    nginx把同一用户的请求分发到了不同的服务器,如果不做处理,就会导致session丢失. 1.粘性IP: 在nginx配置文件中,增加配置, 对IP进行HASH后,散列到服务器. 这个实现最简单.但 ...

  4. C/C++ 标准

    正式标准是需要付费的,不过可以在http://open-std.org/上找到标准的草案(和实际标准相差不大但是可以免费获取) 下面列出一下可能会用到的标准草案:C99:http://open-std ...

  5. x:Name与Name区别

    x:Name与Name有两个不同点: 1.x:Name是Xaml的标记特性,任何在Xaml中定义的元素,都可以使用x:Name来为元素指定名称. Name是FrameworkElement定义的依赖项 ...

  6. JAVA中commons-collections-3.2.1.jar包是干什么用的?

    类似C++中的Boost库,对Java容器类型和算法的补充

  7. Github注册

    官网:https://github.com/ sign in : 登录. sign up: 注册. 注意邮箱不可以随便乱填,邮箱用于激活账号和找回密码. 由于github的服务器在国外,访问比较慢,需 ...

  8. 模式:模版、样式;属于分类、识别的范围;分类、归类的标准-How are patterns obtained?

    模式及套路 模式:模版.样式:属于分类.识别的范围. How are patterns obtained? Through : re-use, classification and finally a ...

  9. thinkphp清除缓存

    前台 //清除缓存 $(function(){ $("#cache").click(function(){ layer.confirm('你确定要清除缓存吗?', {icon: 3 ...

  10. dropout总结

    1.伯努利分布:伯努利分布亦称“零一分布”.“两点分布”.称随机变量X有伯努利分布, 参数为p(0<p<1),如果它分别以概率p和1-p取1和0为值.EX= p,DX=p(1-p). 2. ...