PAT (Basic level) practise:1039. Whether to buy or not to buy

Source: Internet
Author: User

"Topic link"

Little Red want to buy some beads to make a string of their favorite beads. The owner of the bead sells a lot of colorful beads, but refuses to sell any strings. So little Red want you to help judge, whether a bead contains all the beads they want? If so, tell her how many extra beads there are, and if not, tell her how many beads are missing.

For convenience, we use characters in [0-9], [A-z], [A-z] range to represent colors. For example, in Figure 1, the 3rd string is the bead string that little red wants to do, so the 1th string can be bought, because it contains all the beads she wants, and 8 more unwanted beads; The 2nd string cannot be bought because there is no black beads and a red bead is missing.


Figure 1

Input format:

Each input consists of 1 test cases. Each test case is given in 2 rows of the owner's bead string and Little red want to do the bead string, two strings are not more than 1000 beads.

Output format:

If you can buy, output "Yes" in one line and how many extra beads are available, and if not, output "no" in a row and how many beads are missing. Separated by 1 spaces in between.

Input Sample 1:

Ppryygrrybr2258yrr8rry

Output Example 1:

Yes 8

Input Sample 2:

Ppryygrryb225yrr8rry

Output Example 2:

No 2

Submit Code:

1#include <stdio.h>2#include <string.h>3 4 voidGetbucket (Char*STR,int*ducket)5 {6     intLen =0;7      while(Str[len]! =' /')8     {9ducket[(int) str[len]]++;Tenlen++; One     } A } -  - voidTestvoid) the { - #defineMax_str_len (1000) -     intducket1[ -]; -     intducket2[ -]; +     intI, D1, D2; -     Charstr1[max_str_len+1]; +     Charstr2[max_str_len+1]; A  atmemset (STR1,0x00,sizeof(STR1)); -memset (STR2,0x00,sizeof(STR2)); -memset (Ducket1,0x00,sizeof(Ducket1)); -memset (Ducket2,0x00,sizeof(Ducket2)); -  -scanf"%s", str1); inscanf"%s", str2); -  to Getbucket (str1, ducket1); + Getbucket (str2, Ducket2); -  theD1 = D2 =0; *      for(i =0; I < -; i++) $     {Panax Notoginseng         if(Ducket1[i]-ducket2[i] <0) -         { theD1 + = (Ducket2[i]-ducket1[i]); +         } A         Else the         { +D2 + = (Ducket1[i]-Ducket2[i]);  -         } $     } $  -     if(D1! =0) -     { theprintf"No%d", D1); -     }Wuyi     Else the     { -printf"Yes%d", D2); Wu     } - } About  $ intMainvoid) - { - test (); -     return 0; A}

PAT (Basic level) practise:1039. Whether to buy or not to buy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.