HDU 1172

Problem Description

Input

Output

Solution

``````#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int n,a[105],b[105],c[105],num,ans;
int fx[5],fy[5];
bool re[5];

int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';ch=getchar();}
return x*f;
}
inline void check(int x){

fy[1]=x/1000;
fy[2]=x/100%10;
fy[3]=x/10%10;
fy[4]=x%10;
bool flag=0;

for(int i=1;i<=n;i++){

int tw=0;//同位
int cx=0;//出现
fx[1]=a[i]/1000;
fx[2]=a[i]/100%10;
fx[3]=a[i]/10%10;
fx[4]=a[i]%10;//分解此数字

for(int j=1;j<=4;j++){
//判断同位是否相同
if(fx[j]==fy[j]) tw++;
}
if(tw!=c[i]) flag=1;

for(int j=1;j<=4;j++) re[j]=0;

for(int j=1;j<=4;j++){
//枚举这sb猜的数字
for(int k=1;k<=4;k++){
//判断这和数字
if(fx[j]==fy[k]&&re[k]==0){

cx++;
re[k]=1;
break;
}
}
}
if(cx!=b[i]) flag=1;
}

if(!flag){

num++;
ans=x;
}
return ;
}
int main(){

while(scanf("%d",&n)==1){

if(!n) break;

num=0;
for(int i=1000;i<=9999;i++) check(i);
if(num==1) printf("%d\n",ans);
else puts("Not sure");
}
return 0;
}
``````

2022-12-29 14:21

2022-12-15 01:36

2022-12-10 09:46

2022-11-30 12:50

2022-12-26 18:01

2022-12-02 22:32

2022-12-28 17:14