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数组快速得到,求出长度后然后利用字符串最小表示法求循环节的最小 ...
随机推荐
- channel bonding
一.什么是bondingLinux bonding驱动提供了一个把多个网络接口设备捆绑为单个的网络接口设置来使用,用于网络负载均衡及网络冗余二.bonding应用方向1.网络负载均衡对于bonding ...
- Memcached内存存储
早就听说过Memcached独特的内存管理方式,写着篇文章的目的就是了解Memcached的内存管理,学习其源代码. 1.什么是Slab Allocator memcached默认情况下采用了名为Sl ...
- 《学习的艺术》 (The Art of Learning)——划小圈 (Making Smaller Circles)
“……我对象棋.武术以及范围更广的整个学习过程这三者的核心及相互关系的研究在一定程度上是受到了罗伯特.波席格<摩托车维护艺术>一书的启发.我决不会忘记指导我今后数年学习方式的那一幕.波席格 ...
- css3技巧属性之text-overflow
text-overflow:clip | ellipsis 默认值:clip 取值: clip: 当对象内文本溢出时不显示省略标记(...),而是将溢出的部分裁切掉. ellipsis: 当对象内文本 ...
- java学习初体验之课后习题
import java.util.Scanner; public class HelloWorld { public static void main(String[] args) { //打印Hel ...
- js--3目运算符
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- iOS开发关于xcode中souceControl的苹果文档翻译(节选)
Subversion 1.7 provides many benefits: svn1.7版本有以下好处: Improved performance. Increased speed for many ...
- 针对IE的CSS样式hack
针对IE的CSS样式hack,如下: 例子:background:#000: 1.只针对IE6的hack方式(_):_background:#000: 2.只针对IE7的hack方式(+):+back ...
- Dokan官方说明文档
Dokan 库Copyright(c) Hiroki Asakawa http://dokan-dev.net/en 什么是Dokan库================================ ...
- 四、WCF的配置文件
注:本文为学习摘抄,原文地址:http://www.cnblogs.com/iamlilinfeng/archive/2012/10/02/2710224.html 一.概述 配置也是WCF编程中的主 ...