#include <iostream>
using namespace std;
int main()
{
const int arrSize = 3;
string town[arrSize];
int minValue = 0;
int maxValue = 0;
for (int i = 0; i < arrSize; i++)
cout << "Enter " << i + 1 << " town: ";
cin >> town[i];
if (town[i].length() < town[minValue].length())
minValue = i;
if (town[i].length() > town[maxValue].length())
maxValue = i;
}
cout << endl << "The shortest: " << town[minValue] << endl;
cout << "The longest: " << town[maxValue];
return 0;
Код дан в приложении.
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
using namespace std;
int main()
{
const int arrSize = 3;
string town[arrSize];
int minValue = 0;
int maxValue = 0;
for (int i = 0; i < arrSize; i++)
{
cout << "Enter " << i + 1 << " town: ";
cin >> town[i];
if (town[i].length() < town[minValue].length())
minValue = i;
if (town[i].length() > town[maxValue].length())
maxValue = i;
}
cout << endl << "The shortest: " << town[minValue] << endl;
cout << "The longest: " << town[maxValue];
return 0;
}
Код дан в приложении.