I want to buy some red beads made a bunch of their favorite beads. There are many stall selling beads strings of colorful beads, but refused to sell any string split up. So red to help you determine what, a beaded yard contains all the beads you want? If so, tell her how much extra beads; if not, then tell her how much missing beads.
For your convenience, we use [0-9], [az], the characters within [AZ] to represent the range of colors. For example, in FIG. 1, the third string is wanted red beads; a first string may then buy, because it contains all the beads she wants, does not require more than the beads 8; the second string can not buy because there is no black beads, and a less red beads.
Input formats:
Each input comprises a test. Each test case separately in two lines has given beads and red beads wanted to stall, no more than 1000 two strings of beads.
Output formats:
If you can buy the output in a row Yes
and how much extra beads; if not buy, the output in a row No
as well as lack of the number of beads. Meanwhile separated by a space.
Sample Input 1:
ppRYYGrrYBR2258
YrR8RrY
Output Sample 1:
Yes 8
Sample Input 2:
ppRYYGrrYB225
YrR8RrY
Output Sample 2:
No 2
Thinking
- Use
map
containers to count the number of maps, each test has beads, if one can not find any to illustrate the lack of, or a reduction on the corresponding beads - A1092 ( https://pintia.cn/problem-sets/994805342720868352/problems/994805374509498368 ) is the English version of this title
Code
#include<bits/stdc++.h>
using namespace std;
int main()
{
map<char,int> mp;
string a;
string b;
getline(cin, a);
getline(cin, b);
for(int i=0;i<a.size();i++)
{
if(mp.count(a[i]) == 0)
{
mp[a[i]] = 1;
}else mp[a[i]] += 1;
}
bool can_make = true;
int need = 0;
for(int i=0;i<b.size();i++)
{
if(mp.count(b[i]) == 0 || mp[b[i]] == 0) //找不到指定颜色的珠子或者该珠子用完
{
can_make = false;
need++;
}else
{
mp[b[i]] -= 1;
}
}
if(can_make)
{
map<char,int>::iterator it;
int extra = 0;
for(it=mp.begin();it!=mp.end();it++)
extra += it->second;
cout << "Yes " << extra;
}else cout << "No " << need;
return 0;
}
Quote
https://pintia.cn/problem-sets/994805260223102976/problems/994805283241443328