String input and output processing-cyclically receive and process the typed string with spaces

String input and output processing

Input The
first line is a positive integer N, the maximum is 100. After that is a multi-line string (the number of lines is greater than N), each line of the string may contain spaces and the number of characters does not exceed 1000.

Output
First output the first N lines of character strings (which may contain spaces) in the input as they are, and then output the remaining character strings (without spaces) separated by spaces or carriage returns in order of lines. A blank line is output between each line of output.

Sample input
2
www.dotcpp.com DOTCPP
ACM
DOT CPP

Sample output
www.dotcpp.com DOTCPP

A C M

D

O

T

CPP

#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
    
    
    int i=0,j,N,len;
    char str[1000];
    char c;
    scanf("%d\n",&N);
    while(scanf("%[^\n]%c",str,&c)!=EOF)
    {
    
    //%[^\n]接收包括空格在内的字符
     //%c用于消化'\n'
        i++;
        if(i<=N)
            printf("%s\n\n",str);
        else
        {
    
    
            len=strlen(str);
            for(j=0;j<len;j++)
            {
    
    
                if(str[j]==' ')
                    printf("\n\n");
                else
                    printf("%c",str[j]);
            }
            printf("\n\n");
        }
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_44378854/article/details/112793188