public class GuessRank {
public static void main(String[] args) {
for(int a = 1; a<=5; a++){
for(int b = 1; b<=5; b++){
for(int c = 1; c<=5; c++){
for(int d = 1; d<=5; d++){
for(int e = 1; e<=5; e++){
if(toMeetAllTheConditions(a,b,c,d,e)) {
System.out.println("a:"+a+" b:"+b+" c:"+c+" d:"+d+" e:"+e);
}
}
}
}
}
}
}
private static boolean toMeetAllTheConditions(int a, int b, int c, int d, int e) {
if( (a==b)||(a==c)||(a==d)||(a==e)||(b==c)||(b==d)||(b==e)||(c==d)||(c==e)||(d==e) ) return false; if( (e==2)||(e==3) ) return false; if( ((a==1)||(a==2)) && (e!=1) ) return false;
if( ((a!=1)&&(a!=2)) && (e==1) ) return false; if( ((b==1)||(b==2)) && (b!=2) ) return false;
if( ((b!=1)&&(b!=2)) && (b==2) ) {/*DoNothing*/} if( ((c==1)||(c==2)) && (a!=5) ) return false;
if( ((c!=1)&&(c!=2)) && (a==5) ) return false; if( ((d==1)||(d==2)) && (c==1) ) return false;
if( ((d!=1)&&(d!=2)) && (c!=1) ) return false; if( ((e==1)||(e==2)) && (d!=1) ) return false;
if( ((e!=1)&&(e!=2)) && (d==1) ) return false; return true;
}
}
public static void main(String[] args) {
for(int a = 1; a<=5; a++){
for(int b = 1; b<=5; b++){
for(int c = 1; c<=5; c++){
for(int d = 1; d<=5; d++){
for(int e = 1; e<=5; e++){
if(toMeetAllTheConditions(a,b,c,d,e)) {
System.out.println("a:"+a+" b:"+b+" c:"+c+" d:"+d+" e:"+e);
}
}
}
}
}
}
}
private static boolean toMeetAllTheConditions(int a, int b, int c, int d, int e) {
if( (a==b)||(a==c)||(a==d)||(a==e)||(b==c)||(b==d)||(b==e)||(c==d)||(c==e)||(d==e) ) return false; if( (e==2)||(e==3) ) return false; if( ((a==1)||(a==2)) && (e!=1) ) return false;
if( ((a!=1)&&(a!=2)) && (e==1) ) return false; if( ((b==1)||(b==2)) && (b!=2) ) return false;
if( ((b!=1)&&(b!=2)) && (b==2) ) {/*DoNothing*/} if( ((c==1)||(c==2)) && (a!=5) ) return false;
if( ((c!=1)&&(c!=2)) && (a==5) ) return false; if( ((d==1)||(d==2)) && (c==1) ) return false;
if( ((d!=1)&&(d!=2)) && (c!=1) ) return false; if( ((e==1)||(e==2)) && (d!=1) ) return false;
if( ((e!=1)&&(e!=2)) && (d==1) ) return false; return true;
}
}
解决方案 »
- [Java][Swing]可以开发多点触摸桌面程序吗?win7系统下
- 急,关于查询内容导出到txt的问题
- java怎样和sql连啊,代码怎么写啊?偶是新手,多多帮忙!
- 什么是daemon线程,有何作用?
- 求一简单特殊字符识别显示程序:在线等
- 各位大哥,有没有下载java编译器的网址啊??
- 用JAVA开发一个带加密解密功能的记事本,不知道该怎么做?
- java 第8章补充题目
- 请高手帮忙:applet、socket、数据库安全问题
- Java jbutton 点击一次 实现这个按钮往下移动 怎么才能实现????(新手没有分 请熟手帮忙谢谢)
- 使用java实现求树形结构通路的问题
- JAVA数据库连接问题
public static void main(String[] args) {
for(int a = 1; a<=5; a++){
for(int b = 1; b<=5; b++){
for(int c = 1; c<=5; c++){
for(int d = 1; d<=5; d++){
for(int e = 1; e<=5; e++){
if(toMeetAllTheConditions(a,b,c,d,e)) {
System.out.println("a:"+a+" b:"+b+" c:"+c+" d:"+d+" e:"+e);
}
}
}
}
}
}
}
private static boolean toMeetAllTheConditions(int a, int b, int c, int d, int e) {
if( (a==b)||(a==c)||(a==d)||(a==e)||(b==c)||(b==d)||(b==e)||(c==d)||(c==e)||(d==e) ) return false; if( (e==2)||(e==3) ) return false; if( ((a==1)||(a==2)) && (e!=1) ) return false;
if( ((a!=1)&&(a!=2)) && (e==1) ) return false; if( ((b==1)||(b==2)) && (b!=2) ) return false;
if( ((b!=1)&&(b!=2)) && (b==2) ) {/*DoNothing*/} if( ((c==1)||(c==2)) && (a!=5) ) return false;
if( ((c!=1)&&(c!=2)) && (a==5) ) return false; if( ((d==1)||(d==2)) && (c==1) ) return false;
if( ((d!=1)&&(d!=2)) && (c!=1) ) return false; if( ((e==1)||(e==2)) && (d!=1) ) return false;
if( ((e!=1)&&(e!=2)) && (d==1) ) return false; return true;
}
}
public class t {
public static void main(String[] args) {
// 6、有A、B、C、D和E共5所学校。在一次检查评比中,已知E肯定不是第2或第3名,
// 他们互相进行推测,A校有人说,E校肯定是第1名;B校有人说,我校可能是第2名;
// C校有人说,A校最差;D校有人说,C校不是最好;E校有人说,D校会获得第一名。
// 结果只有第一名和第二名的学校的人猜对了。编程指出这5所学校的名词。
// 条件:E肯定不是第2或第3名(E!=2&&E!=3) 第一名和第二名的学校的人猜对了 其它的都错了
// A校有人说,E校肯定是第1名;(A不能是第一名或第二名)
// B校有人说,我校可能是第2名 (B校不能是第一名)
// C校有人说,A校最差;
// D校有人说,C校不是最好
// E校有人说,D校会获得第一名
String[] str = { "A", "B", "C", "D", "E" };//五个人
System.out.println("1 2 3 4 5");
for (int i = 0; i < 5; i++) {// 第一名
for (int j = 0; j < 5; j++) {// 第二名
for (int k = 0; k < 5; k++) {// 第三名
for (int l = 0; l < 5; l++) {// 第四名
for (int m = 0; m < 5; m++) {// 第五名
boolean dyi = false;//第一名
boolean der = false;//第二名
boolean dsan = true;//第三名
boolean dsi = true;//第四名
boolean dwu = true;//第五名
if (j != i && k != i && k != j && l != i && l != j
&& l != k && m != i && m != j && m != k
&& m != l) {// 消除重复
if (4 != j && 4 != k) {//E不能为第二名也不能为第三名
if (i == 0) {// A为第一名时
if (i == 4) {// E为第一名
dyi = true;
}
}
if (j == 0) {// A为第二名时
if (i == 4) {// E为第一名
der = true;
}
}
if (i == 1) {// B为第一名时
if (j == 1) {// B为第二名
dyi = true;
}
}
if (j == 1) {// B为第二名时
if (j == 1) {// B为第二名
der = true;
}
}
if (i == 2) {// C为第一名时
if (m == 0) {// A为第五名
dyi = true;
}
}
if (j == 2) {// C为第二名时
if (m == 0) {// A为第五名
der = true;
}
}
if (i == 3) {// D为第一名时
if (i != 2) {// C不等于第一名
dyi = true;
}
}
if (j == 3) {// D为第二名时
if (i != 2) {// C不等于第一名
der = true;
}
}
if (i == 4) {// E为第一名时
if (i == 3) {// D为第一名
dyi = true;
}
}
if (j == 4) {// E为第二名时
if (i == 3) {// D为第一名
der = true;
}
}
// 三四五名均为false
if (k == 0) {// 第三名为A时
if (i != 4) {
dsan = false;
}
}
if (k == 1) {// 第三名为B时
if (j != 1) {
dsan = false;
}
}
if (k == 2) {// 第三名为C时
if (m != 0) {// A不为最差
dsan = false;
}
}
if (k == 3) {// 第三名为D时
if (i == 2) {// C校是最好
dsan = false;
} }
if (l == 0) {// 第四名为A时
if (i != 4) {
dsi = false;
}
}
if (l == 1) {// 第四名为B时
if (j != 1) {
dsi = false;
}
}
if (l == 2) {// 第四名为C时
if (m != 0) {// A不为最差
dsi = false;
}
}
if (l == 3) {// 第四名为D时
if (i == 2) {// C校是最好
dsi = false;
} }
if (l == 4) {// 第四名为E时
// D校不等于第一名
if (i != 3) {
dsi = false;
}
}
if (m == 0) {// 第五名为A时
if (i != 4) {
dwu = false;
}
}
if (m == 1) {// 第五名为B时
if (j != 1) {
dwu = false;
}
}
if (m == 2) {// 第五名为C时
if (m != 0) {// A不为最差
dwu = false;
}
}
if (m == 3) {// 第五名为D时
if (i == 2) {// C校是最好
dwu = false;
} }
if (m == 4) {// 第五名为E时
// D校不等于第一名
if (i != 3) {
dwu = false;
}
}
if (dyi == true && der == true
&& dsan == false && dsi == false
&& dwu == false) {
System.out.println(str[i] + " "
+ str[j] + " " + str[k] + " "
+ str[l] + " " + str[m]);
}
} } } }
} } }
}}