码迷,mamicode.com
首页 > 其他好文 > 详细

UVA1587 BOX盒子

时间:2015-04-22 23:51:29      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

给定矩形的长和宽,判断它们能否构成长方体的六个面

 1 #include<iostream>
 2 #include<string>
 3 using namespace std;
 4 int t;
 5 void change(int a[7][3])                   //输入两个数字,按顺序:小,大;排列。
 6 {
 7     for (int k = 1; k <= 6; k++)
 8     if (a[k][1] > a[k][2])
 9     {
10         t = a[k][1];
11         a[k][1] = a[k][2];
12         a[k][2] = t;
13     }
14 }
15 int main()
16 {
17     int a[7][3];
18     for (int i = 1; i <= 6; i++)
19     for (int ii = 1; ii <= 2; ii++)
20         cin >> a[i][ii];
21     change(a);
22     int coincide[7] = { 0 };
23     int square = 0;
24     int side[7][3] = { 0 };
25     for (int k = 1; k <= 6; k++)
26     {
27         for (int kk = 1; kk <= 6; kk++)
28         {
29             if (a[k][1] == a[kk][1] && a[k][2] == a[kk][2] && k != kk)     //两面完全相等
30                 coincide[k]++;                  
31             for (int j = 1; j <= 2; j++)
32             {
33                 if (a[k][1] == a[kk][j] && k != kk)
34                     side[k][1]++;
35                 if (a[k][2] == a[kk][j] && k != kk)
36                     side[k][2]++;
37             }
38         }
39         if (a[k][1] == a[k][2])
40             square++;
41     }
42     int judge = 1;     //
43     if (square == 0 && coincide[0] == 5)         ////
44         judge = 0;
45     if (square > 2 && side[0][0] != 10)  //square大于2即为正方形。出去自身所在边,side应为10
46         judge = 0;
47     for (int h = 1; h <= 6; h++)
48     {
49         if (coincide[h] == 0)   //没有面面相同
50 
51         {
52             judge = 0; break;
53         }
54 
55         for (int j = 1; j <= 2; j++)
56         if (side[h][j] < 3)   //自己算一条,总共四条,应该为3。
57         {
58             judge = 0;
59             break;
60         }
61     }
62     if (judge == 0)  cout << "sorry!wrong!";
63     else cout << "possible";
64     system("pause");
65     return 0;
66 }

 

UVA1587 BOX盒子

标签:

原文地址:http://www.cnblogs.com/ghost-song/p/4448835.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!