A1092
可输入内容为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的更多相关文章
- 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 ...
- 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 ...
- PAT B1039/A1092 到底买不买项链
小红买些珠子做项链,但是卖家不肯拆散了卖,于是帮忙判断一下,某串珠子是否全部包含自己想要的珠子,如果是告诉她有多少多余的珠子,如果不是,又缺了那些珠子现在为了方便起见用"0-9"& ...
- 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 ...
- PTA(Basic Level)1039.到底买不买
小红想买些珠子做一串自己喜欢的珠串.卖珠子的摊主有很多串五颜六色的珠串,但是不肯把任何一串拆散了卖.于是小红要你帮忙判断一下,某串珠子里是否包含了全部自己想要的珠子?如果是,那么告诉她有多少多余的珠子 ...
- 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甲级题解分类byZlc
专题一 字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...
随机推荐
- TcpListener、TcpClient
1.TcpClient using System; using System.Text; using System.Net.Sockets; namespace tcpclient { class t ...
- Mysql学习---基础操作学习
1.1. 基本操作 数据库引擎 Inodb:支持事务[原子性操作,完成一些列操作后才算完成操作,否则rollback] MyISAM: 支持全文索引,强调了快速读取操作,主要用于高负载的select ...
- Entity FrameWork Code First 配置关系
Has方法与With方法 A.HasRequired(a => a.B).WithOptional(b => b.A);上面一句配置意思就是A类包含B类一个不为null的实例,B类包含A类 ...
- ThinkPHP最新版本SQL注入漏洞
如下controller即可触发SQL注入: code 区域 public function test() { $uname = I('get.uname'); $u = M('user')-> ...
- HDU 5677 ztr loves substring(Manacher+dp+二进制分解)
题目链接:HDU 5677 ztr loves substring 题意:有n个字符串,任选k个回文子串,问其长度之和能否等于L. 题解:用manacher算法求出所有回文子串的长度,并记录各长度回文 ...
- What is Systems Architecture ?
What is Systems Architecture ? Systems Architecture is a generic discipline to handle objects (exi ...
- reactnative调研
/** * This function parses the exported methods inside RCTBridgeModules and * generates an array ...
- nrf52840蓝牙BLE5.0空中速率测试(nordic对nordic)
一.基础知识: [1]Data Length:物理层发送一包数据的最大值: [2]MTU: ATT层发送一次数据长度的最大值: [3]GAP Event Length:一个connection eve ...
- 使用Nginx 做负载均衡
Nginx可以作为一个非常高效的负载均衡系统,通过分发HTTP请求到多个应用服务器来提高整个系统的吞吐量,性能和可用性. 负载均衡的算法/机制 下面是Nginx支持的机制 轮询机制 轮询算法 最少连接 ...
- 集合HashMap和HashSet中迭代器的使用
package setTest; import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import ...