题解 | #最长&最短文本#
最长&最短文本
https://www.nowcoder.com/practice/3331d16fe07d4358858178ff5fa73e0d
#include <bits/stdc++.h> using namespace std; int main() { string s; vector<string>v; while(getline(cin,s)) v.push_back(s); int maxLen = 0,minLen = INT_MAX; for(auto a:v){ if(a.length()>maxLen) maxLen = a.length(); if(a.length()<minLen) minLen = a.length(); } for(auto a:v) if(a.length() == minLen) cout<<a<<endl; for(auto a:v) if(a.length() == maxLen) cout<<a<<endl; // cout<<maxLen<<endl; // cout<<minLen<<endl; } // 64 位输出请用 printf("%lld")
为什么maxLen初始化为INT_MIN或者-1就出bug????????????