Home > Back-end >  For help, the topic is "write print words in its input the length of the histogram", I pla
For help, the topic is "write print words in its input the length of the histogram", I pla

Time:10-10

#include
# define MAXWORD 15
# define IN 1
# define OUT 0
The main ()
{
Int c, wl [16], I, state=OUT, overflow=0, numin=0, num=0;
While ((c=getchar ())!=(EOF)
{
For (I=0; i <=MAXWORD; I + +)
Wl [I]=0;
If (c=='| | c==' \ t '| | c==' \ b)
{
If (state==IN)
If (I & lt;=MAXWORD)
Wl [I] + +;
Else if (I & gt; MAXWORD)
Overflow + +;

Putchar (NULL);
}

Else if (state==OUT)
{
I + +;
State=IN;
}
The else
I + +;
}

For (int h=1; H & lt;=MAXWORD; H + +)
{
For (; Wl [h] & gt; 0; Wl [h] -)
{
Numin + +;
Num + +;
}
Printf (" % d in length by the number of words for % d \ t: ", h, numin);
For (int p=1; P & lt; Num=)
Putchar (' * ');
Printf (" \ n ");
}
If (overflow & gt; 0)
Printf (" % d words are more than the "maximum, overflow);
}

CodePudding user response:

The maximum length is how many? 15?

Is there a limit number of words?

CodePudding user response:

There is no limit to the number the maximum length of 15,

CodePudding user response:

#include
# define MAXWORD 15
# define IN 1
# define OUT 0

Int main () {
Int c, wl [16], I, state=OUT, overflow=0;

//move from while inside the
For (I=0; i <=MAXWORD; I + +) wl [I]=0;

i=0;
While ((c=getchar ())!=(EOF)
{
If (c=='\ b) {//this is delete one character at a time before
If (I) (I) -;
} else if (c=='| | c==' \ t '| | c==' \ n ') {
If (state==) IN {
If (I & lt;=MAXWORD)
Wl [I] + +;
The else
Overflow + +;
}
//after word segmentation, state to instead the out, and the length counting to qing 0
State=OUT;
I=0;
} else {
//the previous two if can be merged into one, has been in, continue to set it in
I + +;
State=IN;
}
}
//the last exit is Ctrl + z, at this time I also length to statistical
If (I & lt;=MAXWORD)
Wl [I] + +;
The else
Overflow + +;
printf("\n");
For (int h=1; H & lt;=MAXWORD; H++)
{
//the original num, min what is all useless, output directly by the
Printf (" % d in length by the number of words for % d \ t: ", h, wl [h]);
For (int p=1; P & lt;=wl [h]; P++) putchar (' * ');
Printf (" \ n ");
}
If (overflow & gt; 0)
Printf (" % d words are more than the maximum \ n ", overflow);
return 0;
}

CodePudding user response:

 # include & lt; Stdio. H> 
Int main ()
{
Char c [1000]={0}, c1;
Int a [100]={0}, [16] b={0};
Int I, j, k=0, l;
for(i=0; i<1000; I++)
{
[I] c=getchar ();
If (c [I]=='\ n')
break;
}
for(j=0; j{
If (c [j]==' ')
{
If (c [j + 1)!=' ')
{
printf("\n");
K++;
}
If (c [j + 1)==' '& amp; & C + 2 [j]==' ')
j++;
}
The else
{
Printf (" * ");
A [k] + +;
}
}
printf("\n");
for(i=0; i{
for(j=0; j<16. J++)
{
If (a==[I] j + 1)
B [j] + +;
}
If (a [I] & gt; 15)
B [15] + +;
}
for(j=0; j<15. J++)
{
If (b [j].=0)
Printf (" % d in length by the number of words for % d \ n ", j + 1, b [j]);
}
Printf (" go beyond the limit of words % d ", b [15]);
return 0;
}

It might be a little trouble

CodePudding user response:

 for (int p=1; P & lt; Num=) 
Putchar (' * ');
Printf (" \ n ");
}

This a few lines of code or the loop body does not perform, even may be an infinite loop,
  • Related