您的位置:首页 > 其它

hdu 1172 猜数字

2011-09-11 19:25 441 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1172
/*
2011-9-11
author:BearFly1990
*/
package acm.hdu.tests;

import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;

public class hdu_1172 {
public static int[][] a = new int[110][3];
public static int t ;
public static int result;
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedInputStream(System.in));

while(in.hasNext()){
t = in.nextInt();
if(t == 0)break;
result = 0;
for(int i = 0; i < t; i++){
a[i][0] = in.nextInt();
a[i][1] = in.nextInt();
a[i][2] = in.nextInt();
}
if(!find()){
System.out.println("Not sure");
}else{
System.out.println(result);
}

}
}
private static boolean find() {

int count = 0;
int[] n = new int[4];
int[] z = new int[4];
for(int i = 3585; i < 10000; i++){
n[0] = i%10;
n[1] = i/10%10;
n[2] = i/100%10;
n[3] = i/1000%10;
boolean isTrueNum = true;
for(int j = 0; j < t; j++){
int findTrue = 0;
int findAll = 0;

z[0] = a[j][0]%10;
z[1] = a[j][0]/10%10;
z[2] = a[j][0]/100%10;
z[3] = a[j][0]/1000%10;
boolean[] flag = new boolean[4];
Arrays.fill(flag, false);
for(int k = 0; k < 4; k++){
for(int l = 0 ; l < 4; l++){
if(n[l] == z[k] && !flag[l]){
flag[l] = true;
findAll++;
break;
}
}
}
for(int k = 0 ; k < 4; k++){
if(n[k] == z[k])findTrue++;
}
if(findTrue != a[j][2] || findAll != a[j][1]){
isTrueNum = false;
break;
}
}
if(isTrueNum){
result = i;
count++;
}
if(count > 1)break;
}
if(count > 1 || count == 0)return false;
return true;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: