?? 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 + -