#15397: 測資有問題?


hshua (hshua)

學校 : 新北市立林口高級中學
編號 : 52506
來源 : [163.20.185.250]
最後登入時間 :
2024-05-06 11:04:22
d260. 11455 - Behold my quadrangle -- UVa11455 | From: [125.227.237.177] | 發表日期 : 2018-10-04 08:02

測資有問題?

例如:

1 2 3 6 

可以是 "quadrangle" 嗎?

 

#0: 100% WA (line:1)

您的答案為: banana
正確答案為: quadrangle
 
#15400: Re:測資有問題?


hshua (hshua)

學校 : 新北市立林口高級中學
編號 : 52506
來源 : [163.20.185.250]
最後登入時間 :
2024-05-06 11:04:22
d260. 11455 - Behold my quadrangle -- UVa11455 | From: [125.227.237.177] | 發表日期 : 2018-10-04 10:14

測資有問題?

例如:

1 2 3 6 

可以是 "quadrangle" 嗎?

 

#0: 100% WA (line:1)

您的答案為: banana
正確答案為: quadrangle

程式碼如下,請指點指點

#include <iostream>

#include <algorithm>

#include <map>

using namespace std;

map<int,int> M;

//=======================================

int main(){

int n,x,flag,e[10];  

    cin>>n;

    

    while(n--){

        M.clear();

        flag=0;

        for(int i=0; i<4; i++){

            cin>>e[i];

            if(x>0) M[e[i]]++;

            else flag=1;

        }

        int len=M.size();

        

        if(len==1 && flag==0) cout<<"square";

        else if(len==2 && flag==0) cout<<"rectangle";

        else {

            sort(e,e+4); //由小到大排序

            if(e[0]+e[1]+e[2]<=e[3]) flag=1; //"1 2 3 6" is quadrangle???

            

            if(flag==0) cout<<"quadrangle";

            else cout<<"banana";

        }    

 

        if(n>0) cout<<endl;

    }

    

    return 0;

}

 

 
#15404: Re:測資有問題?


inversion (「我們所認識的可符香是個像天使的好女孩」之葉林 *Cries...)

學校 : 國立清華大學
編號 : 43537
來源 : [49.159.6.107]
最後登入時間 :
2022-05-28 19:29:12
d260. 11455 - Behold my quadrangle -- UVa11455 | From: [49.158.83.43] | 發表日期 : 2018-10-04 20:08

測資有問題?

例如:

1 2 3 6 

可以是 "quadrangle" 嗎?

 

#0: 100% WA (line:1)

您的答案為: banana
正確答案為: quadrangle

程式碼如下,請指點指點

#include

#include

#include

using namespace std;

map<int,int> M;

//=======================================

int main(){

int n,x,flag,e[10];  

    cin>>n;

    

    while(n--){

        M.clear();

        flag=0;

        for(int i=0; i<4; i++){

            cin>>e[i];

            if(x>0) M[e[i]]++;

            else flag=1;

        }

        int len=M.size();

        

        if(len==1 && flag==0) cout<<"square";

        else if(len==2 && flag==0) cout<<"rectangle";

        else {

            sort(e,e+4); //由小到大排序

            if(e[0]+e[1]+e[2]<=e[3]) flag=1; //"1 2 3 6" is quadrangle???

            

            if(flag==0) cout<<"quadrangle";

            else cout<<"banana";

        }    

 

        if(n>0) cout<<endl;

    }

    

    return 0;

}

 


首先,1、2、3、6是無法組成四邊形的。

 

再來,您輸入的for迴圈裡面的「x」這個變數是有何用途呢?既沒有初始化,也沒有後續的改值。

 

最後,這題應該是不需要map的,為何使用到了map呢?

 
ZeroJudge Forum