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数组快速得到,求出长度后然后利用字符串最小表示法求循环节的最小 ...
随机推荐
- redis10--主从模式
redis的主从模式(1)介绍redis存储数据是在内存中运行的,运行速度比关系型数据库要快一些.而且它具有SortSet/Hash等具有特色的数据类型,这是其它数据库无法比拟的.redis有增删改查 ...
- ASCII码对应表chr(num)
chr(9) tab空格 chr(10) 换行 chr(13) 回车 Chr(13)&chr(10) 回车换行 chr(32) 空格符 ...
- USACO 2.3 Cow Pedigrees
Cow Pedigrees Silviu Ganceanu -- 2003 Farmer John is considering purchasing a new herd of cows. In t ...
- POJ 2231 Moo Volume
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Description Farmer Jo ...
- swift 2中关键字和解释整理
1.swift 最新关键字和符号参考:https://developer.apple.com/library/mac/documentation/Swift/Conceptual/Swift_Prog ...
- Ubuntu彻底删除mysql
删除 mysql sudo apt-get autoremove --purge mysql-server-5.0sudo apt-get remove mysql-serversudo apt-ge ...
- hdu 2993 MAX Average Problem(斜率DP入门题)
题目链接:hdu 2993 MAX Average Problem 题意: 给一个长度为 n 的序列,找出长度 >= k 的平均值最大的连续子序列. 题解: 这题是论文的原题,请参照2004集训 ...
- ActiveMQ in Action(4) - Security
关键字: activemq 2.4 Security ActiveMQ支持可插拔的安全机制,用以在不同的provider之间切换.2.4.1 Simple Authentication Plug ...
- WTL版本ACEdit控件,改写自MFC版,附带源码
自动完成是个很酷也很实用的功能,比如在浏览器地址栏输入几个字母,相关的记录就会在下拉框中陈列出来. 最近在做公司产品UI部分的改善,原版本是MFC做的,我决定用WTL,于是就遇到自动完成控件的问题.遍 ...
- markdown 自己搞一个浏览工具
注意!`下不能有空行 `上也不能有空行 问题未解决 <!DOCTYPE html> <html lang="en"> <head> <me ...