Time limit: 1Sec Memory Limit: 128MB
Title Description
Input and output processing of strings.
The first line is a positive integer N, up to 100, followed by multiple lines (lines larger than N), each of which may contain spaces and no more than 1000 characters.
Output
The first N lines of the input string (which may contain spaces) are output as is, and then the remaining strings (which do not contain spaces) are output sequentially by line with a space or carriage return division. A blank line is output between each line of output.
1
2
3
4
|
2
www.dotcpp.com DOTCPP
A C M
D O T CPP
|
Sample Output
1
2
3
4
5
6
7
8
9
10
11
|
www.dotcpp.com DOTCPP
A C M
D
O
T
CPP
|
C Code
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
|
#include<stdio.h>
int main(){
int N, i;
scanf("%d", &N);
getchar(); //Capture carriage return
char str[N][1000]; //Used to save the first N lines of the string
char extra[1000]; //Used to save additional strings
for(i=0; i<N; i++){ //Loop through each string in a specified number of lines
gets(str[i]);
}
for(i=0; scanf("%c", &extra[i]) != EOF; i++){
//Enter additional strings, one character at a time, when the end of the input (ctrl+Z) input stops, the benefit in the line feed will not terminate the input
}
for(i=0; i<N; i++){
printf("%s\n\n", str[i]);
}
for(i=0; extra[i] != NULL; i++){
if(extra[i] == ' '||extra[i] == '\n'){ //Line break when there are spaces or line breaks in the extra array
printf("\n\n");
continue;
}
printf("%c", extra[i]);
}
return 0;
}
|