Tip:
May use part of the library functions:
String. The size ()
The vector. The clear ()
The vector. The push_back (STR)
The vector. The size ()
The vector [I]
For example:
Enter
Smith
Tom
Carpenter
Jerry
John
Bob
Kate
Jessie
O
The longest string: Carpenter
The shortest string: Tom, Bob
CodePudding user response:
This is a simple problem, LZ still write myself, there is something wrong with the code to askCodePudding user response:
#include#include
#include
using namespace std;
Vector
Int main () {
String temp;
While (cin & gt;> Temp) {
STR. Push_back (temp);
}
Int indexMin=0, indexMax=0;
For (int I=1; i
IndexMax=I;
If (STR [I]. Length () & lt; STR [indexMin]. Length ())
IndexMin=I;
}
Cout & lt; <"The longest string:" & lt;
}
All the input string under Windows or use Ctrl + D with Ctrl + Z input end under the Linux good