Home > Back-end >  Pure new inquire a problem C programming problem
Pure new inquire a problem C programming problem

Time:10-10

To write program to find the shortest and longest in the input string,
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 ask

CodePudding user response:

#include
#include
#include
using namespace std;
Vector STR;

Int main () {
String temp;
While (cin & gt;> Temp) {
STR. Push_back (temp);
}
Int indexMin=0, indexMax=0;
For (int I=1; iIf (STR [I]. Length () & gt; STR [indexMax]. Length ())
IndexMax=I;
If (STR [I]. Length () & lt; STR [indexMin]. Length ())
IndexMin=I;
}
Cout & lt; <"The longest string:" & lt; Cout & lt; <"The shortest string:" & lt; return 0;
}
All the input string under Windows or use Ctrl + D with Ctrl + Z input end under the Linux good
  • Related