HDU1202 無語題

來源:互聯網
上載者:User

        這一題WA了8次。再看討論時,罵聲一片!個人也覺得這題出的不好。貼在這,供後來者借鑒。

 

#include<iostream>#include<iomanip>using namespace std;double judge_score(int tem)  //分數對應的點數,題目給出的只是整數,所以調用時要強制類型轉化{if(tem>=90 && tem<=100)return 4.0;else if(tem>=80 && tem<=89)return 3.0;else if(tem>=70 && tem<=79)return 2.0;else if(tem>=60 && tem<=69)return 1.0;return 0.0;}int main(){int t,i;double credit,score;while(cin>>t){double all_score=0.0,all_credit=0.0;for(i=0;i<t;i++){cin>>credit>>score;if(score!=-1)  //分數為-1,不計算{all_score+=judge_score(int(score))*credit; //分數的強制類型轉化,應該很重要,沒做這個,結果WA了8次all_credit+=credit;}}if(all_credit==0.0 || all_score==0.0)  //GPA不存在{cout<<-1<<endl;continue;}double GPA=all_score*1.0/all_credit;cout<<setiosflags(ios::fixed)<<setprecision(2)<<GPA<<endl;}return 0;}

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.