zoukankan      html  css  js  c++  java
  • NEFU 725 Number Guessing 枚举

    Number Guessing

    Time Limit 1000ms

    Memory Limit 65536K

    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
    							
    ----------------

    直接枚举数字匹配

    ----------------

    #include <iostream>
    #include <cstring>
    using namespace std;
    
    int a[11111]= {0};
    bool v[11111]= {0};
    int cnt=0;
    char g[10];
    int t,x,y;
    int n;
    int err=0;
    char str[10];
    
    bool check(int i)
    {
        int a,b,c,d;
        a=i%10;
        i/=10;
        b=i%10;
        i/=10;
        c=i%10;
        i/=10;
        d=i%10;
        if (a!=b&&a!=c&&a!=d&&b!=c&&b!=d&&c!=d)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    int bull(int t,int p)
    {
        int ret=0;
        for (int i=0; i<4; i++)
        {
            if (t%10==p%10)
            {
                ret++;
            }
            t/=10;
            p/=10;
        }
        return ret;
    }
    
    int cow(int t,int p)
    {
        int ret=0;
        int arr1[5];
        int arr2[5];
        for (int i=0; i<4; i++)
        {
            arr1[i]=t%10;
            t/=10;
            arr2[i]=p%10;
            p/=10;
        }
        for (int i=0; i<4; i++)
        {
            for (int j=0; j<4; j++)
            {
                if (arr1[i]==arr2[j])
                {
                    ret++;
                }
            }
        }
        return ret;
    }
    
    
    int main()
    {
        int out;
        cnt=0;
        for (int i=0; i<=9999; i++)
        {
            if (check(i))
            {
                a[cnt++]=i;
            }
        }
    
        while (cin>>n)
        {
            if (n<=0) break;
            memset(v,0,sizeof(v));
            int ans=cnt;
            while (n--)
            {
                cin>>t;
                cin>>str;
                x=str[0]-'0';
                y=str[2]-'0';
                //cout<<x<<" "<<y<<endl;
                for (int i=0; i<cnt; i++)
                {
                    if (v[i]) continue;
                    if (bull(t,a[i])!=x||cow(t,a[i])!=y)
                    {
                        v[i]=true;
                    }
                    else
                    {
                        out=a[i];
                    }
                }
            }
            int a,b,c,d;
            a=out%10;
            out/=10;
            b=out%10;
            out/=10;
            c=out%10;
            out/=10;
            d=out%10;
            cout<<d<<c<<b<<a<<endl;
        }
        return 0;
    }
    







  • 相关阅读:
    如何高效查看 Docker 日志
    linux:有效使用docker logs查看日志
    FFmpeg命令行工具学习(一):查看媒体文件头信息工具ffprobe
    性能调优
    【禅道】Windows本地安装禅道2.0.9
    Handle
    Operate the elements
    Web功能测试常用方法
    Drop down box selection(Select)
    Iframe
  • 原文地址:https://www.cnblogs.com/cyendra/p/3226305.html
Copyright © 2011-2022 走看看