首页 > 其他分享 >北大ACM poj3589 Number-guessing Game

北大ACM poj3589 Number-guessing Game

时间:2023-08-21 17:07:13浏览次数:45  
标签:digits guessing ++ poj3589 number value Number correct


Number-guessing Game


Time Limit: 1000MS

 

Memory Limit: 65536K

Total Submissions: 5805

 

Accepted: 4204


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>
main()
{
	int n,i,j,A,B;
	char a[5],b[5];
	scanf("%d",&n);
	while(n--)
	{
		i=A=B=0;
		scanf("%s%s",a,b);
		for(;a[i];i++)
		{
			j=0;
			for(;b[j];j++)
			{
				if(a[i]==b[j])
				{
					B++;
					if(i==j) A++;
				}
			}
		}
		printf("%dA%dB\n",A,B-A);
	}
}

 

标签:digits,guessing,++,poj3589,number,value,Number,correct
From: https://blog.51cto.com/u_10101161/7177236

相关文章

  • 杭电ACM HDU 3346 Lucky Number
    LuckyNumberTimeLimit:2000/1000MS(Java/Others)   MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):1523   AcceptedSubmission(s):800ProblemDescriptionToChinesepeople,8isaluckynumber.Nowyourtaskistojudgeifanu......
  • 【开源三方库】bignumber.js:一个大数数学库
    OpenHarmony(OpenAtom OpenHarmony简称“OpenHarmony”)三方库,是经过验证可在OpenHarmony系统上可重复使用的软件组件,可帮助开发者快速开发OpenHarmony应用。如果是发布到开源社区,称为开源三方库,开发者可以通过访问开源社区获取。接下来我们来了解bignumber.js开源三方库。bignum......
  • Google classic interview questions, throwing eggs the least number of times All
    Googleclassicinterviewquestions,throwingeggstheleastnumberoftimesAllInOne谷歌经典面试题,扔鸡蛋最少次数14✅你在一栋100层的大楼里工作,你得到2个相同的鸡蛋。你需要计算出鸡蛋可以掉落到最高的楼层而不破裂。问题是你需要投掷多少次。找到一种在......
  • Number of Beautiful Integers in the Range
    NumberofBeautifulIntegersintheRangeYouaregivenpositiveintegers low, high,and k.Anumberisbeautiful ifitmeetsbothofthefollowingconditions:Thecountofevendigitsinthenumberisequaltothecountofodddigits.Thenumberisdivi......
  • 西农OJ P1067 Humble Number
    1067:HumbleNumber题目描述如果一个数只有素数因子2,3,5,7,那么这个数被称为“HumbleNumber”。前20个“HumbleNumber”是:1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,25,27。经验证,2000000000以内的“HumbleNumber”共有5842个。你的任务是编写一个程序,根据要求输出序列中的某一个数。如22,......
  • CF1738C_EvenNumberAddicts
    CF1738CEvenNumberAddicts考虑综合只跟每个数的奇偶性有关,就先统计奇数个数及偶数个数。有DP和数学分类讨论两种方法。具体看题解吧:https://www.luogu.com.cn/problem/solution/CF1738C数学dp......
  • Oracle listagg() 和tow_number()
    listagg();多条数据合并某列数据listagg(role_name,'分割符')withingroup(orderby根据哪些字段排序) over(partitionby分组字段)row_number():根据某个字段分组并且取到每个类型时间最大的数据 a='1'意思是分组后取到第一条select*from(select......
  • 读取xls文件时报错 Initialisation of record 0x203(NumberRecord) left 4 bytes rema
    项目背景:公司的一个客户报告项目需要同步及抽取客户方的文件数据,文件类型为xls格式,文件为客户方的第三方厂商系统批量生成,工具及方法不明问题:读取该类xls文件后,无法成功创建Workbook,报错提示“Initialisationofrecord0x203(NumberRecord)left4bytesremainingstilltob......
  • IfcDayInMonthNumber
    IfcDayInMonthNumber类型定义IfcDayInMonthNumber是一个整数,用于定义指定日期在一个月中的位置。 类型:整数 IFC1.5.1中的新型。IFC4添加规则ValidRange的位置 FormalPropositionsRuleDescriptionValidRangeThevalidrangeforpositioningadayinamonth......
  • row_number()和rownum排序的区别
    在Oracle中使用ROW_NUMBER()和ROWNUM进行排序时,它们的性能可能会有一些差异。以下是它们之间的一些对比:ROW_NUMBER()排序:ROW_NUMBER()是一种窗口函数,可以为结果集中的每一行分配一个唯一的行号,并且可以根据指定的排序字段进行排序。ROW_NUMBER()函数通常在内部执行排序操作,然后为......