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& ...
随机推荐
- 【Leetcode】【Medium】3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...
- 使用c++11写个最简跨平台线程池
为什么需要多线程? 最简单的多线程长啥样? 为什么需要线程池,有什么问题? 实现的主要原理是什么? 带着这几个问题,我们依次展开. 1.为什么需要多线程? 大部分程序毕竟都不是计算密集型的,简单的说, ...
- ZT 类与类之间的四种关系
csdn上一个好贴子:http://bbs.csdn.net/topics/390646332 类与类之间的四种关系1.依赖(Dependency) 类A在类B中作为一个成员函数的参数或者是返回值 ...
- UVa 247 - Calling Circles(Floyd求有向图的传递闭包)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 牛客网多校训练第一场 J - Different Integers(树状数组 + 问题转换)
链接: https://www.nowcoder.com/acm/contest/139/J 题意: 给出n个整数的序列a(1≤ai≤n)和q个询问(1≤n,q≤1e5),每个询问包含两个整数L和R( ...
- BZOJ 3399 [Usaco2009 Mar]Sand Castle城堡:贪心【最小匹配代价】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3399 题意: 给你一个数列a,和一个可变换顺序的序列b(数列长度≤25000). a增加一 ...
- 如何选择PHP项目的开发方案?
我说的项目开发方案并不是谈论到底用不用PHP去开发的问题,而是当你遇到一个项目,已经决定了用PHP,然后才来看的问题:用PHP的什么开发方案. 基本上有这么几种方案.各有各的说法,良莠不齐,我就谈谈我 ...
- Windows 使用iCloud日历
作者:Lumos Night链接:https://www.zhihu.com/question/34287617/answer/97299386来源:知乎著作权归作者所有.商业转载请联系作者获得授权, ...
- Redis(RedisTemplate)使用hash哈希
RedisTemplate配置:https://www.cnblogs.com/weibanggang/p/10188682.html package com.wbg.springRedis.test ...
- ucos问题
1. 在系统初始化之前,不要调用系统函数,如下: void OSRun(void) { SYSTICK_InternalInit(1); // 1ms time tick SYSTICK_IntCmd ...