| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 14703 | Average score |
|
| 14712 | Compute Cosine Function with a Series |
|
| 14715 | Prime factorization |
|
| 14819 | Average grade |
|
| 14825 | Longest common subsequence |
|
Description
Write a program to calculate average scores.
Suppose there are s students taking the same c courses. The program should compute the average score for each student, as well as the average score for each course across all students.
-
Input:
- The first line contains two integers: s and c.
-
The following s lines each represent one student’s scores. Each line contains c numbers, where the j-th number represents that student’s score in the j-th course.
-
Output:
-
A total of s + c lines.
-
The first s lines each contain the average score of one student.
-
The next c lines each contain the average score of one course across all students.
-
-
Constraints:
-
0 < s ≤ 100
-
0 < c ≤ 100
-
Input
First line: s, c.
Following s lines each represent one student's score, c represents the student's score in the j-th course.
Ex. 3 4
87 89 97 89
78 100 76 98
99 90 89 94
Output
A total of s + c lines.
The first s lines each contain the average score of one student.
The next c lines each contain the average score of one course across all students.
Ex. 90
88
93
88
93
87
93
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Write a program to compute cos(x) for a given real number x (in radians, 0≤x≤2π) using the Taylor series:
To ensure sufficient accuracy, use double precision floating-point arithmetic and sum the series up to n = 15 (i.e., include the terms for n=0,1,…,15).
For example, please perform this calculation
Information about factorial function:
- 0! = 1
-
(2n)!=1×2×3×⋯×(2n)
Notes:
-
Do not call a library cosine function to compute the answer; use the series definition.
-
For efficiency and numerical stability, update powers and factorials iteratively rather than recomputing them from scratch each term.
Input
Given real number x (in radians, 0≤x≤2π)
Output
Output: Print the result rounded to exactly 6 digits after the decimal point.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
This program reads a positive integer n and performs prime factorization.
For each prime factor, output the prime number followed by its exponent.
The prime factors must be listed in ascending order.
Hint:
-
Start dividing
nby the smallest prime (2). -
Count how many times it can be divided (that is the exponent).
-
Continue with the next prime number (3, 5, 7, …) until
nbecomes 1.
Input
A single positive integer n.
Output
A sequence of integers, where each pair consists of a prime factor and its exponent, separated by a space.
Factors are listed from smallest to largest.
Take sample input 1 as example,
123456 = 26 x 31x 6431,
then, output
2 6 3 1 643 1
Important Notes
-
A newline (
\n) is printed at the end of the output. -
A space must follow the last exponent before the newline.
-
The formatting of the output must match the samples exactly.
For example,
// Sample Output 1
2 6 3 1 643 1' ''\n' // ' ' is a blank space, and '\n' is a newline character
Sample Input Download
Sample Output Download
Tags
Discuss
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
Tags
Discuss
Description
Write a program to compute the Longest Common Subsequence (LCS).
A subsequence of a sequence is obtained by deleting some characters from the original sequence.
For example, aed is a subsequence of bacedf.
The longest common subsequence of two sequences is the common subsequence with the greatest length.
For instance, ade is one of the longest common subsequences of abcde and zzadfess.
Use the following recursive algorithm to compute the length of the LCS:
-
If the first characters of both strings are the same,
the length of the LCS is 1 plus the LCS length of the two strings with their first characters removed. -
If the first characters are different,
the LCS length is the maximum of the following two results:-
The LCS length after removing the first character from the first string.
-
The LCS length after removing the first character from the second string.
-
Constraints:
0 < n ≤ 16
Input
Two lines, each containing a lowercase letter string of length ≤ n.
Ex. abcde
zzadfess
Output
The length of the longest common subsequence.
Ex. 3