Uva1587 Box, uva1587box
Ivan works at a factory that produces heavy machinery. he has a simple job -- he knocks up wooden boxes of different sizes to pack machinery for delivery to the MERs. each box is a rectangular parallelepiped. ivan uses six rectangular wooden pallets to make a box. each pallet is used for one side of the box.
Joe delivers pallets for Ivan. joe is not very smart and often makes mistakes -- he brings Ivan pallets that do not fit together to make a box. but Joe does not trust Ivan. it always takes a lot of time to explain Joe that he has made a mistake. fortunately, Joe adores everything related to computers and sincerely believes that computers never make mistakes. ivan has decided to use this for his own advantage. ivan asks you to write a program that given sizes of six rectangular pallets tells whether it is possible to make a box out of them.
Input
Input file contains several test cases. Each of them consists of six lines. Each line describes one pallet and contains two integer numbersWAndH(1W,H10 000) -- width and height of the pallet in millimeters respectively.
Output
For each test case, print one output line. Write a single word'POSSIBLE'To the output file if it is possible to make a box using six given pallets for its sides. Write a single word'IMPOSSIBLE'If it is not possible to do so.
Sample Input
1345 25842584 6832584 1345683 1345683 13452584 6831234 45671234 45674567 43214322 45674321 12344321 1234
Sample Output
POSSIBLEIMPOSSIBLE
Hope that every time the Code is improved.
AC code:
1 # include <iostream> 2 3 using namespace std; 4 5 6 struct Box 7 {8 int a, B; 9} box [6]; 10 11 12 void Swap (int *, int *); 13 void Sort (); 14 int Judge (); 15 16 17 int main () 18 {19 while (cin> box [0]. a> box [0]. b) 20 {21 if (box [0]. a <box [0]. b) 22 Swap (& box [0]. a, & box [0]. b); 23 for (int I = 1; I <6; I ++) 24 {25 cin> box [I]. a> box [I]. b; 26 if (box [I]. a <box [I]. b) 27 Swap (& box [I]. a, & box [I]. b); 28} 29 Sort (); 30 if (Judge () 31 cout <"POSSIBLE" <endl; 32 else33 cout <"IMPOSSIBLE" <endl; 34} 35 return 0; 36} 37 void Swap (int * p, int * q) 38 {39 int r; 40 r = * p; 41 * p = * q; 42 * q = r; 43} 44 45 void Sort () 46 {47 struct Box c; 48 for (int I = 1; I <6; I ++) 49 for (int j = 0; j <6-i; j ++) 50 {51 if (box [j]. a <box [j + 1]. a) 52 {53 c = box [j]; 54 box [j] = box [j + 1]; 55 box [j + 1] = c; 56} 57} 58 for (int I = 1; I <6; I ++) 59 for (int j = 0; j <6-i; j ++) 60 {61 if (box [j]. B <box [j + 1]. B & box [j]. a = box [j + 1]. a) 62 {63 c = box [j]; 64 box [j] = box [j + 1]; 65 box [j + 1] = c; 66} 67} 68} 69 70 int Judge () 71 {72 if (box [0]. a = box [1]. a & box [1]. a = box [2]. a & box [2]. a = box [3]. a) 73 if (box [0]. B = box [1]. B & box [1]. B = box [4]. a & box [4]. a = box [5]. a) 74 if (box [2]. B = box [3]. B & box [3]. B = box [4]. B & box [4]. B = box [5]. b) 75 return 1; 76 return 0; 77}View Code