hdoj 2061 Treasure the new start, freshmen!(结构体)

原创 2015年11月18日 20:41:39

Treasure the new start, freshmen!

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13374    Accepted Submission(s): 4068


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!
代码:
#include<stdio.h>
struct node
{
	char course[50];
	double  credit;
	double score;
}a[1100];
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,i,j,flag=0;
		scanf("%d",&n);
		double  sum=0.0,cnt=0.0;
		for(i=0;i<n;i++)
		{
			scanf("%s %lf %lf",a[i].course  ,&a[i].credit ,&a[i].score );
			if(a[i].score <60&&a[i].score >=0)
			{
				flag=1;
			}
			sum+=a[i].credit *a[i].score ;
			cnt+=a[i].credit ;
		}
		if(flag)
		printf("Sorry!\n");
		else
		{
			printf("%.2lf\n",sum/cnt);
		}
		if(t)
		printf("\n");
	}
	return  0;
 } 

版权声明:本文为博主原创文章,未经博主允许不得转载。

HDU2061Treasure the new start, freshmen!

Treasure the new start, freshmen! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/3276...
  • xu_fish
  • xu_fish
  • 2016年01月12日 15:41
  • 131

武汉科技大学计算机学院菜鸟杯:Treasure the new start, freshmen! (杭电2061)

Treasure the new start, freshmen! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/327...

hdu2061--Treasure the new start, freshmen!

Description background: A new semester comes , and the HDU also meets its 50th birthday. No matter...

hdu2061 Treasure the new start, freshmen!

Treasure the new start, freshmen! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/327...

Treasure the new start, freshmen!

Treasure the new start, freshmen! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/327...

golang中结构体的初始化方法(new方法)

转自:http://my.oschina.net/ifraincoat/blog/517139 自定义一个结构体 type Rect struct {    ...
  • xxx9001
  • xxx9001
  • 2016年09月18日 14:53
  • 5445

C/C++日常学习总结(第二篇)结构体和类的大小及区别&为什么是new一个对象而不是malloc

1.大家在定义一个动态

类模板&结构体模板的new运算

类模板和结构体模板是如何进行带类型信息参数/用模板参数进行new运算 结构体模板: template class Node { public: Node *next; //指向后继结点的指针 ...

new delete 以及结构体的综合应用

关于new 和 delete的操作 1.  ->运算符叫做“指向结构体成员运算符”,是C语言和C++语言的一个运算符,用处是使用一个指向结构体或对象的指针访问其内成员。 ...

从零开始学C++之从C到C++(一):const与#define、结构体对齐、函数重载name mangling、new/delete 等

一、bool 类型 逻辑型也称布尔型,其取值为true(逻辑真)和false(逻辑假),存储字节数在不同编译系统中可能有所不同,VC++中为1个字节。 声明方式:bool result; resu...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:hdoj 2061 Treasure the new start, freshmen!(结构体)
举报原因:
原因补充:

(最多只允许输入30个字)