程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> uva1587 Box,uva1587box

uva1587 Box,uva1587box

編輯:關於C語言

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 customers. 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.

\epsfbox{p3214.eps}

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 numbersw and h ( 1$ \le$wh$ \le$10 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 2584
2584 683
2584 1345
683 1345
683 1345
2584 683
1234 4567
1234 4567
4567 4321
4322 4567
4321 1234
4321 1234

Sample Output 

POSSIBLE
IMPOSSIBLE

希望每次代碼都有進步。
AC代碼:
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 else 33 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

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved