MiYu鍘熷垱, 杞笘璇鋒敞鏄?: 杞澆鑷?______________鐧界櫧銇眿
棰樼洰鍦板潃:
http://acm.hdu.edu.cn/showproblem.php?pid=2061
棰樼洰鎻忚堪:
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!
棰樼洰鍒嗘瀽:
榪欏彧鏄竴閬撶畝鍗曠殑鏁板艱綆楅, 鍞竴鐨勯毦搴﹀湪璇婚. 鐩存帴浣跨敤棰樼洰緇欏嚭鐨勫叕寮忓氨鍙互浜? 褰撶劧濡傛灉鎸傜鐨勮瘽,瑕佽緭鍑?"Sorry!"
涓嬮潰鏄鐩殑澶ц嚧緲昏瘧:
鑳屾櫙:
鏂扮殑瀛︽湡鍗沖皢鍒版潵錛屼篃姝i㈡澀宸炵數瀛愮鎶澶у50鍛ㄥ勾鏍″簡銆傛棤璁轟綘鐨勪笓涓氭槸浠涔堬紝鎴戝敮涓瑕佸憡璇夐偅涔堢殑鏄細“鐝嶆儨澶у鐨勭敓媧伙紝鍒╃敤濂芥椂闂淬?#8221; 寰堝浜鴻涓哄ぇ瀛︾殑鐢熸椿鍥炴槸涓板瘜澶氶噰銆備絾浜嬪疄鏄紝澶у鐢熸椿涔熷悓鏍峰繖紕屻傚鏋滀綘瑕佹帉鎻′功涓婄殑鐭ヨ瘑錛屼綘鐨勭┖闂叉椂闂村繀欏昏姳鍦ㄨ嚜瀛﹀拰瀹炶返涓婏紝灝ゅ叾鏄疄璺點傛垜璁や負錛屼綔涓轟竴浣嶅ぇ瀛︾敓錛屾墍鏈変漢閮藉繀欏葷姝h嚜宸辯殑瀛︿範鎬佸害銆?br>“娌℃湁涓嶅姵鑰岃幏鐨勪簨鎯?#8221;錛屾澀鐢典篃璁劇珛浜嗗瀛﹂噾錛屼綘鑳藉緱鍒板悧錛熷畠涓昏渚濇嵁鏄鐢熻幏寰楃殑GPA(嫻嬭瘎騫沖潎鍒?銆傜幇鍦紝鎴戝皢鍛婅瘔浣犲畠鐨勮鍒欙紝浣犵殑浠誨姟灝辨槸緙栫▼璁$畻GPA銆?br>鍋囧鏈塊闂ㄨ紼嬶紝絎琲闂ㄨ鐨勫鍒嗕負Ci錛屼綘鐨勬垚緇╀負涓篠i錛屽垯GPA涓猴細
GPA = (C1 * S1 + C2 * S2 +……+Ci * Si……) / (C1 + C2 + ……+ Ci……) (1 <= i <= K, Ci != 0)
濡傛灉鏈変竴闂ㄨ紼嬫垚緇╁湪0鍒?0涔嬮棿錛屽垯GPA灝嗕笉瀛樺湪銆?/span>
浠g爜濡備笅:
MiYu鍘熷垱, 杞笘璇鋒敞鏄?: 杞澆鑷?______________鐧界櫧銇眿
#include <iostream>
int main ()
{
int f, T, N;
double s, c;
double up, down;
scanf( "%d", &T );
while ( T -- )
{
scanf ( "%d", &N );
up = down = f = 0;
while ( N -- )
{
scanf ( "%*s%lf%lf", &c, &s );
if ( f )
{
continue;
}
if ( s < 60 && s >= 0 )
{
f = 1;
}
up += s * c;
down += c;
}
printf( f ? "Sorry!\n" : "%.2f\n", up / down );
if ( T ) putchar ( '\n' );
}
return 0;
}

]]>