Ytu 2574: Blank formatting

Source: Internet
Author: User
Tags printf
2574: Blank formattingTime limit: 1 Sec memory limit: MB
Submissions: 233 Resolution: 118
Title Description

Congratulations on entering the Blue Bridge Cup finals, this competition uses the automatic machine evaluation system.

If you have a gap between your answers and the standard answer, you may not be able to score, so be extra cautious.

But you don't have to be too alarmed. Because in some cases, the evaluation system will "blank format" your answer. This is done by removing all the blanks, and replacing the middle one with a single space. The so-called Blank refers to: space, tab, carriage return.

The following code implements this functionality. Read the code carefully, fill in the missing parts, and add the complete to make it work.

void f (char* from, char* to)

{

char* p_from = from;

char* p_to = to;

while (*p_from== ' | | | *p_from== ' \ t ' | | *p_from== ' \ n ') p_from++;

do{

if (*p_from== ' | | | *p_from== ' \ t ' | | *p_from== ' \ n ') {

do{p_from++;} while (*p_from== ' | | | *p_from== ' \ t ' | | *p_from== ' \ n ');

if (____________________) *p_to++ = "; Fill in the blanks

}

}while (*p_to++ = *p_from++);

} Input

One line of code, not a standard format. Output

The standard form of the output code. Sample Input

      char*        p_from = from     ;    
Sample Output
char* p_from = from;
Tips

The standard format of the code is that there are no spaces at the end of the line, there should be only one space in the middle where there are no more. lost in the valley of the birds, flying alone in the vast world, but do not know where they should fly ...

#include <stdio.h> int main () {void F (char* from, char* to);
    Char pf[1000],pt[1000];
    Char *pff=pf,*ptt=pt;
        while (~SCANF ("%s", pf)) {f (PFF,PTT);
    printf ("%s", PT);
    } printf ("\ n");
return 0;     } void F (char* from, char* to) {char* P_from = from;//assigns a value to the pointer, where P_from is the start char* p_to = to;       P_to for End while (*p_from== ' | | | *p_from== ' \ t ' | | *p_from== ' \ n ') p_from++;
        The first character, when the pointer refers to a space or tab or newline do {//when the pointer refers to a space or tab or a newline, the pointer moves backwards//if it is not a space or tab or line wrap, P_to=p_from, and both move backwards
            if (*p_from== ' | | | *p_from== ' \ t ' | | *p_from== ' \ n ') {do {p_from++;
            } while (*p_from== ' | | | *p_from== ' \ t ' | | *p_from== ' \ n ');
            When the pointer refers to a space or tab or wrap, the pointer moves backwards if (*p_from!= ' &&*p_from== ' \ t ' && *p_from== ' \ n ') *p_to++ = '; When the pointer content is not empty, make the p_to pointer record P_from's address}} while (*p_to++ = *p_from++); Loop when *p_to is not empty}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.