iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 30
1
自我挑戰組

一日一CPE系列 第 30

[Day30]11455: Behold My Quadrangle

考題日期:2018/05/29
題號:11455
星等:1
語言:C++


題目:
https://ithelp.ithome.com.tw/upload/images/20191015/201209377BmLiQRuZj.png


題意:
判斷輸入的四個邊可否組成正方形、矩形、四邊形,或者甚麼都不成組成。


程式:

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
   int test,a[4];
   cin>>test;
   while(test--)
   {
       for(int i = 0 ; i < 4 ; i++)
       {
           cin>>a[i];
       }
       sort(a,a+4);
       if(a[0] == a[1] && a[1] == a[2] && a[2] == a[3])
            cout<<"square"<<endl;
       else if(a[0] == a[1] && a[2] == a[3])
            cout<<"rectangle"<<endl;
       else if(a[0]+a[1]+a[2]>a[3])
            cout<<"quadrangle"<<endl;
       else
            cout<<"banana"<<endl;
   }
   return 0;
}

測資:
https://ithelp.ithome.com.tw/upload/images/20191015/20120937O8colBLtbK.png


上一篇
[Day29]10905: Children's Game
系列文
一日一CPE30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
阿展展展
iT邦好手 1 級 ‧ 2020-01-29 00:09:02

恭喜完賽 有些題目 值得細細品嘗呢!
/images/emoticon/emoticon64.gif

我要留言

立即登入留言