Number Guessing

时间限制(普通/Java):3000MS/10000MS          运行内存限制:65536KByte
总提交:38            测试通过:16

描述

Number Guessing is a computer game. First, the computer chooses four different digits, you need to guess these four digits in the fewest times,for each guess, the computer will show a judgement in the form of "#A#B", "#" is a number 0~4. "#A" shows how many digits you guessed with both correct value and position. "#B" shows how many digits you guessed with correct value. For example, the computer chose 1234, and you guessed 6139, the computer will show "1A2B" for you have number "1" correct value but wrong position and number "3" correct value with correct position.Thus the computer gives you the judgement of "1A2B". Now you have memorized the digits you guessed and the judgements you got, you feel like you can figure out the correct answer. Life is filled with wisdom, isn't it?

输入

There are several test cases. For each test case, the first line contains a single positive integer N indicates the times you can guess,the following N lines is the record of the guess, in the form:

#### #A#B

The first four numbers is the numbers guessed,then the judgements for your guess.The input is terminated by a negative integer.

输出

For each test case, output a single line contains exactly four digits that the computer has chosen. You may assume that each test case gives you enough information, so you can figure out the unique correct answer.

样例输入

2
1234 2A4B
1243 0A4B
3
0732 3A3B
1526 0A0B
4567 0A2B
-1

样例输出

2134
0734
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
#include<cstdlib>#define NUMBER_MAX_LENGTH 4
#define RESULT_MAX_LENGTH 4
#define CASE_MAX_NUMBER 1000class Case{
public:void set(void){ scanf("%s%s", number, result); }bool isFitThisNumber(const char* n);
private:char number[NUMBER_MAX_LENGTH + 1];char result[RESULT_MAX_LENGTH + 1];
};bool Case::isFitThisNumber(const char* bit){char posRight = '0';char posValueRight = '0';for (size_t ix = 0; ix != NUMBER_MAX_LENGTH; ++ix){if (number[ix] == bit[ix]){ ++posValueRight; }}for (size_t i = 0; i != NUMBER_MAX_LENGTH; ++i){for (size_t j = 0; j != NUMBER_MAX_LENGTH; ++j){if (number[i] == bit[j]){++posRight;break;}}}return posRight == result[2] && posValueRight == result[0];
}Case numberCase[CASE_MAX_NUMBER];
int caseSize;bool isFitAllCase(const int n){char bit[NUMBER_MAX_LENGTH] = { n / 1000 + '0', n / 100 % 10 + '0', n / 10 % 10 + '0', n % 10 + '0' };if (n / 1000 > 0 && (bit[0] == bit[1] || bit[0] == bit[2] || bit[0] == bit[3] || bit[1] == bit[2] || bit[1] == bit[3] || bit[2] == bit[3])){return false;}else if (n / 100 > 0 && bit[1] == bit[2] || bit[1] == bit[3] || bit[2] == bit[3]){return false;}else if (n / 10 > 0 && bit[2] == bit[3]){return false;}else{for (size_t ix = 0; ix != caseSize; ++ix){if (!numberCase[ix].isFitThisNumber(bit)){ return false; }}return true;}
}void setCase(void){for (size_t ix = 0; ix != caseSize; ++ix){numberCase[ix].set();}
}int main(void){while (cin >> caseSize, caseSize >= 0){setCase();for (int i = 0; i != 10000; ++i){if (isFitAllCase(i)){printf("%04d\n", i);break;}}}return EXIT_SUCCESS;
}

Number Guessing相关推荐

  1. python猜数游戏流程_python简单猜数游戏实例

    本文实例讲述了python简单猜数游戏.分享给大家供大家参考.具体实现方法如下: #!/usr/bin/env python import random number = random.randint ...

  2. Python案例:猜数游戏

    Python案例:猜数游戏 一.猜数游戏概述 Every programmer has a story about how they learned to write their first prog ...

  3. ssm练手小项目_20 个 JavaScript+Html+CSS 练手的小项目

    前言: 最近在 GitHub 上发现了一个 vanillawebprojects[1] 开源仓库,里面收集了 20 个 JavaScript+Html+CSS的练手项目,没有使用任何框架,可以让你从基 ...

  4. 杭电oj题目题型分类(转)

    1001 整数求和 水题 1002 C语言实验题--两个数比较 水题 1003 1.2.3.4.5... 简单题 1004 渊子赛马 排序+贪心的方法归并 1005 Hero In Maze 广度搜索 ...

  5. HDOJ题目分类大全

    版权声明:本文为博主原创文章,欢迎转载,转载请注明本文链接! https://blog.csdn.net/qq_38238041/article/details/78178043 杭电里面有很多题目, ...

  6. HDU题目分类大全【大集合】

    基础题: 1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.  1032.1037.1040.1048.1056.105 ...

  7. python如何询问用户是否继续游戏_Python猜猜游戏如何再现

    我想指出你的代码有一些问题. 最主要的一点是,当你输入yes时,游戏不会再次运行.它所要做的就是运行main(),它将打印your game,然后询问您是否要重试一次.如果你把你的游戏放在一个定义里, ...

  8. 学习python最好的书籍_最好的Python书籍

    学习python最好的书籍 Python is an amazing programming language. It can be applied to almost any programming ...

  9. 杭电OJ题目分类(转载)

    1001 整数求和 水题 1002 C语言实验题--两个数比较 水题 1003 1.2.3.4.5... 简单题 1004 渊子赛马 排序+贪心的方法归并 1005 Hero In Maze 广度搜索 ...

最新文章

  1. 河南大学明德计划2020计算机学院,河南大学启动“明德计划”
  2. Ajax Control Toolkit 34个服务器端控件 详解
  3. ListView嵌套RecyclerView遇到的一些坑以及解决办法
  4. 另一个程序正在使用此文件 进程无法访问 iis
  5. python安卓版turtle模块下载_python之turtle的模块
  6. 【信息抽取】NLP中关系抽取的概念,发展及其展望
  7. IOS笔记-计算机中的进制 反码补码 和存储细节
  8. nexus 安装_Jenkins Pipelines将制品发布到Nexus存储库
  9. boost::phoenix::if_相关的测试程序
  10. OCM备考 三. Managing Database Availability 之RMAN高级操作
  11. 开始使用Lumen吧,3分钟搞定登陆认证
  12. Less的条件表达式Guards
  13. 树莓派4bwlan驱动_树莓派4到手,你了解它所使用的新版Debian系统吗?
  14. 关于wordpress站点地图代码调试
  15. cesium 隐藏entity_cesium中随entity动态变化的弹出框
  16. android studio jdy08,JDY-08模块 蓝牙4.0 BLE CC2541 airsync iBeacon 兼容arduino
  17. vdbench - 性能压力测试工具
  18. ie11浏览器For win7 x64 官方下载 V9600 官方版
  19. VMware14虚拟机安装苹果系统
  20. 烽火戏诸侯用460万字写出最好的小说江湖,《雪中悍刀行》你服吗

热门文章

  1. git-cz 一款git commit 统一规范的工具
  2. 使用h5的方式来实现钟表
  3. Java写计算器自闭了
  4. 解决warning: LF will be replaced by CRLF in方法
  5. OpenCV + ORC 实现身份证识别
  6. 打开Shapefile文件的正确方式
  7. 2022年全球打鼾解决方案行业分析报告
  8. 绑定机制(转自天运科技)
  9. Spark的任务调度
  10. Robot fish: bio-inspired fishlike underwater robots 阅读笔记 1