Number-guessing Game
Number-guessing Game
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 51 Accepted Submission(s) : 31
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.
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.
For each test case, output *A*B stands for how close the two numbers are.
#include <stdio.h>
#include <stdlib.h> int main()
{
int T,a[],b[],i,sign,j,signs;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&j,&i);
a[]=j/;
a[]=(j/)%;
a[]=(j%)/;
a[]=j%;
b[]=i/;
b[]=(i/)%;
b[]=(i%)/;
b[]=i%;
for(i=,sign=,signs=;i<;i++)
{
if(a[i]==b[i])
{
sign++;
}
else
{
for(j=;j<;j++)
if(b[i]==a[j])
{
signs++;
}
}
}
printf("%dA%dB\n",sign,signs);
}
return ;
}
Number-guessing Game的更多相关文章
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 第一章:Python基础の快速认识基本语法
本課主題 第一个 Hello World 程序实战 用户输入实战 模块介紹 变量介绍 格式化介紹 条件判断介紹和操作实战 for 循环介紹和操作实战 作业需求 Python 第一个 Hello Wor ...
- python猜数字游戏console版本
加入python学习小组后的第一次作业,python GUI写猜数字游戏.由于加班比较多,第一步先实现console版本,下一步再实现GUI版本. 虽然猜数字游戏是个小游戏,但是涉及到的基础知识点还是 ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- hdu 3354 Probability One
Probability One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- AST11103 Problem Solving
AST11103 Problem Solving with Programming SkillsAdditional Individual Assignment: Min-Game Programmi ...
- POJ 3994:Probability One
Probability One Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1674 Accepted: 1151 D ...
- 20 个使用原生 JavaScript 实现的 Web 项目
20 个使用原生 JavaScript 实现的 Web 项目 20 vanilla JavaScript Web Projects https://github.com/learning-js-by- ...
- csuoj 1353: Guessing the Number
这个题我想到要用kmp找到循环节: 但是后面的我就不会做了: 看到题解才知道是字符串的最小表示: #include<cstdio> #include<cstring> #inc ...
- [coj 1353 Guessing the Number]kmp,字符串最小表示法
题意:给一个字符串,求它的最小子串,使得原串是通过它重复得到的字符串的一个子串. 思路:先求最小长度,最小循环长度可以利用kmp的next数组快速得到,求出长度后然后利用字符串最小表示法求循环节的最小 ...
随机推荐
- loadrunner时间损耗-analysis中忽略
请问怎么在Analysis中过滤掉思考时间? 在Analysis上放"help"下有个漏斗状的图标,鼠标放上去后显示“Apply filter on sunmmary page”, ...
- 读书笔记之ado.net entity framework
提供了对数据访问的一种抽象层,是更加易于以编程的方式来操作及管理数据 有以下几种模式:Model First, Database First, and Code First 现在主要讨论code Fi ...
- JavaEE XML 基础知识
JavaEE XML 基础知识 @author ixenos 1. XML开头都需要一个声明 <?和?>表明这是一个处理指令 <?xml version=”1.0” encod ...
- hdu_5821_Ball(贪心)
题目链接:hdu_5821_Ball 题意: 给你序列A和序列B,依次给你m个区间,每次你可以交换区间内的任意数,问最后能不能将A变成B 题解: 比赛当时没想到,智商被压制 1001: 假设有4个红球 ...
- 3种日志类型,微信付款反馈-->写入txt日志
--> 接收 $GLOBALS["HTTP_RAW_POST_DATA"] ---->xml 反系列化$qr = XML_unserialize( $rowpost ...
- QQ互联功能
QQ作为现在使用人数最多的几个聊天软件之一,倘若能够方便的进行沟通(在大家的机器上都安装了QQ客户端或者浏览器的前提下),在商家推广的时候也许会带来不小的利益. http://wp.qq.com/in ...
- libmad编译
patch -Np1 -i ../libmad-0.15.1b-fixes-1.patch && sed "s@AM_CONFIG_HEADER@AC_CONFIG_HEAD ...
- bullet_01
#include <btBulletDynamicsCommon.h> #include <osgViewer/Viewer> #include <map> #in ...
- Sql Server 和 Access 数据库在书写sql语句时的语法差异
sql:datediff(d,eff_time,getdate()) access: datediff('d',eff_time,getdate())
- Yii2.0的安装与配置教程
版权声明:本文为博主原创文章,未经博主允许不得转载. PHP版本需求:PHP5.4.0以上,因为Yii2.0基于PHP5.4以上版本进行了完全重写. 目前有两种方法可以安装Yii2.0,一种是安装Co ...