返回
基础
分类

4 没有人有相同的宠物,3、 每个人喝不同的饮料

日期: 2020-03-16 12:52 浏览次数 : 184

下面的问题相信很多人都听过:
1 有五栋五种颜色的房子
2 每一位房子的主人国籍都不同
3 这五个人每人只喝一种饮料,只抽一种牌子的香烟,只养一种宠物
4 没有人有相同的宠物,抽相同牌子的香烟,喝相同的饮料

必赢手机登录网址 , 源码下载地址:

题目是:
1、 在一条街上,有5座房子,喷了5种颜色。 
2、 每个房里住着不同国籍的人 
3、 每个人喝不同的饮料,抽不同品牌的香烟,养不同的宠物 
约束条件:
1、 英国人住红色房子 
2、 瑞典人养狗 
3、 丹麦人喝茶 
4、 绿色房子在白色房子左面 
5、 绿色房子主人喝咖啡 
6、 抽Pall Mall 香烟的人养鸟 
7、 黄色房子主人抽、Dunhill 香烟 
8、 住在中间房子的人喝牛奶 
9、 挪威人住第一间房 
10、抽Blends香烟的人住在养猫的人隔壁 
11、养马的人住抽Dunhill 香烟的人隔壁 
12、抽Blue Master的人喝啤酒 
13、德国人抽Prince香烟 
14、挪威人住蓝色房子隔壁 
15、抽Blends香烟的人有一个喝水的邻居

提示:

问题:

问题是:谁养鱼?

1、 英国人住在红房子里
2 、瑞典人养了一条狗
3 、丹麦人喝茶
4 、绿房子在白房子左边
5 、绿房子主人喝咖啡
6 、抽PALL MALL烟的人养了一只鸟
7 、黄房子主人抽DUNHILL烟
8 、住在中间那间房子的人喝牛奶
9 、挪威人住第一间房子
10 、抽混合烟的人住在养鱼人的旁边
11 、养马人住在DUNHILL烟的人旁边
12 、抽BLUE MASTER烟的人喝啤酒
13、 德国人抽PRINCE烟
14 、挪威人住在蓝房子旁边
15 、抽混合烟的人的邻居喝矿泉水

 

#include<stdio.h>
char*COL[]={NULL,"红","黄","绿","蓝","白"};
char*PAD[]={NULL,"狗","猫","鱼","鸟","马"};
char*DRK[]={NULL,"茶  ","牛奶","咖啡","啤酒","水  "};
char*GUO[]={NULL,"挪威","英国","德国","丹麦","瑞典"};
char*SMK[]={NULL,"Blends","BlueMaster","Dunhill","Pall Mall","Prince"};
struct{ char guojia, color, pads, drink, smoke; } aa[5];
int OK(void)
{
    int i,j;
    for(i=0;i<5;i++)
     if(aa[i].guojia==2 && aa[i].color==1)goto next1;
    return 0;
next1:
    for(i=0;i<5;i++)
     if(aa[i].guojia==5 && aa[i].pads==1)goto next2;
    return 0;
next2:    
    for(i=0;i<5;i++)
     if(aa[i].guojia==4 && aa[i].drink==1)goto next3;
    return 0;
next3:
    for(i=0;i<5;i++)
     if(aa[i].color==3)goto next3_1;
    return 0;
next3_1:
    for(j=i+1;j<5;j++)
     if(aa[j].color==5)goto next4;
    return 0;
next4:
    for(i=0;i<5;i++)
     if(aa[i].color==3 && aa[i].drink==3)goto next5;
    return 0;
next5:
    for(i=0;i<5;i++)
     if(aa[i].smoke==4 && aa[i].pads==4)goto next6;
    return 0;
next6:
    for(i=0;i<5;i++)
     if(aa[i].color==2 && aa[i].smoke==3)goto next7;
    return 0;
next7:
    for(i=0;i<5;i++)
     if(aa[i].guojia==3 && aa[i].smoke==5)goto next10;
    return 0;
next10:
    for(i=0;i<5;i++)
     if(aa[i].smoke==2 && aa[i].drink==4)goto next11;
    return 0;
next11:
    for(i=0;i<5;i++)
     if(aa[i].smoke==3)goto next12_1;
next12_1:
    if(i==0){if(aa[1].pads==5)goto next13;}
    else if(i==4){if(aa[3].pads==5)goto next13;}
    else if(aa[i-1].pads==5||aa[i+1].pads==5)goto next13;
    return 0;
next13:
    for(i=0;i<5;i++)
     if(aa[i].smoke==1)goto next13_1;
next13_1:
    if(i==0){if(aa[1].pads==2)goto next14;}
    else if(i==4){if(aa[3].pads==2)goto next14;}
    else if(aa[i-1].pads==2||aa[i+1].pads==2)goto next14;
    return 0;
next14:
    for(i=0;i<5;i++)
     if(aa[i].smoke==1)goto next14_1;
next14_1:
    if(i==0){if(aa[1].drink==5)goto next15;}
    else if(i==4){if(aa[3].drink==5)goto next15;}
    else if(aa[i-1].drink==5||aa[i+1].drink==5)goto next15;
    return 0;
next15:
    return 1;
}

问题是: 谁养鱼?
这道迷题出自1981年柏林的德国逻辑思考学院。据说世界上只有2%的人能出答案。就连大名鼎鼎的爱因斯坦也成为此题大伤脑筋,所以这道题也经常被国内外知名公司用做面试题目,相信许多朋友都只做出过一个答案,如果碰巧你属于那98%该怎么办呢。没关系,如果这个问题用电脑来解决就非常easy了。
程序代码如下:
using System;

1、在一条街上,有5座房子,喷了5种颜色。 
2、每个房里住着不同国籍的人 
3、每个人喝不同的饮料,抽不同品牌的香烟,养不同的宠物 
问题是:谁养鱼? 
提示: 
1、英国人住红色房子 
2、瑞典人养狗 
3、丹麦人喝茶 
4、绿色房子在白色房子左面 
5、绿色房子主人喝咖啡 
6、抽Pall Mall 香烟的人养鸟 
7黄色房子主人抽、Dunhill 香烟 
8、住在中间房子的人喝牛奶 
9、 挪威人住第一间房 
10、抽Blends香烟的人住在养猫的人隔壁 
11、养马的人住抽Dunhill 香烟的人隔壁 
12、抽Blue Master的人喝啤酒 
13、德国人抽Prince香烟 
14、挪威人住蓝色房子隔壁 
15、抽Blends香烟的人有一个喝水的邻居
你们可以猜得出来吗?

char color[4]={1,2,3,5};
char drink[4]={1,3,4,5};
char guojia[4]={2,3,4,5};
char smoke[]={1,2,3,4,5};
char pads[5]={1,2,3,4,5};

namespace netsafe.math
{

 

int rot(char a[],int n)
{   int i,j,k,t;
    for(k=n-1;k>0;k--)
       if(a[k-1]<a[k])break;
    if(k==0)
    { for(i=0,j=n-1;i<j;i++,j--)
      {char t=a[i];
           a[i]=a[j];
           a[j]=t;
      }
      return 0;
    }
    t=a[k-1];i=k;
    for(j=k+1;j<n;j++)
      if(t<a[j]&&a[j]<a[i])i=j;
    a[k-1]=a[i];a[i]=t;
    for(i=k;i<n-1;i++)
      for(j=k;j<n-1+k-i;j++)
        if(a[j]>a[j+1])
        {  t=a[j];
           a[j]=a[j+1];
           a[j+1]=t;
        }
    return 1;
}

public class ayst
{

 

int main()
{   int i,j,k,ans=0;
    int i1,i2,i3,i4,i5;
    aa[1].color=4;
    aa[2].drink=2;
    aa[0].guojia=1;
    for(i1=0;i1<24;i1++){
        aa[0].color=color[0];
        aa[2].color=color[1];
        aa[3].color=color[2];
        aa[4].color=color[3]; 
        rot(color,4);
    for(i2=0;i2<24;i2++){
        aa[0].drink=drink[0];
        aa[1].drink=drink[1];
        aa[3].drink=drink[2];
        aa[4].drink=drink[3];
        rot(drink,4);
    for(i3=0;i3<24;i3++){
        aa[1].guojia=guojia[0];
        aa[2].guojia=guojia[1];
        aa[3].guojia=guojia[2];
        aa[4].guojia=guojia[3];
        rot(guojia,4);
    for(i4=0;i4<120;i4++){
        for(i=0;i<5;i++)
        aa[i].smoke=smoke[i];
        rot(smoke,5);
    for(i5=0;i5<120;i5++){
        for(j=0;j<5;j++)
        aa[j].pads=pads[j];
        rot(pads,5);
        if(OK()){
        printf("---------------------第%d种解---------------------n",++ans);
        for(k=0;k<5;k++)
        printf("第%d户: %s人 %s房子 养%s 喝%s 抽%sn",k+1,GUO[aa[k].guojia],
        COL[aa[k].color],PAD[aa[k].pads],DRK[aa[k].drink],SMK[aa[k].smoke]);
    }}}}}}
    return 0;
}

///
/// 问题中的所有元素
///
string[,] data= {{"黄房子", "蓝房子", "白房子", "红房子", "绿房子"},
{"挪威人", "英国人", "德国人", "丹麦人", "瑞典人"},
{"DUNHILL", "PRINCE", "混合烟", "PALL MALL", "BLUE MASTER"},
{"咖 啡", "矿泉水", "茶", "牛奶", " 啤酒 "},
{"鱼", " 恐龙", "马", "鸟", "狗"}};

 

 

///
/// answer用来存放答案
///
int[,] answer=new int[6, 6];

算法1:

运行结果表明:总共有七组可能的解答,具体如下 ---------------------第1种解---------------------
第1户: 挪威人 黄房子 养猫 喝水   抽Dunhill
第2户: 丹麦人 蓝房子 养马 喝茶   抽Blends
第3户: 英国人 红房子 养鸟 喝牛奶 抽Pall Mall
第4户: 德国人 绿房子 养鱼 喝咖啡 抽Prince
第5户: 瑞典人 白房子 养狗 喝啤酒 抽BlueMaster
---------------------第2种解---------------------
第1户: 挪威人 绿房子 养鸟 喝咖啡 抽Pall Mall
第2户: 德国人 蓝房子 养猫 喝水   抽Prince
第3户: 英国人 红房子 养马 喝牛奶 抽Blends
第4户: 丹麦人 黄房子 养鱼 喝茶   抽Dunhill
第5户: 瑞典人 白房子 养狗 喝啤酒 抽BlueMaster
---------------------第3种解---------------------
第1户: 挪威人 绿房子 养鸟 喝咖啡 抽Pall Mall
第2户: 德国人 蓝房子 养鱼 喝水   抽Prince
第3户: 英国人 红房子 养马 喝牛奶 抽Blends
第4户: 丹麦人 黄房子 养猫 喝茶   抽Dunhill
第5户: 瑞典人 白房子 养狗 喝啤酒 抽BlueMaster
---------------------第4种解---------------------
第1户: 挪威人 绿房子 养鱼 喝咖啡 抽Blends
第2户: 德国人 蓝房子 养猫 喝水   抽Prince
第3户: 瑞典人 黄房子 养狗 喝牛奶 抽Dunhill
第4户: 英国人 红房子 养马 喝啤酒 抽BlueMaster
第5户: 丹麦人 白房子 养鸟 喝茶   抽Pall Mall
---------------------第5种解---------------------
第1户: 挪威人 绿房子 养鸟 喝咖啡 抽Pall Mall
第2户: 德国人 蓝房子 养猫 喝水   抽Prince
第3户: 瑞典人 白房子 养狗 喝牛奶 抽Blends
第4户: 英国人 红房子 养马 喝啤酒 抽BlueMaster
第5户: 丹麦人 黄房子 养鱼 喝茶   抽Dunhill
---------------------第6种解---------------------
第1户: 挪威人 绿房子 养鸟 喝咖啡 抽Pall Mall
第2户: 德国人 蓝房子 养猫 喝水   抽Prince
第3户: 瑞典人 白房子 养狗 喝牛奶 抽Blends
第4户: 丹麦人 黄房子 养鱼 喝茶   抽Dunhill
第5户: 英国人 红房子 养马 喝啤酒 抽BlueMaster
---------------------第7种解---------------------
第1户: 挪威人 绿房子 养鸟 喝咖啡 抽Pall Mall
第2户: 德国人 蓝房子 养鱼 喝水   抽Prince
第3户: 瑞典人 白房子 养狗 喝牛奶 抽Blends
第4户: 丹麦人 黄房子 养猫 喝茶   抽Dunhill
第5户: 英国人 红房子 养马 喝啤酒 抽BlueMaster

int[,] ALL=new int[6,122];
int count=1;
int nLevel = 0;
int[] List=new int[6];
public static void Main(string[] args)
{
ayst c=new ayst();
c.p(); ///生成全排列到all
c.run();
Console.Read(); /// 按任意键继续

 

}
void run()
{
int i1,i2,i3,i4,i5;
///通过逻辑条件顺序的有效选择来优化程序
for (i1=1;i1<=120;i1++) ///房子
{
/// 9 、挪威人住第一间房子
/// 14 、挪威人住在蓝房子旁边
/// 不满足条件就短路
///

[csharp] view plaincopyprint?

if (ALL[2,i1]!=2)continue;

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Text;  
  4. using System.Collections;  
  5. namespace AiYinSiTan  
  6. {  
  7.     class Program  
  8.     {  
  9.         static void Main(string[] args)  
  10.         {  
  11.             string[] 饮料 = new string[4]{ "咖啡", "牛奶", "啤酒", "矿泉水" };  
  12.             string[] 香烟 = new string[4]{ "PALL MALL", "DUNHILL", "BLUE MASTER", "混合烟" };  
  13.             string[] 宠物 = new string[4]{ "鸟", "猫", "马", "鱼" };  
  14.             string[] 房子 = new string[4]{ "白", "绿", "黄", "蓝" };  
  15.             int[] 房子次序 = new int[4] { 2, 3, 4, 5 };  
  16.   
  17.             //int counnum = 0;  
  18.             #region 穷举所有可能性  
  19.             for (int i = 0; i < 4; i++)//饮料  
  20.             {  
  21.                 string 英国人饮料 = 饮料[i];  
  22.                 for (int i1 = 0; i1 < 4; i1++)  
  23.                 {  
  24.                     if (饮料[i1] != 饮料[i])  
  25.                     {  
  26.                         string 瑞典人饮料 = 饮料[i1];  
  27.                         for (int i2 = 0; i2 < 4; i2++)  
  28.                         {  
  29.                             if (饮料[i2] != 饮料[i] && 饮料[i2] != 饮料[i1] )  
  30.                             {  
  31.                                 string 挪威人饮料 = 饮料[i2];  
  32.                                 for (int i3 = 0; i3 < 4; i3++)  
  33.                                 {  
  34.                                     if (饮料[i3] != 饮料[i] && 饮料[i3] != 饮料[i1] && 饮料[i3] != 饮料[i2])  
  35.                                     {  
  36.                                         string 德国人饮料 = 饮料[i3];  
  37.                                         for (int j = 0; j < 4; j++)  
  38.                                         {  
  39.                                             string 英国人香烟 = 香烟[j];  
  40.                                             for (int j1 = 0; j1 < 4; j1++)  
  41.                                             {  
  42.                                                 if (香烟[j1] != 香烟[j])  
  43.                                                 {  
  44.                                                     string 瑞典人香烟 = 香烟[j1];  
  45.                                                     for (int j2 = 0; j2 < 4; j2++)  
  46.                                                     {  
  47.                                                         if (香烟[j2] != 香烟[j] && 香烟[j2] != 香烟[j1])  
  48.                                                         {  
  49.                                                             string 挪威人香烟 = 香烟[j2];  
  50.                                                             for (int j3 = 0; j3 < 4;j3++)  
  51.                                                             {  
  52.                                                                 if (香烟[j3] != 香烟[j] && 香烟[j3] != 香烟[j1] && 香烟[j3] != 香烟[j2])  
  53.                                                                 {  
  54.                                                                     string 丹麦人香烟 = 香烟[j3];  
  55.                                                                     for (int l = 0; l < 4; l++)  
  56.                                                                     {  
  57.                                                                         string 英国人宠物 = 宠物[l];  
  58.                                                                         for (int l1 = 0; l1 < 4; l1++)  
  59.                                                                         {  
  60.                                                                             if (宠物[l1] != 宠物[l])  
  61.                                                                             {  
  62.                                                                                 string 德国人宠物 = 宠物[l1];  
  63.                                                                                 for (int l2 = 0; l2 < 4; l2++)  
  64.                                                                                 {  
  65.                                                                                     if (宠物[l2] != 宠物[l] && 宠物[l2] != 宠物[l1])  
  66.                                                                                     {  
  67.                                                                                         string 挪威人宠物 = 宠物[l2];  
  68.                                                                                         for (int l3 = 0; l3 < 4; l3++)  
  69.                                                                                         {  
  70.                                                                                             if (宠物[l3] != 宠物[l] && 宠物[l3] != 宠物[l1] && 宠物[l3] != 宠物[l2])  
  71.                                                                                             {  
  72.                                                                                                 string 丹麦人宠物 = 宠物[l3];  
  73.                                                                                                 for (int m = 0; m < 4; m++)  
  74.                                                                                                 {  
  75.                                                                                                     string 瑞典人房子 = 房子[m];  
  76.                                                                                                     for (int m1 = 0; m1 < 4; m1++)  
  77.                                                                                                     {  
  78.                                                                                                         if (房子[m1] != 房子[m])  
  79.                                                                                                         {  
  80.                                                                                                             string 德国人房子 = 房子[m1];  
  81.                                                                                                             for (int m2 = 0; m2 < 4; m2++)  
  82.                                                                                                             {  
  83.                                                                                                                 if (房子[m2] != 房子[m] && 房子[m2] != 房子[m1])  
  84.                                                                                                                 {  
  85.                                                                                                                     string 挪威人房子 = 房子[m2];  
  86.                                                                                                                     for (int m3 = 0; m3 < 4; m3++)  
  87.                                                                                                                     {  
  88.                                                                                                                         if (房子[m3] != 房子[m] && 房子[m3] != 房子[m1] && 房子[m3] != 房子[m2])  
  89.                                                                                                                         {  
  90.                                                                                                                             string 丹麦人房子 = 房子[m3];  
  91.                                                                                                                             for (int n = 0; n < 4; n++)  
  92.                                                                                                                             {  
  93.                                                                                                                                 int 英国人房子次序 = 房子次序[n];  
  94.                                                                                                                                 for (int n1 = 0; n1 < 4; n1++)  
  95.                                                                                                                                 {  
  96.                                                                                                                                     if (房子次序[n1] != 房子次序[n])  
  97.                                                                                                                                     {  
  98.                                                                                                                                         int 德国人房子次序 = 房子次序[n1];  
  99.                                                                                                                                         for (int n2 = 0; n2 < 4; n2++)  
  100.                                                                                                                                         {  
  101.                                                                                                                                             if (房子次序[n2] != 房子次序[n] && 房子次序[n2] != 房子次序[n1])  
  102.                                                                                                                                             {  
  103.                                                                                                                                                 int 瑞典房子次序 = 房子次序[n2];  
  104.                                                                                                                                                 for (int n3 = 0; n3 < 4; n3++)  
  105.                                                                                                                                                 {  
  106.                                                                                                                                                     if (房子次序[n3] != 房子次序[n] && 房子次序[n3] != 房子次序[n1] && 房子次序[n3] != 房子次序[n2])  
  107.                                                                                                                                                     {  
  108.                                                                                                                                                         int 丹麦人房子次序 = 房子次序[n3];  
  109.  
  110.                                                                                                                                                         #region 构造相关结果  
  111.                                                                                                                                                         //counnum++;  
  112.                                                                                                                                                         //if (counnum == 4801)  
  113.                                                                                                                                                         //{  
  114.                                                                                                                                                         //    Console.WriteLine("ffffffffffff");  
  115.                                                                                                                                                         //}  
  116.                                                                                                                                                         //Console.WriteLine("第"+counnum.ToString()+"次操作!");  
  117.                                                                                                                                                         //生成符合条件的对象  
  118.                                                                                                                                                         Man 英国人啊 = new Man();  
  119.                                                                                                                                                         英国人啊.国籍 = "英国";  
  120.                                                                                                                                                         英国人啊.房子 = "红";  
  121.                                                                                                                                                         英国人啊.香烟 = 英国人香烟;  
  122.                                                                                                                                                         英国人啊.宠物 = 英国人宠物;  
  123.                                                                                                                                                         英国人啊.房子次序 = 英国人房子次序;  
  124.                                                                                                                                                         英国人啊.饮料 = 英国人饮料;  
  125.   
  126.                                                                                                                                                         Man 瑞典人啊 = new Man();  
  127.                                                                                                                                                         瑞典人啊.国籍 = "瑞典";  
  128.                                                                                                                                                         瑞典人啊.宠物 = "狗";  
  129.                                                                                                                                                         瑞典人啊.房子 = 瑞典人房子;  
  130.                                                                                                                                                         瑞典人啊.香烟 = 瑞典人香烟;  
  131.                                                                                                                                                         瑞典人啊.房子次序 = 瑞典房子次序;  
  132.                                                                                                                                                         瑞典人啊.饮料 = 瑞典人饮料;  
  133.   
  134.                                                                                                                                                         Man 丹麦人啊 = new Man();  
  135.                                                                                                                                                         丹麦人啊.国籍 = "丹麦";  
  136.                                                                                                                                                         丹麦人啊.饮料 = "茶";  
  137.                                                                                                                                                         丹麦人啊.房子 = 丹麦人房子;  
  138.                                                                                                                                                         丹麦人啊.香烟 = 丹麦人香烟;  
  139.                                                                                                                                                         丹麦人啊.宠物 = 丹麦人宠物;  
  140.                                                                                                                                                         丹麦人啊.房子次序 = 丹麦人房子次序;  
  141.   
  142.                                                                                                                                                         Man 挪威人啊 = new Man();  
  143.                                                                                                                                                         挪威人啊.国籍 = "挪威";  
  144.                                                                                                                                                         挪威人啊.房子次序 = 1;  
  145.                                                                                                                                                         挪威人啊.房子 = 挪威人房子;  
  146.                                                                                                                                                         挪威人啊.香烟 = 挪威人香烟;  
  147.                                                                                                                                                         挪威人啊.宠物 = 挪威人宠物;  
  148.                                                                                                                                                         挪威人啊.饮料 = 挪威人饮料;  
  149.   
  150.                                                                                                                                                         Man 德国人啊 = new Man();  
  151.                                                                                                                                                         德国人啊.国籍 = "德国";  
  152.                                                                                                                                                         德国人啊.香烟 = "PRINCE";  
  153.                                                                                                                                                         德国人啊.房子 = 德国人房子;  
  154.                                                                                                                                                         德国人啊.宠物 = 德国人宠物;  
  155.                                                                                                                                                         德国人啊.房子次序 = 德国人房子次序;  
  156.                                                                                                                                                         德国人啊.饮料 = 德国人饮料;  
  157.   
  158.                                                                                                                                                         ManContainer 老外合集 = new ManContainer();  
  159.                                                                                                                                                         老外合集.丹麦人 = 丹麦人啊;  
  160.                                                                                                                                                         老外合集.德国人 = 德国人啊;  
  161.                                                                                                                                                         老外合集.挪威人 = 挪威人啊;  
  162.                                                                                                                                                         老外合集.瑞典人 = 瑞典人啊;  
  163.                                                                                                                                                         老外合集.英国人 = 英国人啊;  
  164.                                                                                                                                                         //验证对象是符合条件  
  165.                                                                                                                                                         if (Check1(老外合集) && Check2(老外合集) && Check3(老外合集) && Check4(老外合集) && Check5(老外合集) && Check6(老外合集) && Check7(老外合集) && Check8(老外合集) && Check9(老外合集))  
  166.                                                                                                                                                         {  
  167.                                                                                                                                                             Man FuHeTiaoJian= GetManByChongWu("鱼", 老外合集);  
  168.                                                                                                                                                             Console.WriteLine("养鱼的人是:" + FuHeTiaoJian.国籍 + "人,宠物是:" + FuHeTiaoJian.宠物 + " 房子是:" + FuHeTiaoJian.房子+"色的 抽的是:"+FuHeTiaoJian.香烟+"牌香烟 喝的是:"+FuHeTiaoJian.饮料+" 房子次序是:"+FuHeTiaoJian.房子次序);  
  169.                                                                                                                                                         }  
  170.                                                                                                                                                         #endregion  
  171.                                                                                                                                                     }  
  172.                                                                                                                                                 }  
  173.                                                                                                                                             }  
  174.                                                                                                                                         }  
  175.                                                                                                                                     }  
  176.                                                                                                                                 }  
  177.                                                                                                                             }  
  178.                                                                                                                         }  
  179.                                                                                                                     }  
  180.                                                                                                                 }  
  181.                                                                                                             }  
  182.                                                                                                         }  
  183.                                                                                                     }  
  184.                                                                                                 }  
  185.                                                                                             }  
  186.                                                                                         }  
  187.                                                                                     }  
  188.                                                                                 }  
  189.                                                                             }  
  190.                                                                         }  
  191.                                                                     }  
  192.                                                                 }  
  193.                                                             }  
  194.                                                         }  
  195.                                                     }  
  196.                                                 }  
  197.                                             }  
  198.                                         }  
  199.                                     }  
  200.                                 }  
  201.                             }  
  202.                         }  
  203.                     }  
  204.                 }  
  205.             }  
  206.             #endregion  
  207.   
  208.             System.Console.Write("执行完毕!");  
  209.             System.Console.Read();  
  210.         }  
  211.  
  212.         #region 判决方法  
  213.         /// <summary>  
  214.         /// 绿房子在白房子旁边,绿房子主人喝咖啡  
  215.         /// </summary>  
  216.         /// <param name="老外合集"></param>  
  217.         /// <returns></returns>  
  218.         static public bool Check1(ManContainer 一个老外)  
  219.         {  
  220.             Man temp1 = GetManByFangZi("绿", 一个老外);  
  221.             Man temp2 = GetManByFangZi("白", 一个老外);  
  222.   
  223.             return (Math.Abs(temp1.房子次序 - temp2.房子次序) == 1 && temp1.饮料 == "咖啡");  
  224.         }  
  225.         /// <summary>  
  226.         /// 抽"PALL MALL"烟的人养 "鸟";  
  227.         /// </summary>  
  228.         /// <param name="老外合集"></param>  
  229.         /// <returns></returns>  
  230.         static public bool Check2(ManContainer 一个老外)  
  231.         {  
  232.             Man temp1 = GetManByYan("PALL MALL", 一个老外);  
  233.             return (temp1.宠物=="鸟");  
  234.         }  
  235.         /// <summary>  
  236.         /// 黄房子 主人抽 "DUNHILL"烟;  
  237.         /// </summary>  
  238.         /// <param name="老外合集"></param>  
  239.         /// <returns></returns>  
  240.         static public bool Check3(ManContainer 一个老外)  
  241.         {  
  242.             Man temp1 = GetManByFangZi("黄", 一个老外);  
  243.             return (temp1.香烟 == "DUNHILL");  
  244.         }  
  245.         /// <summary>  
  246.         /// 未知4.饮料 = "牛奶";未知4.房子次序 = 3; 中间房子的人喝牛奶  
  247.         /// </summary>  
  248.         /// <param name="老外合集"></param>  
  249.         /// <returns></returns>  
  250.         static public bool Check4(ManContainer 一个老外)  
  251.         {  
  252.             Man temp1 = GetManByHouseIndex(3, 一个老外);  
  253.             return (temp1.饮料 == "牛奶");  
  254.         }  
  255.         /// <summary>  
  256.         /// 未知5 抽混合烟的人住在样猫的人旁边!  
  257.         /// </summary>  
  258.         /// <param name="老外合集"></param>  
  259.         /// <returns></returns>  
  260.         static public bool Check5(ManContainer 一个老外)  
  261.         {  
  262.             Man temp1 = GetManByYan("混合烟", 一个老外);  
  263.             Man temp2 = GetManByChongWu("猫", 一个老外);  
  264.             return (Math.Abs(temp1.房子次序 - temp2.房子次序) == 1);  
  265.         }  
  266.         /// <summary>  
  267.         /// 养马的人住在抽DUNHILL烟的旁边  
  268.         /// </summary>  
  269.         /// <param name="老外合集"></param>  
  270.         /// <returns></returns>  
  271.         static public bool Check6(ManContainer 一个老外)  
  272.         {  
  273.             Man temp1 = GetManByChongWu("马", 一个老外);  
  274.             Man temp2 = GetManByYan("DUNHILL", 一个老外);  
  275.             return (Math.Abs(temp1.房子次序 - temp2.房子次序) == 1);  
  276.         }  
  277.         /// <summary>  
  278.         /// 抽BLUEMASTER烟的人喝啤酒  
  279.         /// </summary>  
  280.         /// <param name="老外合集"></param>  
  281.         /// <returns></returns>  
  282.         static public bool Check7(ManContainer 一个老外)  
  283.         {  
  284.             Man temp1 = GetManByYan("BLUE MASTER", 一个老外);  
  285.             return (temp1.饮料 == "啤酒");  
  286.         }  
  287.         /// <summary>  
  288.         /// 挪威人住在蓝房子旁边则 蓝房子 位置为2  
  289.         /// </summary>  
  290.         /// <param name="老外合集"></param>  
  291.         /// <returns></returns>  
  292.         static public bool Check8(ManContainer 一个老外)  
  293.         {  
  294.             Man temp1 = GetManByFangZi("蓝", 一个老外);  
  295.             return (temp1.房子次序 == 2);  
  296.         }  
  297.         /// <summary>  
  298.         /// 混合烟的邻居喝矿泉水  
  299.         /// </summary>  
  300.         /// <param name="老外合集"></param>  
  301.         /// <returns></returns>  
  302.         static public bool Check9(ManContainer 一个老外)  
  303.         {  
  304.             Man temp1 = GetManByYan("混合烟", 一个老外);  
  305.             Man temp2 = GetManByYingLiao("矿泉水", 一个老外);  
  306.             return (Math.Abs(temp1.房子次序 - temp2.房子次序) == 1);  
  307.         }  
  308.         #endregion  
  309.  
  310.         #region 通过一定条件获取人员  
  311.         /// <summary>  
  312.         /// 通过房子序号获取房主  
  313.         /// </summary>  
  314.         /// <param name="index"></param>  
  315.         /// <param name="一个老外"></param>  
  316.         /// <returns></returns>  
  317.         static public Man GetManByHouseIndex(int index, ManContainer 一个老外)  
  318.         {  
  319.             if (一个老外.丹麦人.房子次序 == index)  
  320.             {  
  321.                 return 一个老外.丹麦人;  
  322.             }  
  323.             if (一个老外.德国人.房子次序 == index)  
  324.             {  
  325.                 return 一个老外.德国人;  
  326.             }  
  327.             if (一个老外.挪威人.房子次序 == index)  
  328.             {  
  329.                 return 一个老外.挪威人;  
  330.             }  
  331.             if (一个老外.瑞典人.房子次序 == index)  
  332.             {  
  333.                 return 一个老外.瑞典人;  
  334.             }  
  335.             if (一个老外.英国人.房子次序 == index)  
  336.             {  
  337.                 return 一个老外.英国人;  
  338.             }  
  339.             return null;  
  340.         }  
  341.   
  342.         /// <summary>  
  343.         /// 抽某种烟的人  
  344.         /// </summary>  
  345.         /// <param name="index"></param>  
  346.         /// <param name="一个老外"></param>  
  347.         /// <returns></returns>  
  348.         static public Man GetManByYan(string 烟名, ManContainer 一个老外)  
  349.         {  
  350.             if (一个老外.丹麦人.香烟 == 烟名)  
  351.             {  
  352.                 return 一个老外.丹麦人;  
  353.             }  
  354.             if (一个老外.德国人.香烟 == 烟名)  
  355.             {  
  356.                 return 一个老外.德国人;  
  357.             }  
  358.             if (一个老外.挪威人.香烟 == 烟名)  
  359.             {  
  360.                 return 一个老外.挪威人;  
  361.             }  
  362.             if (一个老外.瑞典人.香烟 == 烟名)  
  363.             {  
  364.                 return 一个老外.瑞典人;  
  365.             }  
  366.             if (一个老外.英国人.香烟 == 烟名)  
  367.             {  
  368.                 return 一个老外.英国人;  
  369.             }  
  370.             return null;  
  371.         }  
  372.   
  373.         /// <summary>  
  374.         /// 养某种宠物  
  375.         /// </summary>  
  376.         /// <param name="index"></param>  
  377.         /// <param name="一个老外"></param>  
  378.         /// <returns></returns>  
  379.         static public Man GetManByChongWu(string 宠物名, ManContainer 一个老外)  
  380.         {  
  381.             if (一个老外.丹麦人.宠物 == 宠物名)  
  382.             {  
  383.                 return 一个老外.丹麦人;  
  384.             }  
  385.             if (一个老外.德国人.宠物 == 宠物名)  
  386.             {  
  387.                 return 一个老外.德国人;  
  388.             }  
  389.             if (一个老外.挪威人.宠物 == 宠物名)  
  390.             {  
  391.                 return 一个老外.挪威人;  
  392.             }  
  393.             if (一个老外.瑞典人.宠物 == 宠物名)  
  394.             {  
  395.                 return 一个老外.瑞典人;  
  396.             }  
  397.             if (一个老外.英国人.宠物 == 宠物名)  
  398.             {  
  399.                 return 一个老外.英国人;  
  400.             }  
  401.             return null;  
  402.         }  
  403.   
  404.         /// <summary>  
  405.         /// 住某种颜色房子的  
  406.         /// </summary>  
  407.         /// <param name="index"></param>  
  408.         /// <param name="一个老外"></param>  
  409.         /// <returns></returns>  
  410.         static public Man GetManByFangZi(string 房子颜色, ManContainer 一个老外)  
  411.         {  
  412.             if (一个老外.丹麦人.房子 == 房子颜色)  
  413.             {  
  414.                 return 一个老外.丹麦人;  
  415.             }  
  416.             if (一个老外.德国人.房子 == 房子颜色)  
  417.             {  
  418.                 return 一个老外.德国人;  
  419.             }  
  420.             if (一个老外.挪威人.房子 == 房子颜色)  
  421.             {  
  422.                 return 一个老外.挪威人;  
  423.             }  
  424.             if (一个老外.瑞典人.房子 == 房子颜色)  
  425.             {  
  426.                 return 一个老外.瑞典人;  
  427.             }  
  428.             if (一个老外.英国人.房子 == 房子颜色)  
  429.             {  
  430.                 return 一个老外.英国人;  
  431.             }  
  432.             return null;  
  433.         }  
  434.   
  435.         /// <summary>  
  436.         /// 喝某种饮料的人  
  437.         /// </summary>  
  438.         /// <param name="index"></param>  
  439.         /// <param name="一个老外"></param>  
  440.         /// <returns></returns>  
  441.         static public Man GetManByYingLiao(string 饮料名称, ManContainer 一个老外)  
  442.         {  
  443.             if (一个老外.丹麦人.饮料 == 饮料名称)  
  444.             {  
  445.                 return 一个老外.丹麦人;  
  446.             }  
  447.             if (一个老外.德国人.饮料 == 饮料名称)  
  448.             {  
  449.                 return 一个老外.德国人;  
  450.             }  
  451.             if (一个老外.挪威人.饮料 == 饮料名称)  
  452.             {  
  453.                 return 一个老外.挪威人;  
  454.             }  
  455.             if (一个老外.瑞典人.饮料 == 饮料名称)  
  456.             {  
  457.                 return 一个老外.瑞典人;  
  458.             }  
  459.             if (一个老外.英国人.饮料 == 饮料名称)  
  460.             {  
  461.                 return 一个老外.英国人;  
  462.             }  
  463.             return null;  
  464.         }  
  465.         #endregion  
  466.     }  
  467.  
  468.     #region 对象模型  
  469.     //人员模型  
  470.     public class Man:Object  
  471.     {  
  472.         #region 属性  
  473.         private string guoji="";  
  474.         public string 国籍  
  475.         {  
  476.             get  
  477.             {  
  478.                 return guoji;  
  479.             }  
  480.             set  
  481.             {  
  482.                 guoji = value;  
  483.             }  
  484.         }  
  485.   
  486.   
  487.         private string yinliao = "";  
  488.         public string 饮料  
  489.         {  
  490.             get  
  491.             {  
  492.                 return yinliao;  
  493.             }  
  494.             set  
  495.             {  
  496.                 yinliao = value;  
  497.             }  
  498.         }  
  499.   
  500.   
  501.         private string xiangyan = "";  
  502.         public string 香烟  
  503.         {  
  504.             get  
  505.             {  
  506.                 return xiangyan;  
  507.             }  
  508.             set  
  509.             {  
  510.                 xiangyan = value;  
  511.             }  
  512.         }  
  513.   
  514.         private string chongwu = "";  
  515.         public string 宠物  
  516.         {  
  517.             get  
  518.             {  
  519.                 return chongwu;  
  520.             }  
  521.             set  
  522.             {  
  523.                 chongwu = value;  
  524.             }  
  525.         }  
  526.   
  527.         private string fangzi = "";  
  528.         public string 房子  
  529.         {  
  530.             get  
  531.             {  
  532.                 return fangzi;  
  533.             }  
  534.             set  
  535.             {  
  536.                 fangzi = value;  
  537.             }  
  538.         }  
  539.   
  540.         private int fangziindex=0;  
  541.         public int 房子次序  
  542.         {  
  543.             get  
  544.             {  
  545.                 return fangziindex;  
  546.             }  
  547.             set  
  548.             {  
  549.                 fangziindex = value;  
  550.             }  
  551.         }  
  552.         #endregion  
  553.         #region 方法  
  554.         public override bool Equals(object obj)  
  555.         {  
  556.             return base.Equals(obj);  
  557.         }  
  558.         public void Copy(Man a)  
  559.         {  
  560.             this.国籍 = a.国籍;  
  561.             this.香烟 = a.香烟;  
  562.             this.饮料 = a.饮料;  
  563.             this.宠物 = a.宠物;  
  564.             this.房子 = a.房子;  
  565.         }  
  566.         #endregion  
  567.     }  
  568.     //业务模型,为结果的一种可能性  
  569.     public class ManContainer  
  570.     {  
  571.         public Man 英国人;  
  572.         public Man 瑞典人;  
  573.         public Man 丹麦人;  
  574.         public Man 挪威人;  
  575.         public Man 德国人;  
  576.     }  
  577.     #endregion  
  578. }  

for(int j=0;j<5;j++,answer[j,1]=ALL[j,i1]);
for (i2=1;i2<=120;i2++) ///人种
{

 

for(int j=0;j<5;j++,answer[j,2]=ALL[j,i2]);
/// 9 、挪威人住第一间房子
if (ALL[1,i2]!=1)continue;
///1、 英国人住在红房子里
///
if (find(1,4)!=find(2,2))continue;

算法2(中软一个同事用C++写的 本人借用到C# ):

/// 4 、绿房子在白房子左边
///
if (find(1,5)>find(1,3))continue;

 

for (i3=1;i3<=120;i3++) ///烟
{

using System;

for(int j=0;j<5;j++,answer[j,3]=ALL[j,i3]);
/// 13、 德国人抽PRINCE烟
///
if(find(2,3)!=find(3,2))continue;
/// 7 、黄房子主人抽DUNHILL烟
///
if(find(1,1)!=find(3,1))continue;

using System.Collections.Generic;

for (i4=1;i4<=120;i4++) ///饮料
{

using System.Text;

for(int j=0;j<5;j++,answer[j,4]=ALL[j,i4]);
/// 8 、住在中间那间房子的人喝牛奶
///
if(ALL[3,i4]!=4)continue;

 

/// 5 、绿房子主人喝咖啡
///
if (find(1,5)!=find(4,1))continue;

namespace AiYinSiTan2

/// 3 、丹麦人喝茶
///
if(find(2,4)!=find(4,3))continue;

{

/// 15 、抽混合烟的人的邻居喝矿泉水

   struct House{

if(Math.Abs(find(3,3)-find(4,2))!=1)continue;
/// 12 、抽BLUE MASTER烟的人喝啤酒
///

       public string nation;

if(find(3,5)!=find(4,5))continue;

       public string color;

for (i5=1;i5<=120;i5++) ///宠物
{

       public string pet;

for(int j=0;j<5;j++,answer[j,5]=ALL[j,i5]);
/// 10 、抽混合烟的人住在养鱼人的旁边
///
if(Math.Abs(find(3,3)-find(5,1))!=1)continue;

       public string drink;

/// 2 、瑞典人养了一条狗
///
if(find(2,5)!=find(5,5))continue;
/// 6 、抽PALL MALL烟的人养了一只鸟
///
if(find(3,4)!=find(5,4))continue;
/// 11 、养马人住在DUNHILL烟的人旁边
///

       public string cigarette;

if(Math.Abs(find(5,3)-find(3,1))!=1)continue;
///
///能活到这里的data,当然是答案喽
///
write_answer();

           };

}

   class Program

}
}

    {

}
}
}

       

///
/// 非常典型的用递归实现排列组合算法。
///
public void p()
{
int nCount,nJudge,key;
nLevel++;
if(nLevel>5)
{
writeall();///有一种排列就写到All数组里
nLevel--;
return;
}

       static void Main(string[] args)

for(nCount=1;nCount<=5;nCount++)
{
key=0;
for(nJudge=0;nJudge<=nLevel-1;nJudge++)
if(nCount==List[nJudge])
{
key=1;
break;
}

       {

if(key==0)
{
List[nLevel]=nCount;
p();
}
}
nLevel--;
}

           string[] Title = new string[5] { "国籍", "颜色", "宠物", "饮料", "香烟" };

///
/// 写入all数组
///

           House house0= new House();

void writeall()
{
int i;
for (i=1;i<=5;i++)
{
ALL[i,count]=List[i];
}
count++;
}

           House house1 = new House();

int find(int i,int j)
{

           House house2 = new House();

int k;
for(k=0;k<=5;k++)
{
if (answer[k,i]==j)
{
return k;
}
}
return -1;
}

           House house3 = new House();

///
/// 将答案打印出来
///
void write_answer()
{

           House house4 = new House();

for (int i = 1;i<=5;i++)
{
for(int j=1 ;j<=5;j++)
{
Console.Write(data[i-1,answer[j,i]-1]+",");

           House[] HouseMan = new House[5] { new House(), new House(), new House(),new House(), new House() };//房子从左到右编号

}
Console.WriteLine();
}
Console.WriteLine();
}
}
}
说明:程序使用C#,在Microsoft Visual Studio.net下编译执行通过。如果你没有Microsoft Visual C# 需要安装Microsoft(r) .NET Framework SDK ,把上述代码保存到ayst.cs,然后在命令行模式下执行csc ayst.cs ,然后执行ayst.exe也可以。这个程序是很久之前写的。当时只是为了得到答案,所以程序写的比较乱。让同行见笑了。以下是程序的运行结果(答案一总7种,没想到吧):
黄房子,蓝房子,红房子,绿房子,白房子,
挪威人,丹麦人,英国人,德国人,瑞典人,
DUNHILL,混合烟,PALL MALL,PRINCE,BLUE MASTER,
矿泉水,茶,牛奶,咖 啡, 啤酒 ,
鱼,马,鸟, 恐龙,狗,

           HouseMan[0] = house0;

绿房子,蓝房子,黄房子,红房子,白房子,
挪威人,德国人,瑞典人,英国人,丹麦人,
混合烟,PRINCE,DUNHILL,BLUE MASTER,PALL MALL,
咖 啡,矿泉水,牛奶, 啤酒 ,茶,
恐龙,鱼,狗,马,鸟,

           HouseMan[1] = house1;

绿房子,蓝房子,白房子,黄房子,红房子,
挪威人,德国人,瑞典人,丹麦人,英国人,
PALL MALL,PRINCE,混合烟,DUNHILL,BLUE MASTER,
咖 啡,矿泉水,牛奶,茶, 啤酒 ,
鸟,鱼,狗, 恐龙,马,

           HouseMan[2] = house2;

绿房子,蓝房子,白房子,黄房子,红房子,
挪威人,德国人,瑞典人,丹麦人,英国人,
PALL MALL,PRINCE,混合烟,DUNHILL,BLUE MASTER,
咖 啡,矿泉水,牛奶,茶, 啤酒 ,
鸟, 恐龙,狗,鱼,马,

           HouseMan[3] = house3;

绿房子,蓝房子,白房子,红房子,黄房子,
挪威人,德国人,瑞典人,英国人,丹麦人,
PALL MALL,PRINCE,混合烟,BLUE MASTER,DUNHILL,
咖 啡,矿泉水,牛奶, 啤酒 ,茶,
鸟,鱼,狗,马, 恐龙,

           HouseMan[4] = house4;

绿房子,蓝房子,红房子,黄房子,白房子,
挪威人,德国人,英国人,丹麦人,瑞典人,
PALL MALL,PRINCE,混合烟,DUNHILL,BLUE MASTER,
咖 啡,矿泉水,牛奶,茶, 啤酒 ,
鸟,鱼,马, 恐龙,狗,

 

绿房子,蓝房子,红房子,黄房子,白房子,
挪威人,德国人,英国人,丹麦人,瑞典人,
PALL MALL,PRINCE,混合烟,DUNHILL,BLUE MASTER,
咖 啡,矿泉水,牛奶,茶, 啤酒 ,
鸟, 恐龙,马,鱼,狗,

           HouseMan[0].nation = "挪威";//挪威人住在第一个房子里面

           HouseMan[1].color = "蓝色";//挪威人和住在蓝房子的人相邻,即蓝房子是第2个房子

           HouseMan[2].drink = "牛奶";// 住在中间那个房子里的人喝牛奶

           for (int e = 1; e < 5; e++)   //表示英国人的房子序号

           {

                for (int r = 1; r < 5;r++)//表示瑞典人的房子序号

                {

                    for (int d = 1; d < 5;d++)//表示丹麦人的房子序号

                    {

                        for (int g = 0; g <5; g++)//表示绿房子的序号

                        {

                            for (int p = 0; p< 5; p++)//表示抽Pall Mall牌香烟的人的房子序号

                            {

                                for (int y = 0;y < 5; y++)//表示黄色房子的序号

                                {

                                    for (intb=0; b<5; b++)//表示喝啤酒人的房子序号

                                    {

                                        for (int h =0; h < 5; h++)//表示养马的人的房子序号

                                        {

                                            for(int cat = 0; cat < 5; cat++)//表示养猫的人的房子序号

                                            {

                                               int Germany = 10 - 0 - e

  • r - d;   //表示德国人的房子序号,德国人抽Prince牌香烟;

                                               int Blends = 10 - p - y - b - Germany;//表示抽Blends牌香烟的人的房子序号

                                                int white = 10 - 1 - e - g -y; //表示白房子的序号

                                               int water = 10 - 2 - d - g - b; //表示喝矿泉水的人的房子序号

                                               int fish = 10 - r - p - h

  • cat;//表示养鱼的人的房子序号

 

                                               bool A1 = (e != 1);    //英国人住在红色的房子里;根据房子和国家判断

                                               bool A2 = (r != e);    //瑞典人养狗作为宠物;根据国家和宠物判断

                                               bool A3 = (d != e && d != r && d != 2);//丹麦人喝茶;根据国家和饮料判断

                                               bool A4 = (g != 1 && g != 2 && g != e && g !=d);//绿房子的主人喝咖啡;根据颜色和饮料判断

                                               bool A5 = (p != r);    //抽Pall Mall牌香烟的人养鸟;根据香烟和宠物判断

                                               bool A6 = (y != e && y != 1 && y != g && y !=p);//黄色房子里的人抽Dunhill牌香烟;根据颜色和香烟判断

                                               bool A7 = (b != 2 && b != d && b != g && b != p&& b != y);//抽BlueMaster牌香烟的人喝啤酒;根据香烟和饮料判断

                                               bool A8 = (h != r && h != p && (h == y + 1 || h == y -1));//养马的人和抽Dunhill牌香烟的人相邻,根据香烟和宠物判断

                                               bool A9 = (white == g + 1);    //绿房子紧挨着白房子,在白房子的左边;

                                               bool A0 = (cat == Blends

  • 1 || cat == Blends + 1);//Blends牌香烟的人和养猫的人相邻;

                                               bool A11 = (water == Blends - 1 || water == Blends + 1);//抽Blends牌香烟的人和喝矿泉水的人相邻

 

                                               if (A1 && A2 && A3 && A4 && A5&& A6 && A7 && A8 && A9 && A0&& A11)

                                               {//把满足条件的序号填入结构数组

                                                   HouseMan[e].nation = "英国";

                                                   HouseMan[e].color = "红色";

                                                   HouseMan[r].nation = "瑞典";

                                                   HouseMan[r].pet = "狗";

                                                    HouseMan[d].nation= "丹麦";

                                                   HouseMan[d].drink = "茶";

                                                   HouseMan[g].color = "绿色";

                                                    HouseMan[g].drink ="咖啡";

                                                   HouseMan[p].cigarette = "Pall Mall";

                                                   HouseMan[p].pet = "鸟";

                                                    HouseMan[y].color = "黄色";

                                                   HouseMan[y].cigarette = "Dunhill";

                                                   HouseMan[b].cigarette = "BlueMaster";

                                                    HouseMan[b].drink = "啤酒";

                                                   HouseMan[h].pet = "马";

                                                   HouseMan[Germany].nation = "德国";

                                                   HouseMan[Germany].cigarette ="Prince";

                                                   HouseMan[Blends].cigarette = "Blends";

                                                   HouseMan[white].color = "白色";

                                                    HouseMan[water].drink = "矿泉水";

                                                   HouseMan[cat].pet = "猫";

                                                   HouseMan[fish].pet = "鱼";

                                                   Console.WriteLine("-------------------符合条件的方案----------------------------");

                                                   for (int i = 0; i < 5; i++)

                                                   {

                                                        

                                                       Console.WriteLine(HouseMan[i].nation);

                                                       Console.WriteLine("------------------------------------");

                                                        Console.WriteLine(HouseMan[i].cigarette);

                                                       Console.WriteLine(HouseMan[i].color);

                                                       Console.WriteLine(HouseMan[i].drink);

                                                       Console.WriteLine(HouseMan[i].pet);

                                                       Console.WriteLine("----------------------------------------------------");

                                                    }

 

                                               }

                                            }

 

                                        }

 

                                    }

 

                                }

 

                            }

                        }

 

                    }

 

                }

 

           }

           Console.Read();

       }

    }

 

     

 

//end:

//   for (int i=0; i<5; i++)

//       cout << Title << "t";

//   cout << endl << endl;

   

//   for (int i=0; i<5; i++)

//   {

//       cout << House.nation << "t";

//       cout << House.color << "t";

//       cout << House.pet << "t";

//       cout << House.drink << "t";

//       cout << House.cigarette << "t";

//       cout << endl;

//   }

 

}

 

有钱的朋友上我的CSDN去奉献点分吧,极品资源很多哦!:

有钱的朋友上我的CSDN去奉献点分吧,极品资源很多哦!: