题意:给出两个字符串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的更多相关文章

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

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

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

  4. PAT1092:To Buy or Not to Buy

    1092. To Buy or Not to Buy (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

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

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

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

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

  10. PAT (Advanced Level) 1092. To Buy or Not to Buy (20)

    简单题. #include<cstdio> #include<cstring> ; char s1[maxn],s2[maxn]; ]; ]; int main() { sca ...

随机推荐

  1. PinYin4JUtils

    import java.util.Arrays; import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pinyin ...

  2. 三十三 Python分布式爬虫打造搜索引擎Scrapy精讲—数据收集(Stats Collection)

    Scrapy提供了方便的收集数据的机制.数据以key/value方式存储,值大多是计数值. 该机制叫做数据收集器(Stats Collector),可以通过 Crawler API 的属性 stats ...

  3. 前端工程师(JavaScript)在业余时间如何提高自身能力

    1.前端工程师(JavaScript)在业余时间如何提高自身能力? https://www.zhihu.com/question/40186398?sort=created 2.前端开发工程师必读书籍 ...

  4. Node.js小白开路(一)-- console篇

    在所有内容的学习之中我们经常首先要接受到的常常很大一部分为命令行或是工具的内容展示,console内容为node.js在命令行中答应数据内容的一个途径. Console是nodejs中的元老级模块了. ...

  5. 条款21:必须返回对象的时候,不要妄想使其返回reference

    //先看看下面这个例子 class Rational{ public: Rational(int num, int denu) :numirator(num), denumirator(denu); ...

  6. Java基础学习-extends继承(成员变量,局部变量,成员方法)

    package extend; /*面向对象-继承: * 多个类的共同成员变量和成员方法.抽取到另一个类中(父类),我们多个类就可以访问到父类的成员了 * */ class Game{ String ...

  7. Python label for _ 用法

    Python label for _ 用法 Python label for _ 用法 >>> label_data = [iter([3,4]),iter([4,9]), iter ...

  8. vs无法调试 ,还没有为该文档加载任何符号

      如何:启用非托管代码调试 位于“项目设计器”的“调试”页上的“非托管代码调试”属性确定是否支持本机代码调试. 如果要调用 COM 对象,或启动调用您的项目的.以本机代码编写的自定义程序,并且需要调 ...

  9. libwebsockets 运行问题

    /****************************************************************************** * libwebsockets 运行问题 ...

  10. Ubuntu16.04配置apache+php+mysql

    命令行配置apache input sudo apt-get install apache2 done! 命令行配置mysql 参见: MySQL install and setting 命令行配置p ...