标签:
Time Limit: 20 Sec Memory Limit: 256 MB
http://acm.hdu.edu.cn/showproblem.php?pid=4802
Input
Output
For each test case, print the GPA (rounded to two decimal places) as the answer.
Sample Input
5 2 B 3 D- 2 P 1 F 3 A 2 2 P 2 N 6 4 A 3 A 3 A 4 A 3 A 3 A
Sample Output
For the first test case: GPA =(3.0 * 2 + 1.0 * 3 + 0.0 * 1 + 4.0 * 3)/(2 + 3 + 1 + 3) = 2.33 For the second test case: because credit in GPA computation is 0(P/N in additional treatment), so his/her GPA is “0.00”.
题意
算GPA!
题解:
签到题
代码:
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) #define maxn 200001 #define mod 1000000007 #define eps 1e-9 int Num; char CH[20]; //const int inf=0x7fffffff; //нчоч╢С const int inf=0x3f3f3f3f; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } inline void P(int x) { Num=0;if(!x){putchar(‘0‘);puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts(""); } //************************************************************************************** map<string,double> H; int main() { //test; int n; H["A"]=4.0; H["A-"]=3.7; H["B+"]=3.3; H["B"]=3.0; H["B-"]=2.7; H["C+"]=2.3; H["C"]=2.0; H["C-"]=1.7; H["D"]=1.3; H["D-"]=1.0; H["F"]=0; H["N"]=0; H["P"]=0; while(scanf("%d",&n)!=EOF) { double num=0; double kiss=0; for(int i=1;i<=n;i++) { int tmp=read(); string s; cin>>s; if(s=="N"||s=="P") tmp=0; kiss+=H[s]*tmp; num+=tmp; } if(num==0) cout<<"0.00"<<endl; else printf("%.2lf\n",kiss/num); } }
标签:
原文地址:http://www.cnblogs.com/qscqesze/p/4534458.html