Guess number Game

Source: Internet
Author: User

You is playing the following Bulls and cows game with your friend:you write down a number and ask your friend to guess W Hat the number is. Each time your friend makes a guess, you provide a hint the indicates how many digits in said guess match your secret num ber exactly in both digit and position (called "bulls") and how many digits match the secret number but locate in the Wron G position (called "cows"). Your Friend would use successive guesses and hints to eventually derive the secret number.

For example:

Secret Number: "  1807" Friend's guess: "7810"

Hint: 1 Bull and 3 cows. ( 8 the bull is, the cows 0 is, and 1 7 .)

Write a function to return a hint according to the secret number and friend's guess, use to A indicate the Bulls and c1/> to indicate the cows. In the above example, your function should return "1A3B" .

Please note that both secret number and friend's guess may contain duplicate digits, for example:

Secret number: "  1123" Friend's guess: "0111"

In this case, the 1st 1 in friend's guess is a bull, the 2nd or 3rd 1 is a cow, and your function should return .

Assume that the secret number and your friend's guess only contain digits, and their lengths is always equal.

Guess number Game

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.