Einstein is this riddle in the 20th century, the topic is like this:
1. On a street, there are 5 houses, sprayed 5 colors. 2, people living in different nationalities in each room. 3, everyone drinks different drinks, draws different brands of cigarettes, and raises different pets.
prompt:
1, British living in red house 2, Swedish raising dog 3, Danish drinking tea 4, green house on the left side of the white house 5, green house owner drink coffee 6, pumping a Pall Mall cigarette bird 7, yellow house owner pumping Dunhill cigarette 8, people living in the middle house drink milk 9, Norwegian people living in the first room 10, people smashing the Blends cigarette stay in the next wall 11, people living in tipping Dunhill cigarette next door 12 People who smoke Blue Master drink beer 13, German smokes Prince cigarettes 14, Norwegians live in blue houses 15, people who smoke Blends cigarettes have a drink of water neighbors
The question is: Who rasted fish?
I use C to solve it this is a combination problem. Detailed explanation in the code: /// Einstein's riddle ///// writed by Kevin ///////////////////////////////////////////////////////////////////////////////////////// 's. H> #include
INT A1, A2, A3, A4; / / USBE INT B1, B2, B3, B4; / / / RTIgUCTION INT C1, C2, C3, C4, C5; ///
INT I, J; INT count = 0;
Char country [5] [15] = {"Norwegians", "Sweden", "Danish", "British", "German"}; char color [5] [15] = {"Red", "Green", "White", "Blue", "Yellow"}; Char Drink [5] [15] = {"Beer", "Water", "Coffee", "Tea", "Milk"}; char PETS [5] [15] = {"Cat", "Dog", "Bird", "Fish", "Ma"}; Char Tobaco [5] [15] = {"Prince", "Pall Mall", " Dunhill "," Blends "," Blue Master "};
Char Result [25] [15]; /// Record a combination result sequence
Void subfeek () {Int flagcolor1, flagcolor2, i; British live in Red House if (! (Strs (Result [10], "British") &&! (Result [11], "Red") ))); ELSE IF (! (Result [15], "British") &&! (Strcmp (result [16], "red"))); else if (! (! " "British")) &&! (Result [21], "Red"))))); Else Return; /// Green house on the left side of white house (i = 0; i <25; i ) {= ! (STRCMP (Result [i], "green")))) FlagColor1 = I; if (! (strcmp (Result [i], "white"))) flagcolor2 = i;} if (flagcolor1> flagcolor2) return; / // Sweden raised a dog for (i = 5; I <21; i = 5) {if (! (! ")) STRCPY (Result [i 3], "Dog");} /// Danish drinking tea if (! (Strcmp (Result [5), "Danish") &&! (StrCMP (Result [7], "Tea"))); Else IF ! (STRCMP (Result [10], "Danish") &&! (StrCMP (Result [12], "Tea"))); Else IF (! (! ")) &&! (Result [17], "Tea"))))))))))))); Else IF (! (Result [20], "Danish") &&! (StrCMP (Result [22], "Tea")) ); Else Return; // Green house owner drinks coffee if (! (Result [1], "Green") &&! (Strs (Result [2], "Coffee")); else IF (Strcmp (Result [16], "Green") &&! (Strcmp (Result [17], "Coffee")))); Else IF (! (! (result [21], "green") && (Strcmp) (Result [22], " Coffee ")))); Else Return; /// German smokes Prince smoke for (i = 5; i <21; i = 5) {if (! (Strcmp (result [i]," German ")) STRCPY (Result ");} ///-Huang House master smokes Dunhill smoke for (i = 1; i <21; i = 5) {if (! (! (result [i], "Yellow")))) IF (! (Result [i 3], ")))) STRCPY (Result [i 3]," Dunhill "); else return;} ///-horn people live Dunhill's smoke side IF (! (Strcmp (result [4], "dunhill"
))))))) Strcpy (Result [8], "horse"); else return; if (! (Strcmp (result [24], "dunhill")) IF (! (Result [18], "")))) STRCPY (Result [18], "Horse"); else return; for (i = 9; i <20; i ) {if (! (! (! (Strcmp) (Result [I], "Dunhill"))))) {if (! (strcmp (result [i-6], "))) STRCPY (Result [i-6]," Ma "); Else IF (! STRCMP (Result [i 4], ""))) STRCPY (Result [i 4], "Horse"); Else Return;}} /// Summary BLUE MASTER Smoke Drinks Beer for (i = 2; i <23; i ) {if (! (strcmp (result [i], "beer"))) STRCPY (Result [i 2], "Blue Master");} /// 抽 抽 抽 人 人 喝Water IF (! (Result [2], "Water"))))))))))))))))))))))); Else Return; for (i = 7; i <18; i ) {if (! (strcmp (result [i], "water"))) {if (! (strcmp (result [i-3], "))) STRCPY Result [I-3], "Blends"); ELSE IF (! (Result [i 7], ")))) STRCPY (Result [i 7]," Blends "); else return;}} IF (! (result [22], "water")))))))))))))); else return; / Pumping Blends lives next to the cats (! (Strcmp (result [4], "blends") ))))) STRCPY (RESULT [8], "Cat"); Else Return; For (i = 9; i <20; i ) {IF (! StrCMP (Result [i], "Blends")))))) {if (! (strcmp (Result [i-6], "))) STRCPY (Result [I-6]," Cat "); Else IF (! (Result [i 4], ""))) STRCPY (Result [i 4], "Cat"); Else Return;}} IF (! (strcmp (result [24], "blends")) ) IF (! (Result [18], "))) STRCPY (Result [18]," Cat "); Else Return
/// Summit the Pall Mall smoke raised a bird for (i = 4; i <25; i = 5) {if (! (! "(Result [i],")) &&! (Result [I-1], ""))) {structure (Result [i], "paall mall"); strcpy (Result [i-1], "bird"); Break;}} /// fishing ^ _ ^ For (i = 3; i <24; i = 5) {if (! (StrCMP (result [i], "))) STRCPY (Result [i]," fish ");} print the Result !!! j = 0; for (i = 0; i <25; i ) {if (! (! ")) J ;} if (j == 0) {Printf "A correct combination: / n"); for (i = 0; i <25; i = 5) {printf ("% s in% s house to drink% S / N" , Result [i 1], Result [i], result [i 2], Result [i 3], Result [i 4]);} PrintF ("/ n");} print the result !! ! /}
Void main () {Printf ("Einstein's Hints: / N" "1.) The Swede Keeps Dogs As Pets / N" "3.) The Dane Drinks TEA / n "" 4.) The Green House is on the left of the white house / n "" 5.) The Green House's Owner Drinks coffee / n "6.) The Person WHO Smoke Mall Mall Rears Birds / N" "7 .) THE OWNHILL / N "" 8.) The man living in the center house drinks milk / n "" 9.) The norwegian lives in the first house / n "" 10.) The man who Smokees Blends next to the one who keeps cats / n "" 11.) The man who keeps Horses Lives next to the man who smokehill / n "12.) The Owner Who SmokeS Bluemaster Drinks Beer / N" 13. ) The german smokes prince / n "" 14.) The Norweg Ian lives next to the blue house / n "" 15.) The man who smokers Blends Water / n / n "" The Question IS: WHO OWNS THE FISH? / N "); // Big cycle start Drink // STRCPY (Result [12], Drink [4]); middleman drinks milk for (A1 = 0; A1 <4; A1 ) {struct [2], drink [A1]); for (A2 = 0 A2 <4; A2 ) {IF (A1 == A2) Continue; Else Strpy (Result [7], Drink [A2]); for (A3 = 0; A3 <4; A3 ) {IF (((A3 ==) A2) || (A3 == A1)) Continue; Else Strcpy (Result [17], DRINK [A3]); for (A4 = 0; A4 <4; A4
) {IF ((A4 == A3) || (A4 == A2) || (A4 == A1)) Continue; Else Strcpy (Result [22], Drink [A4]); / Country Strcpy (Result [0 ], country [0]); / The first person is Norwegian people for (B1 = 1; B1 <5; B1 ) {structure (Result [5], country [b1]); for (b2 = 1; b2 < 5; B2 ) {IF (B2 == B1) Continue; Else Strcpy (Result [10], Country [B2]); for (b3 = 1; b3 <5; b3 ) {IF ((b3 == b2) | | (B3 == B1)) Continue; Else Strcpy (Result [15], Country [b3]); for (B4 = 1; B4 <5; B4 ) {IF ((b4 == b1) || (b4 = = B2) || (B4 == B3)) Continue; Else Strcpy (Result [20], Country [B4]); / House color C2 = 3; for (C1 = 0; C1 <5; C1 ) {IF ( C2 == C1) Continue; else {structure (Result [1], color [c1]); struct [6], color [c2]);} for (C3 = 0; C3 <5; C3 ) {IF ((C3 == C2) || (C3 == C1)) CONTINUE; Else Strcpy (Resu LT [11], Color [C3]); for (C4 = 0; C4 <5; C4 ) {IF ((C4 == C1) || (C4 == C2) | (C4 == C3)) Continue Else Strcpy (Result [16], Color [C4]); for (C5 = 0; C5 <5; C5 ) {IF ((C5 == C1) || (C5 == C2) || (C5 == C3) || (C5 == C4)) Continue; Else {STRCPY (Result [21], Color [C5]); SUBFEEK ();