| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10389 | Text Editor |
|
| 10889 | Dictionary subsearch |
|
| 10896 | Number Chains |
|
| 10897 | Mouse Maze |
|
| 10899 | Find/Revision |
|
| 10900 | Transpose of A Matrix |
|
| 10903 | Postman |
|
| 11323 | Tile Sticking: Nightmare Version |
|
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 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
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
Collected letters would be classified by zip code. After that, certain postman likes to sort the letters by sender’s name. Here’s an example:
30013 Xiao 10850 Wang
23679 Huang 23679 Huang
24241 Chen -> 24241 Chen
89346 Hsu 30013 Tsai
10850 Wang 30013 Xiao
30013 Tsai 89346 Hsu
Letters would be arranged firstly by zip code, secondly by name once zip codes are the same. Sort the letters with the name by the weight of the string from high to low. The weight of string is defined as following:
Lower case letters: a ~ z corresponds to 1 ~ 26
Upper case letters: A ~ Z corresponds to 2 ~ 27
| letter | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z |
| weight | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| letter | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
| weight | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
For example, the weight of "Allen" is 2 + 12 + 12 + 5 + 14 = 45
Once the zip code and the weight are the same. Dictionary order is used for sorting names. As an example, the weight of “Tsai” and “Xiao” are the same, “T” is previous than “X”, which results the order: 30013 Tsai, 30013 Xiao.
main.c
#include <stdio.h>
#include <stdlib.h>
#include "function.h"
int main(void){
int n;
int i;
Letter *letters;
// Read inputs
scanf("%d", &n);
letters = (Letter*)malloc(sizeof(Letter)*n);
for(i=0; i<n; i++)
scanf("%d %s", &(letters[i].zipcode), letters[i].name);
// Sort the data
qsort((void*)letters, n, sizeof(Letter), compare);
// Output result
for(i=0; i<n; i++)
printf("%d %s\n", letters[i].zipcode, letters[i].name);
free(letters);
return 0;
}
function.h
#ifndef FUNCTION_H
#define FUNCTION_H
typedef struct {
int zipcode;
char name[15];
} Letter;
int compare(const void *, const void *);
#endif
Input
First line is an integer N, number of the letters. The following N lines have an integer, zip code, followed by a name. N is less than 10 million.
Output
Sorted result, N lines, each line contains the zip code and a name separated by a space.
Sample Input Download
Sample Output Download
Partial Judge Code
10903.cPartial Judge Header
10903.hTags
Discuss
Description
Please refer to the 11251 - Tile Sticking problem for detail. In short, you have infinite rectangle tiles of given sizes, and there is an empty area to be filled. You are asked to compute the number of all possible outcomes. But this problem considers the reflection(反射) and rotation(旋轉).
Example
There are two kinds of tiles: AA(1x2) and B(1x1)
The area to be filled: 2x2
There are 3 possible outcomes:
AA
AA,
AA
BB,
BB
BB.
Input
The first line provides an integer, N, which is larger than or equal to 1 and less than 8, indicating the side of the square area that will be filled.
The second line provides an integer, K, that is larger than 1 and less than 5, indicating the amount of types of tiles.
There will be two integers in each of the following K lines, indicating the dimensions of tiles. All integers in this part are larger than 0 and less than 5.
Output
The number of all the possible outcome that can be made.
Note that reflection (up-down, left-right, diagnal) and rotation (90 degree, 180 degree, 270 degree) IS considered. That's why the output of the example is 3 instead of 7.
(7? 2x two As, 4x A and two Bs, and 1x four Bs)