| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10832 | Pouring Water |
|
| 11186 | Pascal's triangle |
|
| 11263 | Word Count |
|
| 11462 | cppreference |
|
| 11953 | linked list-insert and remove |
|
| 11954 | Bubble sort |
|
Description
Suppose that you have an infinite number of containers with different sizes, already filled with water. Given another empty container with size N liters, you need to find out all the possible methods to fill this N-liter empty container using the provided smaller containers. Note that, to avoid water wastage, if you choose to use a container, all the water in this container should be poured.
For example, assume that we have containers in 1, 5, and 10 liters. To get the 17 liters of water, all the possible methods are listed below:
- 1 container of 10 liters, 1 container of 5 liters, and 2 containers of 1 liter.
- 1 container of 10 liters, 0 containers of 5 liters, and 7 containers of 1 liter.
- 0 containers of 10 liters, 3 containers of 5 liters, and 2 containers of 1 liter.
- 0 containers of 10 liters, 2 containers of 5 liters, and 7 containers of 1 liter.
- 0 containers of 10 liters, 1 container of 5 liters, and 12 containers of 1 liter.
- 0 containers of 10 liters, 0 containers of 5 liters, and 17 containers of 1 liter.
Note that
1. This problem involves three files.
- function.h: Function definition of filliing and showResult.
- function.c: Function describe of filling and showResult.
- main.c: A driver program to test your implementation.
You will be provided with main.c and function.h, and asked to implement function.cpp.
2. For OJ submission:
Step 1. Submit only your function.c into the submission block. (Please choose C compiler)
Step 2. Check the results and debug your program if necessary.
function.h
main.c
Hint
You can use the following incomplete code of function.c to solve this problem.
function.c
Input
The input contains three lines.
The first line contains an integer M (0<M<=5) which represents the number of different size containers.
The second line contains M numbers, S1 ,S2 , …, SM. Si represents the size of the i-th container. Note that these M numbers are in decreasing order.
The third line contains an integer N (0<M<100) which represents the size of the empty container.
Output
Display all the possible methods to fill the empty container. Each line represents a method in the format “(C1,C2,…,CM)”, where Ci represents the number of the size Si container.
Sample Input Download
Sample Output Download
Partial Judge Code
10832.cPartial Judge Header
10832.hTags
Discuss
Description
As described in Wikipedia, Pascal's triangle is a triangular array of the binomial coefficients. The element k on row n of Pascal’s triangle can be calculated by the following relation:
C(n, 1) = 1, for n = 1, 2, …
C(n, n) = 1, for n = 1, 2, …
C(n, k) = C(n-1, k-1) + C(n-1, k), for k = 2, 3, … and for n = 2, 3, …
Given a nonnegative integer M, display the Pascal’s triangle from row 1 to row M.
Use '%10d' to print each element. Print a newline '\n ' at the end of each row.
(Note that the sample output print only 1 blank within each element, which is wrong. You should use '%10d'.)
Input
A positive integer M (1<=M<=30)
Output
Print the Pascal triangle from level 1 to level M.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given an article as input. You have to count the number of each word, and prints the list of words in alphabetical order.
An article is made of paragraphs and words. In this problem, Word Count refers to an useful tool that counts the numbers of appearances of different words in an article. In this problem, we have provide a function that parse the input article and fetch each word. Slightly different from other partial judge you have seem before, your submission should have a main function and all memory you need, and include the "function.h" to use our fetch_word() function. Function fetch_word() is define as following:
const char *fetch_word() ;
Each time you call this function, it returns a const pointer which points to the address of a word, and make sure the end of the returned word is ended by character '\0'. Typically, you have to copy characters from the returning value of fetch_word() to your 2D array (or other memory layout) if necessary, and increase the counter for the specific word. If there is no more words in a article, the function returns NULL, and you should start preparing output the results.
Note: If you try to use a pointer to safe the return value, remember to use the const char* type, like "const char* word = fetch_word();".
After you count the numbers of words, you should sort and print all words as a report. The format will be describeb in Output.
Input
Input is an article. Words are splited by blanks (spaces, tab and new line) and some punctuations(標點符號). The whole input contains only one ariticle. There are no more than 100 different words in a ariticle, and no words are longer than 30 characters.
Output
Print the pair <word number> in each line like the sample output, and seperate word and number by a space. All words should be count as all characters is lowercase(英文小寫). Non-alphabetical characters (like numbers and punctuations) just remain the same. You just have to count all words we fetch for you.
Sample Input Download
Sample Output Download
Partial Judge Code
11263.cPartial Judge Header
11263.hTags
Discuss
Description
This problem will ask you to do some operations on a list. These operations contains insert, remove and show. The position of first node is 0.
Input
The input consist of a number of operations. The first line specifies a non-negative integer N that specifies the number of operations. Each operations (I, R and S) are separated by a newline character (\n).
I stands for “insert”, following by a non-negative integer (insert position, non-negative integer) and a non-negative integer (insert value, 0<=insert value<20). Insert a node at insert position with insert value.
If insert position is greater than or equal to the length of the list, treat the insert position as the next position of the last position at the list.
For example, input is
I 0 0
I 1 1
S
Output should be
0 1
R stands for “remove”, following by a non-negative integer (remove value). Remove the nodes in the list with the value that is equal to remove value.
S stands for “show”. Print the value of all nodes in the list. Separate every prints by a whitespace character. If the list is empty, do not print anything.
For example, input is
2
R 1
S
Output should be nothing.
Output
Print a space after doing S operations (if S has printed something).
Sample Input Download
Sample Output Download
Partial Judge Code
11953.cPartial Judge Header
11953.hTags
Discuss
Description
Please implement bubble sort algorithm to sort a sequence of number in ascending order, and show the sequence of number after each iteration.
The bubble sort algorithm is shown in following:
At each iteration, it scans the whole array from left to right. While scaning each element, treat the element and its neighbor as a pair. If the order of the elements in the pair is reversed, swap the elements.
If there are N elements, N-1 iterations is needed.
Input
There are 2 lines input.
The first line contains a integer n, indicating the total number of integers would be sorted. (1< n <= 100000)
The second line consists of the integers (the value is between -2147483648 and 2147483647) being sorted.
Output
Show the sequence of number after each iteration.
If the input has n numbers, the output would have n-1 lines.
note: print a space before each number, and print '\n' in the end of each line.