a075: Bulls and Cows 猜數字遊戲
標籤 :
通過比率 : 100% (3 人 / 3 人 ) (非即時)
評分方式 :
Tolerant

最近更新 : 2020-04-16 12:01

內容

As a child, I liked to play a game of guessing numbers, also known as Cows and Bulls. In the beginning, one party chose four different digits, such as (1, 2, 3, 5), as the secret number. Then the other tries to guess the secret number, for example, supposing the guessed number as (4, 3, 8, 5). The first one responds with “1A1B”, which indicates that one matching digit is in its right position, it is an A (the digit 5), and one matching digit is in its different position, it is a B (the digit 3). This try and response continue until the secret number is revealed. Please write a program to simulate this guessing process, and the default secret number is defined as (4, 8, 0, 1).

 

小時候常玩一種猜數字的遊戲,開始時由一方選擇四個相異的數字,例如 (1, 2, 3, 5) 。接著由另外一方猜測,例如猜數字 (4, 3, 8, 5) ,對方則回應 1A 1B ,表示一個數字猜對且位置正確(一個A,即數字 5 ),另一數字猜對但位置不對(一個B,即數字 3 )。請寫一個程式,模擬猜數字的進行。程式中內定這組數字 (4, 8, 0, 1) 供電腦玩家猜測。

輸入說明

Every input line contains four guessed numbers separated by spaces. If all four numbers are 0’s, the program ends.

每行輸入 4 個猜測的數字,以單一空格分隔且數字範圍為 0 至 9 的整數。如果 4 個數字全部輸入 0 則結束程式執行。

輸出說明

Output the guess response for each input line expressed as “xAyB”, where x and y are integers from 0 to 4.

輸出每一個輸入行的猜測結果,以 xAyB 的形式表示, x與y 為 0 至 4 的整數。

範例輸入
1 2 3 4
5 6 7 9
0 0 0 0
範例輸出
0A2B
0A0B
測資資訊 :
記憶體限制 : 64 MB
隱藏 測資點#0 (100%): 1.0s , <1K
提示 :
標籤:
出處:
ITSA 迴圈 流程控制 [編輯 :
shengZJ (shengZJ)
]


編號 身分 題目 主題 人氣 發表日期
沒有發現任何「解題報告」