Posted from the German Logic Reflections on Berlin in 1981

xiaoxiao2021-03-06  110

1 has five five colors of the house

2 The owner of each house is different

3 These five people only drink only one drink, only a brand of cigarettes, only to raise a pet

4 No one has the same pet, take the same brand of cigarettes, drink the same drink

prompt:

1, the British live in the red house

2, Sweden raised a dog

3, Danish drinking tea

4, green house on the left side of the white house

5, green house owner drink coffee

6, people who smoke Pall Mall to raise a bird

7, Huang House master smoke Dunhill smoke

8, people living in the middle of the house drink milk

9, Norwegian people live in the first house

10, people who smoke smoke live next to the fish

11, the horses live next to people in Dunhill smoke

12, people who smoke Blue Master smoke drink beer

13, German picking Prince smoke

14, Norwegian live next to the blue house

15. People who smoke mixed smoke drink mineral water

The question is: Who rasted fish? Using system;

Namespace Netsafe.math

{

Public class alyst

{

///

/// All elements in the problem

///

String [,] DATA = {{"Huang House", "Blue House", "White House", "Red House", "Green House"}

{"Norwegian", "British", "German", "Danish", "Sweden"}

{"Dunhill", "Prince", "Mixed Smoke", "Pall Mall", "Blue Master"},

{"Coffee", "Mine Water", "Tea", "Milk", "Beer"}

{"Fish", "Dinosaur", "Ma", "Bird", "Dog"}}

///

/// Answer is used to store answers

///

Int [,] answer = new int rt [6, 6];

int [,] all = new int rt [6,122];

INT count = 1;

INT NLEVEL = 0;

int [] list = new int [6];

Public static void main (string [] args)

{

Aynst c = new ays ();

C.P (); /// Generate full alignment to all

C.Run ();

Console.read (); /// According to any key operation

}

Void Run ()

{

INT I1, I2, I3, I4, I5; // Optimize the program through logical condition sequence

For (i1 = 1; i1 <= 120; i1 ) // 房

{

/// 9, Norwegian people live in the first house

/// 14, Norwegian lives next to the blue house

/// Do not meet the conditions

///

IF (all [2, i1]! = 2) Continue;

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, Norwegian people live in the first house

IF (All [1, I2]! = 1) Continue;

/// 1, the British live in the red house

///

IF (Find (1, 4)! = Find (2, 2)).

/// 4, the green house is on the left side of the white house /////

IF (Find (1, 5)> Find (1, 3)).

For (i3 = 1; i3 <= 120; i3 ) / / / smoke

{

For (int J = 0; J <5; J , Answer [J, 3] = All [J, I3]);

/// 13, German picks Prince smoke

///

IF (Find (2, 3)! = Find (3, 2)) Continue;

/// 7, Huang House owner smokes Dunhill smoke

///

IF (Find (1, 1)! = Find (3, 1)) Continue;

For (i4 = 1; i4 <= 120; i4 ) /// drink

{

For (int J = 0; J <5; J , Answer [J, 4] = All [J, I4]);

/// 8, people living in the middle of the house drink milk

///

IF (All [3, I4]! = 4) Continue;

/// 5, green house owner drink coffee

///

IF (Find (1,5)! = Find (4, 1)) Continue;

/// 3, Danish drink tea

///

IF (Find (2, 4)! = Find (4, 3)) Continue;

/// 15, the neighbors of the smoke, drinking mineral water

IF (Math.Abs ​​(Find (3, 3) -find (4, 2))! = 1) Continue;

/// 12, people who take Blue Master smoke drink beer

///

IF (Find (3, 5)! = Find (4, 5)) Continue;

For (i5 = 1; i5 <= 120; i5 ) // pet

{

For (int J = 0; J <5; J , Answer [J, 5] = All [J, I5]);

/// 10, people who smoke smoke live next to the fish

///

IF (Math.Abs ​​(Find (3, 3) -find (5, 1))! = 1) Continue;

/// 2, Sweden raised a dog

///

IF (Find (2, 5)! = Find (5, 5)) Continue;

/// 6, people who pumping the Pall Mall smoke have raised a bird.

///

IF (Find (3, 4)! = Find (5, 4)) Continue;

/// 11, the harmaman lives next to people in Dunhill smoke

///

IF (Math.Abs ​​(Find (5, 3) -find (3, 1))! = 1) Continue;

///

/// can live to Data, of course, the answer

///

Write_answer ();

}

}

}

}

}

}

///

/// Very typical use of recursive implementation arrangement combination algorithm.

///

Public void p ()

{

Int ncount, njudge, key;

NLEVEL ;

IF (Nlevel> 5)

{

WriteAll (); /// has a arrangement to write to all arrays

NLEVEL -

Return;

}

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 -

}

///

/// Write an ALL array

///

Void WriteAll ()

{

INT I;

For (i = 1; i <= 5; i )

{

All [i, count] = list [i];

}

COUNT ;

}

INT Find (Int i, int J)

{

INT K;

For (k = 0; k <= 5; k )

{

IF (Answer [k, i] == j)

{

Return K;

}

}

Return -1;

}

///

/// Print the answer out

///

Void Write_answer ()

{

For (INT i = 1; i <= 5; i )

{

For (int J = 1; j <= 5; J )

{

Console.write (DATA [I-1, Answer [J, I] -1] ",")

}

Console.writeLine ();

}

Console.writeLine ();

}

}

}

Description: The program uses the current most popular C # language, compiling under Microsoft Visual Studio.net. If you don't have Microsoft Visual C # Need to install Microsoft (r) .NET Framework SDK, save the code to AYST.CS, then execute CSC ayst.cs in command line mode, and then perform Ayst.exe.

转载请注明原文地址:https://www.9cbs.com/read-102824.html

New Post(0)