| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10895 | Grade report(different order) |
|
| 10904 | Building designing 2 |
|
| 11752 | My Insertion Sort |
|
Description
Given a grade report for all students in a class, which includes student ID, Chinese grade, English grade, math grade, and science grade for each student. Please list the report sorted in two different way.
If the order is descending, sort the grade by the total grade from high to low. If the total grade is the same between two students, then sort by order of Chinese grade, English grade, math grade, science grade, and student ID, which is from high to low for all grades and from low to high for student ID.
If the order is ascending, sort the grade by the total grade from low to high. If the total grade is the same between two students, then sort by order of Chinese grade, English grade, math grade, science grade, and student ID, which is from low to high for all grades and from low to high for student ID.
Note that in both two way, the student ID is sorted from low to high.
You need to store these information in structures:
typedef struct
{
int ID;
int Chinese, English, math, science;
int total;
} Grade;
HINT
Hint: While sorting, you can use qsort in <stdlib.h> or write other sorting algorithms by your self.
function.h
main.c
Input
The first line contains an integer N and a string, which means the number of students in the class and the order which grade are sorting in respectively.
In the following N lines, there are 5 integers: student ID, Chinese grade, English grade, math grade, and science grade in each line in order, which are separate by spaces.
Output
List the sorted report, while each line contains student ID, total grade, Chinese grade, English grade, math grade, and science grade in order, where there is a '\t' between each number. Note that there is a '\n' at the end of each line.
Sample Input Download
Sample Output Download
Partial Judge Code
10895.cPartial Judge Header
10895.hTags
Discuss
Description
An architect wants to design a very high building. The building will consist of some floors, and each floor has a certain size. The size of a floor must be greater than the size of the floor immediately above it and what's more, the sum of any two adjacent floor sizes is odd. In addition, the designer (who is a fan of a famous Spanish football team) wants to paint the building in blue and red, each floor a color, and in such a way that the colors of two consecutive floors are different.
To design the building the architect has n available floors, with their associated sizes and colors. All the available floors are of different sizes. The architect wants to design the highest possible building with these restrictions, using the available floors.
Hints : Implement the compare function and modify the design function to get the highest possible building .
function.c
|
#include <stdlib.h> #define RED 0 int compare(const void *a, const void *b) { } // Modify the design function qsort(floorArr, floorNum, sizeof(Floor), compare); height = 0; for (idx = 0; idx < floorNum; idx++) { |
function.h
|
#ifndef FUNCTION_H typedef struct { int compare(const void *a, const void *b); int design(int floorNum, Floor floorArr[]); #endif |
main.c
|
#include <stdio.h> #include <stdlib.h> #include "function.h" #define MAX_FLOOR_NUM 20000
int main() { int floorNum; int i; Floor floorArr[MAX_FLOOR_NUM]; scanf("%d", &floorNum); for (i = 0; i < floorNum; i++) { scanf(" %c %d", &floorArr[i].color, &floorArr[i].size); } printf("%d", design(floorNum, floorArr)); return 0; } |
Input
The first line contains the number of available floors. Then, the size and color of each floor appear in one line. Each floor is represented with a character and an integer between 0 and 999999. There is no floor with size 0. Character 'B' represents the blue floor and character 'R' represents the red floor. The integer represents the size of the floor. There are not two floors with the same size. The maximum number of floors for a problem is 20000
Output
The output will consist of a line with the number of floors of the highest building with the mentioned conditions.
Note: The first floor must be the biggest size in the available floors.
Sample Input Download
Sample Output Download
Partial Judge Code
10904.cPartial Judge Header
10904.hTags
Discuss
Description
In out class, HT Chen introduced a way to implement a qsort-like mysort using bubble sort.
To make you more clearly to the machism, you are asked to implement a qsort-like mysort using insertion sort.
The main function has already provided for you, what you have to do is just implement the mysort function.
For more specific, you just need to fill the following blank:
#include <stdio.h> #include <stdlib.h> int compare(const void* a, const void* b) { // compare a with b } void assign(char* x, char* y, size_t size) { // assign y to x } void mysort(void* arr, size_t count, size_t size, int (*cmp) (const void*, const void*)) { // do sorting!!! }
The pseudo code below would be helpful if you want to know how the insertion sort works.
i ← 1
while i < length(A)
j ← i
while j > 0 and A[j-1] > A[j]
swap A[j] and A[j-1]
j ← j - 1
end while
i ← i + 1
end while
Input
There are 2 lines input.
The first line contains a integer, indicating the total number of integers would be sorted.
The second line consists of the integers being sorted.
Output
The integers have been sorted.
Please notice that the sequence has to be in ascending order.