hdu4802(stl)
来源:互联网 发布:安卓开发java基础 编辑:程序博客网 时间:2024/06/07 08:25
这道题目虽然是个水题,但是我当时并不会用map,后来补了一下
map版
#include <iostream>#include <map>#include <stdio.h>using namespace std;map<string,double>mp;void init(){ mp.insert(pair<string,double>("A",4.0)); mp.insert(pair<string,double>("A-",3.7)); mp.insert(pair<string,double>("B+",3.3)); mp.insert(pair<string,double>("B",3.0)); mp.insert(pair<string,double>("B-",2.7)); mp.insert(pair<string,double>("C+",2.3)); mp.insert(pair<string,double>("C",2.0)); mp.insert(pair<string,double>("C-",1.7)); mp.insert(pair<string,double>("D",1.3)); mp.insert(pair<string,double>("D-",1.0)); mp.insert(pair<string,double>("F",0));}int main(){ int n; string s; while(cin>>n) { double ans=0; int c=0,chu=0; init(); for(int i=1;i<=n;i++) { cin>>c>>s; if(s=="P"||s=="N") continue; ans+=c*mp[s]; chu+=c; } if(chu==0) puts("0.00"); else printf("%.2lf\n",ans/chu); } return 0;}
非map版
#include <iostream>#include <string>#include <stdio.h>using namespace std;string a;int main(){ int n; while(scanf("%d",&n)!=EOF) { // memset(a,0,sizeof(a)); double sum=0.0; int ans=0; int x; for(int i=1; i<=n; i++) { cin>>x>>a ; if(a =="P"||a =="N") continue; else if(a =="A") sum+=x*4.0; else if(a =="A-") sum+=x*3.7; else if(a =="B+") sum+=x*3.3; else if(a =="B") sum+=x*3.0; else if(a =="B-") sum+=x*2.7; else if(a =="C+") sum+=x*2.3; else if(a =="C") sum+=x*2.0; else if(a =="C-") sum+=x*1.7; else if(a =="D") sum+=x*1.3; else if(a =="D-") sum+=x*1.0; else if(a =="F") sum+=x*0; ans+=x; } if(ans==0&&sum==0) printf("0.00\n"); else printf("%.2lf\n",sum/ans); for(int i=0; i<a.length(); i++) a.clear(); } return 0;}
0 0
- hdu4802(stl)
- hdu4802
- 【HDU4802】GPA C++语法基础题(真是瞎了)
- HDU4802-GPA
- HDU4802 GPA
- 【2013南京现场赛】1001 hdu4802 GPA
- STL学习记录(一):STL简介
- c++之STL(10)STL 算法
- C++ STL优先队列(STL堆)
- 认识STL(一):STL概述
- STL学习(一)
- STL学习(二)
- STL学习(三)
- STL(1)
- swap_ranges算法(STL)
- STL实践(count_if)
- 走近STL(转)
- STL版本(转)
- 按键事件
- V尼熊的java之旅——面向对象篇
- poj 1275 Cashier Employment
- 2016华为上机题:计算下一秒
- apt-get 机制详解
- hdu4802(stl)
- Android异步下载网络图片(其一:Handler)
- 3.25
- java例题学习:简单的继承代码小片段
- CodeForces158B
- 二叉树学习总结
- Android异步下载网络图片(其二:AsyncTask)
- shape里面的gradient属性,就是渐变属性
- hdu5556 Land of Farms