社区讨论
样例国满江红求条闭关
B2121最长最短单词参与者 14已保存回复 28
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 28 条
- 当前快照
- 1 份
- 快照标识符
- @mhjhvz92
- 此快照首次捕获于
- 2025/11/04 02:50 4 个月前
- 此快照最后确认于
- 2025/11/04 06:23 4 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
void findMinMaxWords(const string& sentence){
vector<string> words;
string word;
istringstream iss(sentence);
while(iss>>word){
words.push_back(word);
}
string minWord=words[0];
string maxWord=words[0];
for(size_t i=1;i<words.size();++i){
if(words[i].length()<minWord.length()){
minWord=words[i];
}
if(words[i].length()>maxWord.length()){
maxWord=words[i];
}
}
cout<<maxWord<<endl;
cout<<minWord<<endl;
}
int main(){
string input;
getline(cin,input);
findMinMaxWords(input);
return 0;
}
回复
共 28 条回复,欢迎继续交流。
正在加载回复...