📄 3-4.cpp
字号:
#include<vector>
#include<iostream>
#include<string>
using std::cin; using std::cout;
using std::endl; using std::string;
using std::vector;
int main()
{
cout << "Please enter in some words:" << endl;
string word;
vector<string> words;
while (cin >> word)
words.push_back(word);
vector<double>::size_type value = words.size();
string::size_type maxsize = words[0].size();
int max = 0;
for(int n = 0;n != value - 1;n++) {
if(words[n].size() > maxsize) {
maxsize = words[n].size();
max = n;
}
}
string::size_type minsize = words[0].size();
int min = 0;
for(int m = 0;m != value - 1;m++) {
if(words[m].size() < minsize) {
minsize = words[m].size();
min = m;
}
}
cout << endl;
cout << "The longest word is " << words[max] << '.'
<< "The length is " << maxsize << endl;
cout << "The shortest word is " << words[min] << '.'
<< "The length is " << minsize << endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -