HDOJ 2061

Treasure the new start, freshmen!

Problem Description
background:
A new semester comes , and the HDU also meets its 50th birthday. No matter what’s your major, the only thing I want to tell you is:“Treasure the college life and seize the time.” Most people thought that the college life should be colorful, less presure.But in actual, the college life is also busy and rough. If you want to master the knowledge learned from the book, a great deal of leisure time should be spend on individual study and practise, especially on the latter one. I think the every one of you should take the learning attitude just as you have in senior school.
“No pain, No Gain”, HDU also has scholarship, who can win it? That’s mainly rely on the GPA(grade-point average) of the student had got. Now, I gonna tell you the rule, and your task is to program to caculate the GPA.
If there are K(K > 0) courses, the i-th course has the credit Ci, your score Si, then the result GPA is
GPA = (C1 * S1 + C2 * S2 +……+Ci * Si……) / (C1 + C2 + ……+ Ci……) (1 <= i <= K, Ci != 0)
If there is a 0 <= Si < 60, The GPA is always not existed.

Input
The first number N indicate that there are N test cases(N <= 50). In each case, there is a number K (the total courses number), then K lines followed, each line would obey the format: Course-Name (Length <= 30) , Credits(<= 10), Score(<= 100).
Notice: There is no blank in the Course Name. All the Inputs are legal

Output
Output the GPA of each case as discribed above, if the GPA is not existed, ouput:“Sorry!”, else just output the GPA value which is rounded to the 2 digits after the decimal point. There is a blank line between two test cases.

Sample Input
2
3
Algorithm 3 97
DataStruct 3 90
softwareProject 4 85
2
Database 4 59
English 4 81

Sample Output
90.10

Sorry!

Author
zl

Source
校庆杯Warm Up

解题思路
注意最后一行后没有空行。

AC

#include<stdio.h>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;
int main() {
	string s;
	int n, m;
	double num1, num2,credits[15], score[105];
	bool flag;
	while (cin >> n) {
		while (n--) {
			num1 = 0;
			num2 = 0;
			cin >> m;
			flag = true;
			for (int i = 0; i < m; i++) {
				cin >> s >> credits[i] >> score[i];
				if (score[i] >= 0 && score[i] < 60) {
					flag = false;
					continue;
				}
				num1 += credits[i] * score[i];
				num2 += credits[i];
			}
			if (flag == false)
				printf("Sorry!\n");
			else {
				printf("%.2lf\n", num1 / num2);
			}
			if (n != 0)
				printf("\n");
		}
	}
	return 0;
}

相关推荐

  1. HDOJ 2061

    2024-03-18 23:20:05       40 阅读
  2. HDOJ 2041

    2024-03-18 23:20:05       45 阅读
  3. HDOJ 2036

    2024-03-18 23:20:05       39 阅读
  4. HDOJ 2050

    2024-03-18 23:20:05       40 阅读
  5. HDOJ 2078

    2024-03-18 23:20:05       38 阅读
  6. LeeetCode 206

    2024-03-18 23:20:05       52 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-18 23:20:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-18 23:20:05       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-18 23:20:05       82 阅读
  4. Python语言-面向对象

    2024-03-18 23:20:05       91 阅读

热门阅读

  1. 宠物智能喂食机方案设计

    2024-03-18 23:20:05       45 阅读
  2. ROS2纯跟踪实现(C++)

    2024-03-18 23:20:05       35 阅读
  3. 英语单词--痛苦

    2024-03-18 23:20:05       37 阅读
  4. 实现C++自定义的String类

    2024-03-18 23:20:05       34 阅读
  5. Git详细入门笔记

    2024-03-18 23:20:05       28 阅读
  6. 2022 Task 2 Max Sum of 2 integers sharing first and last digits

    2024-03-18 23:20:05       38 阅读
  7. 归并排序思路

    2024-03-18 23:20:05       36 阅读
  8. 职场人如何看待领导打绩效

    2024-03-18 23:20:05       36 阅读
  9. Winform编程详解十四:NumericUpDown 数字输入框

    2024-03-18 23:20:05       42 阅读
  10. 使用Cloudflare来给wordpress网站图片自动压缩加速

    2024-03-18 23:20:05       36 阅读
  11. nslookup和dig命令的使用方法以及区别

    2024-03-18 23:20:05       36 阅读