| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10489 | mid1 practice Josephs |
|
| 10494 | Midterm Practice Moving Books |
|
| 10495 | Midterm Practice Count Square |
|
| 10497 | mid1 practice - queue |
|
| 10498 | mid1 practice - restaurant |
|
| 10501 | Midterm Practice Crazy Monkey |
|
Description
The Josephs problem is notoriously known. For those who are not familiar with the problem, among n people numbered 1, 2, . . . , n, standing in circle every mth is going to be executed and only the life of the last remaining person will be saved. Joseph was smart enough to choose the position of the last remaining person, thus saving his life to give the message about the incident.
The persons are eliminated in a very peculiar order; m is a dynamical variable, which each time takes a different value corresponding to the prime numbers succession (2,3,5,7,...). So in order to kill the i-th person, Josephs cousin counts up to the i-th prime.
Input
Each line with 1 integers, n. n is the number of people.Input terminated by EOF.
Testcase 1 : 1<=n<100
Testcase 2 : 100<=n<500
Testcase 3 : 500<=n<1000
Testcase 4 : 1000<=n<3000
Output
The output will consist in separate lines containing the position of the person which life will be saved.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
The problem is to parse a series of commands to move the books that lie on the table. Initially there are n books lying on their own table (numbered from 0 to n-1, means book 0 lies on table 0) with book bi adjacent to book bi+1 for all 0 <= i < n-1
as shown in the diagram below:
|
Book 0 |
Book 1 |
Book 2 |
Book 3 |
Book 4 |
Book 5 |
…… |
Book N-1 |
|
Table 0 |
Table 1 |
Table 2 |
Table 3 |
Table 4 |
Table 5 |
Table N-1 |
The valid commands and limited for moving books are:
Any command in which A = B or in which A and B are in the same stack of books is an illegal command. All illegal commands should be ignored and should have no affect on the configuration of books.
l move A onto B
Return any books that are stacked on the top of book A and book B to their own table. Then puts book A onto book B.
l move A over B
Return any books that are stacked on the top of book A to their own table.
Then puts book A onto the top of book B.
l pile A onto B
Return any books that are stacked on the top of book B to their own table.
Then puts book A and all books on the top of book A onto the top of book B.
l pile A over B
Put book A and all books on the top of book A onto the top of book B.
l exit
Finish moving the books
Input
The input begins with an integer n on a line by itself representing the number of books in the book world. You may assume that 0 < n < 25.
The number of books is followed by a sequence of book commands, one command per line. Your program should process all commands until the exit command is encountered.
You may assume that all commands will be of the form specified above. There will be no syntactically incorrect commands.
Output
The output should consist of the final state of the books. Each table numbered i (0 <= i < n, where n is the number equal to books initial position) should appear followed immediately by a colon.
If there is at least a book on it, the colon must be followed by one space, followed by a list of books that appear stacked in that position with each book number separated from other book numbers by a space. Don't put any trailing spaces on a line.
There should be one line of output for each book position (i.e., n lines of output where n is the integer on the first line of input).
You are asked to add a new line character at the end.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
The following is a 2 × 2 square, which consists of five different-size squares: four 1 × 1 squares and one 2 × 2 square.

If you are given an N × N square, can you write a C program to calculate the total number of squares contained in this given square?
Input
There are several lines, each of which represents the size N of a square (1 <= N <= 1860). Your program should terminate when 0 is encountered.
Output
For every given square size, your program should print the corresponding square amount followed by a new line character.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Consider a queue of groups. Each group has a unique ID denoted by a string of six uppercase alphabets, e.g. "IPHONE" or "GOOGLE". A new comer with a certain ID first checks if there exists a group of the same ID. If yes, then the new comer joins that group; otherwise, the new comer forms a new group at the end of the queue.
Input
The input is a sequence of IDs. Each ID is a string of six uppercase alphabets, except the last one, which is "END", indicating the end of the input.
Output
The output contains two lines. The first line shows the ID of the last group in the queue. The second line shows the size of the last group.
Note that each line of the output should be ended with a newline character '\n'.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Consider a restaurant with an infinite number of tables, which are numbered as 1, 2, 3, ..., and so on. Each table has 5 seats. When a customer enters the restaurant, he gets a ticket showing a positive integer as his lucky number. He then goes through each table to find a seat. He can take the seat as long as the following two conditions hold: (1) The table is not full yet. (2) His lucky number is greater than the lucky number of anyone at that table. For example, if the lucky numbers of the customers are issued as follows:
1 7 5 6 8 9 2 10 11 3 12 4 13 7 7
The final seating would be
Table No. 1: 1 7 8 9 10
Table No. 2: 5 6 11 12 13
Table No. 3: 2 3 4 7
Table No. 4: 7
Input
The input contains a sequence of positive integers as the lucky numbers, except the last one, which is -1, indicating the end of the input.
Output
The output contains several lines. Each line lists the largest lucky number of the table. Each line should be ended with a newline character '\n'.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
There is a monkey in a zoo. One day, the animal trainer gives the monkey a typewriter. The monkey starts to press the buttons randomly.
The typewriter contains the following buttons.
- English alphabet (i.e., A-Z, and a-z)
- Numbers (i.e., 0-9)
- Special characters
1. '@' means the 'Home' key:
Return the cursor to the beginning of the sentence.
2. '#' means the 'End' key:
Put the cursor at the end of the sentence.
3. '%' means the 'Delete' key:
Delete one character to the right of the cursor.
HINT:

Input
There is one line that contains at least one and at most 100,000 characters which represent what the monkey types.
Output
Print out the result that will be displayed on the screen for the monkey’s typing. Your program should print the answer followed by a new line character.