Hangdian ACM2061

Problem Description
Background:
The new semester begins, and HDU also celebrates its 50th birthday. No matter what your major is, the only thing I want to tell you is: "Cherish college life and take your time."  Most people think college life should be colorful and less stressful. But in fact, university life is also very tedious. If you want to master what you've learned from the book, you should spend a lot of your free time on personal study and practice, especially the latter. I think each of you should adopt the same learning attitude as you did in high school.
"No pain, no gain", HDU also has a scholarship, who can win it? This is largely dependent on the student's GPA (Grade Point Average). Now, I'm going to tell you the rules,
if there are K (K > 0) courses, and the i-th course has credits Ci and your grades Si, then the resulting
GPA = (C1*S1+C2*S2+.... ..+Ci*Si...)/(C1+C2+...+Ci...) (1 <= i <= K, Ci != 0)
if present 0 <= Si < 60, GPA is always absent.
 

enter
The first number N means there are N test cases (N <= 50). In each case, there is a number K (total number of courses), followed by K lines, each line will obey the format: course name (length <= 30), credits (<= 10), grades (<= 100) .
Note: There are no spaces in the course name. All inputs are legal
 

Yield
Output the GPA in each case as described above, if the GPA does not exist, output: "Sorry!", otherwise just output the GPA value rounded to two decimal places. There is a blank line between the two test cases. 
 

example input
 
  
2 3 Algorithms 3 97 DataStruct 3 90 Software Projects 4 85 2 Databases 4 59 English 4 81
 

Sample output
 
  
90.10 Sorry !

Knowledge supplement (for reference: https://blog.csdn.net/moqingxinai2008/article/details/53908265)

1. When used in scanf, the part with * will be ignored (skipped) and will not be acquired by parameters.
       E.g:

[cpp]  view plain copy  
  1. int a,b;  
  2. char b[10];  
  3. scanf("%d%*s",&a,b);  
       The input is:
12 abc
        then 12 will be read into variable a, but the following abc will be discarded after reading, without assigning any variable (such as the character array b here)


        With * and scan set, you can select only what you need from the input and ignore the rest.
In addition, it is also commonly used to empty the buffer. 


2. When used in printf, * means to replace the position of * with the following formal parameters to realize dynamic format output.
      E.g:

[cpp]  view plain copy  
  1. printf("%*s", 10, s); /*意思是输出字符串s,但至少占10个位置,不足的在字符串s左边补空格,这里等同于printf("%10s", s);*/  


[cpp]  view plain  copy
  1. printf("%.*s\n"int,str) ;   
  2. // %.*s 其中的.*表示显示的精度 对字符串输出(s)类型来说就是宽度  
  3. // 这个*代表的值由后面的参数列表中的整数型(int)值给出  
  4.   
  5. // 例如:  
  6. printf("%.*s\n", 1, "abc");        // 输出a  
  7. printf("%.*s\n", 2, "abc");        // 输出ab  
  8. printf("%.*s\n", 3, "abc");        // 输出abc >3是一样的效果 因为输出类型type = s,遇到'\0'会结束  

Answer: I wrote it myself, oj does not pass. . . mmp; reference address (https://blog.csdn.net/riverflowrand/article/details/44353855)

#include <stdio.h>

int main() {
	
	int n, k,  flag;
	double a1, a2, cre, sco;

	scanf("%d", &n);
		
		
		while(n--) {
			a1 = 0.0;
			a2 = 0.0;
			flag = 0;
			scanf("%d", &k);
			while(k--) {
				scanf("%*s%lf%lf", &cre, &sco);
				if(sco<60) {
					flag = 1;
				}
				a1 + = cre * sco;
				a2 + = cre;
			}
			if(flag==1)
				printf("Sorry!\n");
			else
				printf("%.2lf\n", a1 / a2);
			if(n)
				printf("\n");	
		}
		
		
	
	
	return 0;
}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325979681&siteId=291194637