| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10389 | Text Editor |
|
| 10889 | Dictionary subsearch |
|
| 10893 | Moving Cars(4 direction) |
|
| 10896 | Number Chains |
|
| 10897 | Mouse Maze |
|
| 10898 | Enemy at the gates |
|
| 10899 | Find/Revision |
|
| 10900 | Transpose of A Matrix |
|
| 10901 | Pointer Integer Array |
|
Description
In this problem we simulate a simple text editor. Given a series of keyboard input, output the final text content.
The text editing rules are defined as following:
1. Normal alphabetical input and whitespace input (abcdefg…. and ‘ ‘) directly write after the cursor of the text content.
And four special commands started with a backslash(/) character
2. The backspace command which deletes a letter before the cursor (/backspace)
3. The newline command which creates a new line after the cursor (/newline)
4. The two navigating commands which move the cursor (/left /right)
The size of the text content is fixed to 500 characters, and the text content of testcases will not exceed 500 characters when simulating.
Hint:
#include#define MAX_SIZE 500 char content[MAX_SIZE]; char input[MAX_SIZE]; int main() { fgets(input, MAX_SIZE, stdin); /* your code here */ printf("%s", content); return 0; }
Input
The keyboard input sequence.
There is always a valid command(/backspace /newline /left /right) right after the backslash character.
There is no newline character at the end
Output
The final text content.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given a dictionary with n words, such as A1, A2, ..., An, and a string B for searching. If B is a substring of Ai, then Ai is one of the word that we want to search. Find out all the words we want to search.
Note that all the words in dictionary and the string B contain only uppercase or lowercase alphabets. And when searching, uppercase letters are considered the same as lowercase letters, for example, we can use 'the' to find 'THE'.
Input
The first line of the input is an integer n (0<n≦1000).
For the next n lines, each line contains a string Ai (0<length of Ai≦100) and a ‘\n’ at the end of the line.
The last line contains the string B (0<length of B≦10).
Output
Print out all the searched words in their original order in dictionary. Note that you NEED to print ‘\n’ at the end of all the words.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given the position of N cars on a map, we have to list the valid moves of each car along 4 directions (i.e. right, down, left and up).
Note that all cars can move horizontally and vertically.
For example, a map with 10 cars is shown below:
Given the coordinate of car 2 is 2 3 2 6, it means car 2 occupies the position of (2,3) to (2,6) in the map.
The valid moves of car 2 is 1 0 0 2, which means it can move right 1 grid but can’t move down, left and it can move up 2 grid.
HINTS:
function.h
main.c
Input
The first line is a number N (1<=N<=10), which means the total number of cars.
The following N lines are the coordinates of all cars.
Each line consists of 4 numbers. The first two numbers are the row and column of the head of the car. The other two numbers are the row and column of the tail of the car.
Output
Print out the valid moves of the cars in each line.
Each line consists of 4 number, the valid moves along right, down, left and up.
All of the numbers in the same line are separated by a space, and there is a '\n' at the end of each line.
Sample Input Download
Sample Output Download
Partial Judge Code
10893.cPartial Judge Header
10893.hTags
Discuss
Description
Given a number, we can form a number chain by
- arranging its digits in descending order
- arranging its digits in ascending order
- subtracting the number obtained in (2) from the number obtained (1) to form a new number
- and repeat these steps unless the new number has already appeared in the chain
Note that 0 is a permitted digit. The number of distinct numbers in the chain is the length of the chain.
You are to write a program that reads numbers and outputs the length of the chain for each number read.
For example:
Input: 123456789 1. 987654321 - 123456789 = 864197532 2. 987654321 - 123456789 = 864197532 Chain length = 2 You should output: 2 Input: 1234 1. 4321 - 1234 = 3087 2. 8730 - 378 = 8352 3. 8532 - 2358 = 6174 4. 7641 - 1467 = 6174 Chain length = 4 You should output: 4 Input: 444 1. 444 - 444 = 0 2. 0 - 0 = 0 Chain length = 2 You should output: 2
Input
The input consists of a sequence of positive numbers, all less than
, each on its own line, terminated by 0. The input file contains at most 10 numbers.
Output
The output only have to print the chain length, no chain will contain more than 1000 distinct numbers.
Note that there is a '\n' at the end of each line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Write a program that simulates a mouse in a maze. The program must count the steps taken by the mouse from the starting point to the final point.
The maze type is shown in following figure:
S$###
$$#$$
$$$##
##$$F
it consists of S (starting point), #(walls), $(road) and F (final point).
In above case, it needs 7 steps from S to F as following figure,
S$###
$$#$$
$$$##
##$$F
and the mouse can move in the four directions: up, down, left, right. There may be more than one way to reach final point, the program only need to print the least steps.
If there is no way from S to F, then print -1.
Input
The first line has an integer N(1<=N<=10^6), which means the number of test cases.
For each case, the first line has two integers. The first and second integers R and C (3<=R, C<=500) represent the numbers of rows and columns of the maze, respectively. The total number of elements in the maze is thus R x C.
The following R lines, each containing C characters, specify the elements of the maze.
Output
Print out the least steps for each case, and there is a new line character at the end of each line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
The kingdom of far worse is in trouble.
The enemies are going to attack kingdom of far worse.
The enemies have map of kingdom of far worse. The map shows that there are exactly some cities.
They are planning to isolate some cities of kingdom of far worse and their method is bomb some roads.
For example, there is a road between city 2 and city 3.
If the position of a bomb is (2, 3), the road from city 2 to city 3 will be destroyed by the bomb but there is still a road from 3 to 2.
The king of kingdom of far worse request you to write a program to show that which city does NOT have road can leave or enter it.
Note:
Below is a real map and its representation of 2-D array. Left-up is (1, 1).

For example of left part.
(1, 4) is 1, means there is a road from 1 to 4.
(4, 3) is 1, means there is a road from 4 to 3
(1, 2).is 0, means there is NO road from 1 to 2.
Input
One number N, N is the number of cities. 2 <= N <= 50
Following is a 2-D array map with N columns and N rows.
One number B, B is the number of bombs. 1 <= B <= N2
Following is B lines, each line is the position of bomb.
Output
Which city does NOT have road can leave or enter it.
The order of number is increasing. Each number is printed by format "%d\n"
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given a bunch of data which are composed of each student’s name, height (cm), and weight (kg), in this problem, you are asked to design a simple system. The operation of the system is described as follows:
Firstly, the instruction 'F' denotes “Find”, which means the system would print out the results containing the keyword for which the user wants to search in lexicographical order of students’ name. Noted that uppercase alphabet is different from lowercase alphabet when finding the keyword. Also, note that if there does not exist the data containing the keyword, the system would output “NOT FOUND”. Secondly, the instruction 'R' denotes “Revision”, which means the user can revise the ith raw/modified data accordingly. Note that if there are repeated student name after revision, the system would delete both sets of the data. Finally, the program terminates if the user enters character ‘E’ no matter in uppercase or lowercase. For instance,
Raw data
Instruction
Since there are two students named Benny after revision, both of the data #2 and data #4 would be automatically deleted by the system. Then, the user uses 'R' to update the data and wants to find whether there is any data containing keyword “70”. If exist, output the results in lexicographical order of students’ name.
Modified data
Output
Note that
1. This problem involves three files.
- function.h: Function definition of Find_Revise.
- function.c: Function describe of Find_Revise.
- main.c: A driver program to test your implementation.
You will be provided with main.c and function.h, and asked to implement function.c.
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.
Hints:
function.h
main.c
Input
1. The first line N is the number of the students, N ≦ 50.
2. The following N lines are sets of data, where length of Name ≦ 8 characters(alphabet), Height is a 3-digits integer, and Weight is a 2-digit integer.
3. The remaining lines are instructions, where instruction 'F' is followed by a string (length ≦ 8), instruction 'R' is followed by a integer representing the ith raw data, Name, Height, and Weight.
Output
1. Each Name in the output takes 10 characters space, each Height and Weight take 8 characters space. (i.e. %-10s......)
2. Note that there is a newline ‘\n’ at the end of each line.
Sample Input Download
Sample Output Download
Partial Judge Code
10899.cPartial Judge Header
10899.hTags
Discuss
Description
Given a matrix A (you can consider it as a 2-D array), print out transpose of A.
Note: Try to use dynamic memory management to finish this problem.
main.c
#include <stdio.h>
#include "function.h"
int main(void) {
int **mat;
int m, n, i;
scanf("%d %d", &m, &n);
mat = allocateMat(m, n);
readInput(mat, m, n);
printResult(mat, m, n);
// Be sure to release acquired memory space
for(i=0; i<m; i++)
free(mat[i]);
free(mat);
return 0;
}
function.h
#ifndef FUNCTION_H #define FUNCTION_H int** allocateMat(int, int); void readInput(int**, int, int); void printResult(int**, int, int); #endif
Input
First line has two integers, indicates A is M rows by N columns. Next M lines are the content of A, each line has N integers.
Output
N lines, each line contains M integers. Values are separated by a blank. There’s a blank and a newline at the end of each line.
Sample Input Download
Sample Output Download
Partial Judge Code
10900.cPartial Judge Header
10900.hTags
Discuss
Description
Given a pointer integer array **ptr with size N, and an integer array *array with size (N+1)*N/2. Please use malloc function to allocate memory to **ptr and *array. The *array is an ascending sequence of number. Each pointer in array **ptr shall point to one element of *array. And the elements pointed by the **ptr are also ascending.
For example, when n = 5, the size of **ptr will be 5, and the size of *array will be 15. The first pointer of **ptr is *ptr[0] which points to array[0], and the second pointer of **ptr is *ptr[1] which points to array[1], and the third pointer of **ptr is *ptr[2] which points to array[3], and the third pointer of **ptr is *ptr[3] which points to array[6].

main.c
function.h
Input
The first line is size of **ptr
The second line is offset
offset < size <10000
Output
Print each pointer of **ptr + offset
Note that you need to print a newline character ‘\n’ after each number, that is, just one number will be shown in each line of the output.