NEFU 640 猜数

http://acm.nefu.edu.cn/JudgeOnline/problemshow.php?problem_id=640

description

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?
							

input

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 terminated when N is not postive integer, and not need to proceed.

output

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.

sample_input

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

sample_output

2134
0734
我好像找到一点小规律,一般给你一些条件,让你猜测的题目思路基本上都会死暴力然后和条件匹配,全匹配的话就OK了。

这道题还有对整数取第几位上的数的技巧,算是复习一下吧。

代码如下:(可惜比赛的时候没做出来)

#include <stdio.h>
#include <string.h>
using namespace std;
char c[10005][5],b[10005][5];
int a[10];
int hash[15];
int main()
{
    int n,cnt;
    while(~scanf("%d",&n))
    {
        if(n<=0)
            break;
        for(int i=0;i<n;i++)
            scanf("%s%s",c[i],b[i]);
        for(int i=0;i<=9876;i++)
        {
            a[3]=i%10;
            a[2]=(i/10)%10;
            a[1]=(i/100)%10;
            a[0]=(i/1000)%10;
            if(a[0]==a[1]||a[0]==a[2]||a[0]==a[3]||a[1]==a[2]||a[1]==a[3]||a[3]==a[2])
                continue;
            cnt=0;
            for(int j=0;j<n;j++)
            {
                int x=0,y=0;
               memset(hash,0,sizeof(hash));
               hash[c[j][0]-'0']=hash[c[j][1]-'0']=hash[c[j][2]-'0']=hash[c[j][3]-'0']=1;
               for(int jj=0;jj<4;jj++)
               {
                   if(c[j][jj]-'0'==a[jj])
                      x++;
                   if(hash[a[jj]])
                      y++;
               }
               if(b[j][0]-'0'==x&&b[j][2]-'0'==y)
                    cnt++;
            }
            if(cnt==n)
            {
               printf("%04d\n",i);//这种输出的方法很独特
               break;
            }
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值