“Line Reader” is a program that shows only one line of the input article (which is composed by many lines of strings).
Initially, it shows the first line of the article.
Users can control the Line Reader by four commands.
1. u : show the previous line of the current line. If the current line is the 15th line, Line Reader will show the 14th line.
2. d : show the next line of the current line. If the current line is the 15th line, Line Reader will show the 16th line.
3. U : show the 10th line previous to the current line. If the current line is the 15th line, Line Reader will show the 5th line.
4. D : show the 10th line next to the current line. If the current line is the 15th line, Line Reader will show the 25th line.If the line number is less than 1, the Line Reader will show the first line.
If the line number is larger than the total number of lines in the article, the Line Reader will show the last line.
If the line number is smaller than 0 in the article, the Line Reader will show the first line.
For example,
if the current line is the 15th line, and the total number of lines in the article is 20,
after the command D, the Line Reader will show the 20th line.
HINT:
#includeint main(){ int n, m; int i, now; char arr[20][31]; char *str; char ins; scanf( "%d", &n ); for( i = 0 ; i < n ; i++ ){ scanf( "%s", arr[i] ); } //Insert your code here to get commands and execute them return 0; }
N lines of strings
String 1
String 2
String 3
...
String N
M lines of commands
Command 1
Command 2
Command 3
...
Command M
where 1 ≤ N,M ≤ 20
The length of string is less than or equal to 30 and the string doesn't include any whitespace character.
Show the string after applying command 1
Show the string after applying command 2
Show the string after applying command 3
...
Show the string after applying command M
Each end of strings has a newline symbol