| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 14819 | Average grade |
|
| 14820 | Database server |
|
Description
Implement a function average_grade that returns a student's average grade.
If the student has not taken any courses, the average grade should be 0.0.
grade.h
struct student {
int grade[20];
int count;
};
average-grade-main.c
#include <stdio.h>
#include "grade.h"
float average_grade(struct student *std_ptr);
int main(void)
{
int i;
struct student std;
scanf("%d", &(std.count));
for(i = 0; i < std.count; i++)
scanf("%d", &(std.grade[i]));
printf("%f\n", average_grade(&std));
return0;
}
Input
Number of subjects.
Score.
Ex.3
99 93 100
Output
The average score.
Ex.97.333333
Sample Input Download
Sample Output Download
Discuss
Description
Write a program to simulate a database server. The program first reads data into the database, and then executes one query command at a time.
The first part of the input is the data. The first line contains the number of records, n. The next n lines each contain one record, with the following fields. Each string’s length does not exceed m.
-
lastname: stored as a string -
firstname: stored as a string -
ID: stored as a string -
salary: stored as an integer (int) -
age: stored as an integer (int)
The second part of the input is the SQL query commands. The first line contains the number of commands, c. Each command has the following format:
select field1 field2 ... fieldk where condition
-
fieldcan be any oflastname,firstname,ID,salary,age, in any order. -
conditionis a test condition; only the records satisfying the condition will be output. The format ofconditionis:
field operator constant
Here, field can be any column.
-
If the field being compared is a string,
operatorcan be==or!=. -
If the field being compared is a number,
operatorcan be==,>, or<.
The output should be the specified fields of the records that meet the condition, separated by a single space.
Parameter constraints:
0 < n <= 50, 0 < m <= 80, 0 < c <= 100
Input
Numbers or records n.
Next n lines each contain one records, each string's length does not exceed m.
Number of commands c.
Ex. 4
Liu Pangfeng A123456789 80000 40
Wu Janet B123456789 79999 30
Liu Kevin C123456789 0 10
Liu Eric C123456789 0 7
2
select lastname firstname ID where salary > 1000
select firstname salary where lastname == Liu
Output
The specified fields of the records that meet the condition, separated by a single space.
Ex.Liu Pangfeng A123456789
Wu Janet B123456789
Pangfeng Liu 80000 Liu
Kevin 0 Liu
Eric 0 Liu