Home > Back-end >  The PTA 7-2 ironic - enhanced
The PTA 7-2 ironic - enhanced

Time:10-04

Given a word of English, you are asked to write programs, to reverse the order of the all the words in a clause output,
Input format:
Test inputs include a test case, within a row gives the total length of not more than 500 000 string, the string is made up of a number of words and a number of Spaces, the word is composed of English letters (case have distinguish) strings, separated by several Spaces between words,
The output format:
Output a single line of each test case, output after the sentence, in reverse chronological order and ensure that only one space between words,
Input the sample:
Hello World Here I last Come
The output sample:
Last Come I Here World Hello


#include
# define M 500000
Int main ()
{
Char s [M], [M]. B
Int I, k, j, h=0;
K=0;
While ((s [k]=getchar ())! )
='\ n'K++;
S [k]='\ 0';
K=k + 1;
For (I=k; i> 0; I -)
{
S=s [I] [I - 1);
}
S [0]=' ';

J=0;

For (I=k - 1; i>=0; I -)
{
If (s [I]!=' ')
{
j++;
B [j] [I]=s;
}
Else if (j!=0)
{
For (h=j; H> 0; H -)
{
Printf (" % c "[h]. B);
}
If (I.=0)
Printf (" ");
J=0;
}
}
return 0;
}

Why I have been wrong? A small point, poor format problem, ask for help!

CodePudding user response:

 # include 

//# define M 500000
# define M 512

Int main ()
{
Char s [M];//, b [M].
Int CNT, I, j, k;
//int I, k, j, h=0;
K=0;
While (k & lt; M - 1 & amp; & (s [k]=getchar ())! )
='\ n'K++;
S [k]='\ 0';

CNT=0;
For (I=k - 1; I & gt;=0; I -) {
If (s==[I] '& amp; & S [I + 1)!=' ') {
For (j=I + 1; J & lt; I + 1 + CNT; J++)
Putchar (s) [j];
If (CNT & gt; 0)
Putchar (");
CNT=0;
}
If (s [I]!=' ')
Cnt++;
}
For (j=I + 1; J & lt; I + 1 + CNT; J++)
Putchar (s) [j];

Putchar (10);


# if 0
K=k + 1;
For (I=k; i> 0; I -)
{
S=s [I] [I - 1);
}
S [0]=' ';

J=0;

For (I=k - 1; i>=0; I -)
{
If (s [I]!=' ')
{
j++;
B [j] [I]=s;
}
Else if (j!=0)
{
For (h=j; H> 0; H -)
{
Printf (" % c "[h]. B);
}
If (I.=0)
Printf (" ");
J=0;
}
}
# endif
return 0;
}

For your reference ~
  • Related