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

5人阅读 评论(0) 收藏 举报
分类:

原题:1092. To Buy or Not to Buy (20)


解题思路:

建一个记录所要的所有字符出现次数的向量,再与给出的字符串进行比对即可。


代码如下:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
const int maxn = 256;
int h[maxn];

int main()
{
    string s1, s2;
    while(cin >> s1 >> s2)
    {
        fill(h, h+maxn, 0);
        for(int i = 0; i < s2.size(); i++)
            h[s2[i]]++;
        for(int i = 0; i < s1.size(); i++)
            if(h[s1[i]] > 0) h[s1[i]]--;
        int flag = 0; //在无法满足时,直接记录缺额
        for(int i = 0; i < maxn; i++)
            if(h[i] > 0) flag += h[i];

        if(!flag)
            printf("Yes %d\n", s1.size() - s2.size());
        else
            printf("No %d\n", flag);
    }
    return 0;
}

查看评论

PAT (Advanced Level) 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...
  • tuzigg123
  • tuzigg123
  • 2015-07-31 14:56:15
  • 468

PAT A 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...
  • xyzchenzd
  • xyzchenzd
  • 2015-03-17 14:48:24
  • 724

1039. 到底买不买(20) PAT 乙级&&1092. To Buy or Not to Buy (20)PAT甲级

问题描述 小红想买些珠子做一串自己喜欢的珠串。卖珠子的摊主有很多串五颜六色的珠串,但是不肯把任何一串拆散了卖。于是小红要你帮忙判断一下,某串珠子里是否包含了全部自己想要的珠子?如果是,那么告诉她有...
  • SY_Yu
  • SY_Yu
  • 2016-06-21 23:54:56
  • 275

【PAT】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...
  • realxuejin
  • realxuejin
  • 2015-10-11 21:03:58
  • 403

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

基础题,map
  • u011777915
  • u011777915
  • 2017-09-05 17:06:50
  • 69

PAT 1092. To Buy or Not to Buy (20)

#include #include #include #define SIZE 1005 using namespace std; char sell[SIZE], want[SIZE]; mapm;...
  • andyyang0212
  • andyyang0212
  • 2015-04-06 15:31:12
  • 213

pat 1092. To Buy or Not to Buy (20)

1092. To Buy or Not to Buy (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 1...
  • wyh7280
  • wyh7280
  • 2015-07-19 14:36:39
  • 349

PAT 1092. 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...
  • solin205
  • solin205
  • 2015-03-19 13:24:24
  • 346

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 sh...
  • Yangsongtao1991
  • Yangsongtao1991
  • 2015-03-16 11:22:38
  • 310

PAT (Top Level) Practise 1004 To Buy or Not to Buy - Hard Version (35)

1004. To Buy or Not to Buy - Hard Version (35) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B...
  • jtjy568805874
  • jtjy568805874
  • 2016-02-28 12:05:28
  • 763
    个人资料
    持之以恒
    等级:
    访问量: 3150
    积分: 1023
    排名: 5万+
    文章分类
    文章存档
    最新评论
  • PAT (Advanced) 10...

    cx86918626: [reply]M_Syple[/reply] 刚翻到一个帖子,最后一个样例好像是所有的硬币全加起来...

  • PAT (Advanced) 10...

    cx86918626: [reply]M_Syple[/reply]没找到,当时想了很多办法,但最后就是不行,我猜是其实给...

  • PAT (Advanced) 10...

    M_Syple: dfs我也是最后一个点过不了,但看运行时间最后一个点不是大数据检测啊,你最后找到dfs的毛病了么