| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 12109 | Text Editor 2 |
|
| 12533 | Distance on 2D plane |
|
Description
In this problem we simulate a simple text editor. Given two lines of keyboard input texts and commands, output the final text content.
The text editing rules are defined as following:
1.
Normal alphabetical input and whitespace input (abcdefg…. and ‘ ‘) in the first line.
And a series of two special commands started with a backslash(/) character in the second line.
2.
The backspace command which deletes a letter before the cursor (/b)
3.
The navigating command which move the cursor to the right(/r)
4.
The cursor is at the beginning of the text initially.
For example, for the following input:
The quick brown fox jumps over the lazy dog
/b/r/r/r/b
You should first store the "The quick brown fox jumps over the lazy dog" in the input char array and set cursor=0.
Then you can simulate the operation of the text editor.
The size of the text content is less than or equal to 500 characters, and there will be less than or equal to 500 commands when simulating.
The C library function char *gets(char *str) reads a line from stdin and stores it into the string pointed to by str. It stops when either the newline character is read or when the end-of-file is reached, whichever comes first.
Hint:
#include <stdio.h>
#define MAX_SIZE 1001
char content[MAX_SIZE];
char input[MAX_SIZE];
char command[MAX_SIZE];
int main()
{
gets(input);
gets(command);
/* your code here */
printf("%s", content);
return 0;
}
Input
The first line is the text content which should be edited.
The second line is the commands.
There is always a valid command(/b /r) right after the backslash character.
Output
The final text content, and there should be no '\n' at the end of the output.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
In this problem, you are forced to use structure to record imformation and use afterward.
You will be given several points' locations on 2D plane(x, y), and you should compute the Euclidean distance of specific two points.

(Hint: you can use sqrt() to calculate the square root)

You should implement funcion.c below and submit it. (Due to Partial judge)
#include <stdio.h>
#include <math.h>
#include "function.h"
Point * ones_vec_1(int length)
{
/// Please implement
/// 1. Malloc memory for point array
/// 2. Read values into point array
/// 3. Return the address of the first element in the array
}
float compute_distance(Point* a, int first_id, int second_id)
{
float ans;
Point first_p, second_p;
/// Please implement
/// 1. Get two point from function argument
/// 2. Compute 2D distance and return ans
return ans;
}
You should see .c and .h file below to know how the function and the whole program works
Input
Input may have several lines.
The first line contains an integer M, indicating how many points' locations you should read.
(Notice that the first point is indexed 0, and the second point is indexed 1, and so on...)
And the next M lines , each line has two integers, indicating point's location x and y.
The next line contains an integer N, indicating the number of the pairs of chosen two points.
And the next N lines, each line contains two integers, which are two indices representing two specific points needed to be calculated for Euclidean distance.
Output
Ouput has N lines.
Each line contains a floating number, indicating the Euclidan distance of two specific points.