Home > Back-end >  [for]/* the input range of six long string according to the length of the sequence output */don'
[for]/* the input range of six long string according to the length of the sequence output */don'

Time:09-24

/* enter 6 differ long string, will be ordered the 6 string according to the length of the string,
And according to the order from long to short output string, */
# include
# include
using namespace std;
Int main ()
{
Char STR [6] [45].
Char c [45];
Int I, j, x, Max.
for(i=0; I<6; I++)
Cin> STR [I];
Cout for (I=0; I<5; I++)
{
Max=I;
For (j=I; J<6; J++)
If (strlen (STR) [j] & gt; Strlen (STR) [I])
Max=j;
Strcpy (c, STR (Max));
Strcpy (STR (Max), STR [I]);
Strcpy (STR [I], c);
}

Coutfor(i=0; I<6; I++)
Coutreturn 0;
}

CodePudding user response:

There is a problem, way of thinking of writing is not quite right

CodePudding user response:

There is something wrong with the didn't see the shrimps, screenshots,

CodePudding user response:

Int main ()
{
Char STR [6] [45].
Char c [45];
Int I, j, Max.
for(i=0; I<6; I++)
Cin> STR [I];
Coutfor(i=0; I<5; I++)
{
Max=I;
For (j=I; J<6; J++)
{
If (strlen (STR) [j] & gt; Strlen (STR) [I])
{
Max=j;
Strcpy (c, STR (Max));
Strcpy (STR (Max), STR [I]);
Strcpy (STR [I], c);
}
}
}
Coutfor(i=0; I<6; I++)
Cout
return 0;
}


So to write to

CodePudding user response:

Should look for the longest string, and c is size, rather than the STR [I]

 
# include
# include
using namespace std;
Int main ()
{
Char STR [6] [45].
Char c [45];
Int I, j, x, Max.
For (I=0; I & lt; 6; I++)
cin> STR [I];
cout For (I=0; I & lt; 5; I++)
{
Max=I;
Strcpy (c, STR (Max));

For (j=I + 1; J & lt; 6; J++)
{
If (strlen (STR) [j] & gt; Strlen (c))
{
Max=j;
Strcpy (c, STR (Max));
}

}

If (I.=Max) {
Strcpy (STR (Max), STR [I]);
Strcpy (STR [I], c);
}
}
cout For (I=0; I & lt; 6; I++)
cout return 0;
}
  • Related