题意:给出两个字符串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. PHP的可变变量名

    有时候可变的变量名会给编程带来很大的方便.也就是说变量名可以被动态的命名和使用.通常变量通过下面这样的语句来命名 : 1 2 3 <!--?php $a = 'hello'; ?--> 可 ...

  2. 使用springmvc的时候报错NoSuchBeanDefinitionException: No qualifying bean of type

    NoSuchBeanDefinitionException: No qualifying bean of type 其实我至今都不知道错误的根源在哪里,<context:component-sc ...

  3. 《JavaScript高级程序设计》第7章 函数表达式

    定义函数的方式有两种:函数声明和函数表达式 // 函数声明 function function_name(argument) { // body... } // 函数表达式 var function_ ...

  4. 深入理解Lambda

    概述 Lambda是一个表达式,也可以说它是一个匿名函数.然而在使用它或是阅读Lambda代码的时候,却显得并不那么容易.因为它匿名,因为它删减了一些必要的说明信息(比如方法名).下面就来说说Lamb ...

  5. C++中GB2312字符串和UTF-8之间的转换

    在编程过程中需要对字符串进行不同的转换,特别是Gb2312和Utf-8直接的转换.在几个开源的魔兽私服中,很多都是老外开发的,而暴雪为了能 够兼容世界上的各个字符集也使用了UTF-8.在中国使用VS( ...

  6. 011——VUE中使用object与array控制class

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. mcake活动维护常见问题记录【pc端】 ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★

    ★ ★ ★ ★ ★ ★ ★ ★ ★ ★pc端问题及解决方法 ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ 问题一.pc.弹窗,背景兼容ie8的写法 ;;; -moz-opacity:.7;f ...

  8. C# 中字段和属性的使用时机

    在C#中,我们可以非常自由的.毫无限制的访问公有字段,但在一些场合中,我们可能希望限制只能给字段赋于某个范围的值.或是要求字段只能读或只能写,或是在改变字段时能改变对象的其他一些状态,这些单靠字段是无 ...

  9. linux下json库的编译及例程

    .下载JsonCpp http://sourceforge.net/projects/jsoncpp/files/ .下载scons http://sourceforge.net/projects/s ...

  10. 手贱使用shift+delete删除文件之后

    昨天整理文件夹,重新整理和命名所有项目文件,几个很久的项目代码使用shift+delete删除了. 今天早上过来说是要发版本,然后发现居然有个工程是在昨天删除的文件夹里,额,~ 然后各种百度,各种go ...