HNU Number Guessing

描述

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 correct answer.

样例输入

21234 2A4B1243 0A4B30732 3A3B1526 0A0B4567 0A2B-1

样例输出

21340734

#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cmath>
#define N 19
using namespace std;

int s[N],aa[N],bb[N],a[N];
int n;

int check(int ans)
{

    for(int k=0;k<n;k++){

    int cnt=3;

    int ss[4];
    int x=ans;

    for(int i=0;i<4;i++)
    {
        ss[cnt]=x%10;
        x/=10;
        cnt--;
    }

    if(ss[0]==ss[1] || ss[0]==ss[2] || ss[0]==ss[3] || ss[1]==ss[2] || ss[1]==ss[3] || ss[2]==ss[3])
    return 0;

    int tt[4];

    cnt=3;
    x=a[k];
    for(int i=0;i<4;i++)
    {
        tt[cnt--]=x%10;
        x/=10;
    }

    int num=0;
    for(int i=0;i<4;i++)
    {
        if(tt[i]==ss[i])
        {
            num++;
        }
    }
    if(num!=aa[k]) return 0;

    num=0;
    for(int i=0;i<4;i++)
    {
        for(int j=0;j<4;j++)
        {
            if(tt[i]==ss[j])
            {
                num++;
                ss[j]=-1;
            }
        }

    }
    if(num!=bb[k]) return 0;

    }

    return 1;

}

int main()
{
    while(~scanf("%d",&n))
    {
        if(n<0) break;

        char x,y;
       for(int i=0;i<n;i++)
       {
           scanf("%d",&a[i]);
           scanf("%d%c%d%c",&aa[i],&x,&bb[i],&y);
       }
       int ans=0;
       for(int i=0;i<9999;i++)
       {
           if(check(i))
           {
               ans=i;
                break;
           }

       }

       printf("%04d\n",ans);

    }
    return 0;
}
时间: 2024-10-13 10:21:05

HNU Number Guessing的相关文章

nefu 640 Number Guessing

题目:大意就是猜数,给定个四位数,然后给出这个数与正确的数之间的比较(#A*B,#代表有#个数字他的值和位置都对了,*代表有*个数的值对了),给出n个上述的4位数,让你确定这个正确的数是多少. 思路:直接暴力. 注意:程序结束是n为负数,而不是-1,为此超时了两次 T T. 代码: #include <iostream> #include <cstdio> #include <cstring> using namespace std; struct node { cha

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

hausaufgabe--python 35 - easygui

00-- make use of easygui to recode the game of number guessing:

POJ3994 HDU3354 UVALive4736 Probability One【水题】

Probability One Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1944 Accepted: 1335 Description Number guessing is a popular game between elementary-school kids. Teachers encourage pupils to play the game as it enhances their arithmetic sk

AST11103 Problem Solving

AST11103 Problem Solving with Programming SkillsAdditional Individual Assignment: Min-Game Programming (40%)Learning Outcomes1. Use common application software and program development tools;2. Analyze simple problems with basic problem solving skills

[coj 1353 Guessing the Number]kmp,字符串最小表示法

题意:给一个字符串,求它的最小子串,使得原串是通过它重复得到的字符串的一个子串. 思路:先求最小长度,最小循环长度可以利用kmp的next数组快速得到,求出长度后然后利用字符串最小表示法求循环节的最小表示即可. #pragma comment(linker, "/STACK:10240000") #include <map> #include <set> #include <cmath> #include <ctime> #include

BZOJ 4430 Guessing Camels

Description Jaap, Jan, and Thijs are on a trip to the desert after having attended the ACM ICPC World Finals 2015 in Morocco. The trip included a camel ride, and after returning from the ride, their guide invited them to a big camel race in the eveni