nefu 640 Number Guessing
2014-05-02 18:26
381 查看
Number Guessing | ||
| ||
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 <cstdio>
#include <cstring>
using namespace std;
int num,x,y,n;
int vis[11111],dig[10],a[11111];
char str[10];
int rt(int num,int now)
{
int ret=0;
for(int i=0; i<4; i++)
{
if(num%10==now%10)
{
ret++;
}
num/=10;
now/=10;
}
return ret;
}
int pos(int num,int now)
{
int dig1[10],dig2[10],ret=0;
for(int i=0; i<4; i++)
{
dig1[i]=num%10;
num/=10;
dig2[i]=now%10;
now/=10;
}
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
if(dig1[i]==dig2[j])
ret++;
}
}
return ret;
}
int main()
{
int cnt=0,ans;
for(int i=0; i<=9999; i++)
{
dig[0]=i%10;
dig[1]=(i/10)%10;
dig[2]=(i/100)%10;
dig[3]=(i/1000)%10;
if(dig[0]==dig[1]||dig[0]==dig[2]||dig[0]==dig[3]||dig[1]==dig[2]||dig[1]==dig[3]||dig[2]==dig[3])
continue;
a[cnt++]=i;
}
//for(int i=0;i<cnt;i++) cout<<a[i]<<" ";
while(~scanf("%d",&n))
{
if(n<=0) break;
memset(vis,0,sizeof(vis));
for(int i=0; i<n; i++)
{
scanf("%d%s",&num,str);
x=str[0]-'0';
y=str[2]-'0';
//cout<<"x="<<x<<" y="<<y<<endl;
for(int i=0; i<cnt; i++)
{
if(vis[i]) continue;
//cout<<"ai="<<a[i]<<endl;
if(rt(num,a[i])!=x||pos(num,a[i])!=y)
vis[i]=1;
else
{
ans=a[i];
//cout<<"==="<<ans<<endl;
}
}
}
//cout<<"ans="<<ans<<endl;
dig[0]=ans%10;
dig[1]=(ans/10)%10;
dig[2]=(ans/100)%10;
dig[3]=(ans/1000)%10;
for(int i=3; i>=0; i--)
{
printf("%d",dig[i]);
}
printf("\n");
}
return 0;
}
相关文章推荐
- NEFU 725 Number Guessing 枚举
- NEFU 725 Number Guessing 枚举
- csuoj 1353: Guessing the Number
- [coj 1353 Guessing the Number]kmp,字符串最小表示法
- POJ 3589 Number-guessing Game(水~)
- nefu 640 Number Guessing
- Number-guessing Game
- poj 3589 Number-guessing Game
- TZU2014年省赛个人热身赛1 1197:Number Guessing
- poj3589 Number-guessing Game
- HNU Number Guessing
- NEFU 640 猜数
- POJ 3589 Number-guessing Game(简单题)
- poj 3589 Number-guessing Game(水题)
- POJ 3589 Number-guessing Game G++
- POJ 3589 Number-guessing Game(简单题)
- POJ3589 Number-guessing Game
- pku 3589 Number-guessing Game 解题报告
- (Relax ST1.16)POJ 3589 Number-guessing Game(求连个字符串中相同的字符有多少个和同位置&&同字符的字符个数有多少个)
- poj 3589 Number-guessing Game