poj3589

 

Number-guessing Game
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 5077 Accepted: 3700

Description

Larry likes playing the number-guessing game.

Two players are needed in a game. Suppose they are X and Y, and X presents a number for Y to guess. Firstly, X chooses a number with four different digits, keeping it in mind, and tells Y to start guessing. Every time Y has guessed, X should give out *A*B to show Y how close to the number his answer is. Here the symbol * stands for a number, and the number before A is the number of digits in Y's answer with both correct value and position. The number before B is the number of digits in Y's answer with correct value but incorrect position.

For example, if X chooses the number 5204, and Y guesses 4902, then X should give out 1A2B, in which 1A corresponds for digit 0 with both correct value and position and 2B corresponds for digit 2 and 4 with correct value but incorrect position. Then Y will go on guessing according to 1A2B that X presents him until he gets the totally correct number 5204 (when X shows him 4A0B).

Now you are given two numbers, and what you need to do is just testing how close they are.

Input

The first line of the input is an integer T which indicates the number of test cases. For each test case, input two numbers. Each number contains four different digits.

Output

For each test case, output *A*B stands for how close the two numbers are.
 

Sample Input

2
5204 4902
0123 3210

Sample Output

1A2B
0A4B

 

#include<stdio.h>
int main()
{
 int t,i,j,a,b;
 char ch1[4],ch2[4];
 scanf("%d",&t);
 while(t--)
 {
  a=0;b=0;
  getchar();
  for(i=0;i<4;i++)
   scanf("%c",&ch1[i]);
  getchar();
  for(i=0;i<4;i++)
   scanf("%c",&ch2[i]);
  for(i=0;i<4;i++)
   if(ch1[i]==ch2[i])
    a++;
   for(i=0;i<4;i++)
    for(j=0;j<4;j++)
     if(ch1[i]==ch2[j]&&i!=j)
      b++;
     printf("%dA%dB\n",a,b);
 }
  return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值