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 you want to help judge a little red
, the house contains a beaded beads all they 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, YrR8RrY want a little red beads; ppRYYGrrYBR2258 can buy it, because it contains
all the beads she wants, does not need more than the 8 beads; ppRYYGrrYB225 can not buy, because there is no black beads, and a less pieces of red beads.
Enter a description:
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 Description:
If you can buy, the output is "Yes" and how many extra beads in a row; if not buy, the output in a row "No" and the number of missing beads. Meanwhile separated by a space.
Input example:
ppRYYGrrYBR2258
YrR8RrY
Output example:
Yes 8
idea: to process the string. string.erase () code is as follows:
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <vector> #include <queue> #include <cmath> using namespace std; int main() { string a; string b; cin>>a>>b; bool flag=true; int len1=a.length(); int len2=b.length(); int count=0; for(int i=0;i<len2;i++) { int temp=a.find(b[i],0);//不断更新下标,当找不到时,计数 if(temp!=-1) { a.erase(a.begin()+temp); } else { flag=false; count++; } } if(flag) { printf ( "Yes% d \ n ", len1-len2); // time to buy, can be calculated by comparing the length of the string number string plurality } the else the printf ( "% D No \ n-", COUNT); return 0; }