首页 > 试题广场 >

最长&最短文本

[编程题]最长&最短文本
  • 热度指数:9889 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
输入多行字符串,请按照原文本中的顺序输出其中最短和最长的字符串,如果最短和最长的字符串不止一个,请全部输出。

输入描述:
输入包括多行字符串,字符串的长度len(1<=len<=1000)。


输出描述:
按照原文本中的顺序输出其中最短和最长的字符串,如果最短和最长的字符串不止一个,请全部输出。
示例1

输入

hello
she
sorry
he

输出

he
hello
sorry
头像 燃烧的橘子
发表于 2023-02-26 21:30:56
#include <iostream> #include <string> #include<vector> using namespace std; int main() { vector<string>v; string str; 展开全文
头像 KDDA十三尧十三
发表于 2022-01-26 13:46:24
#include<iostream> #include<vector> #include<algorithm> #include<cstring> using namespace std; bool cmp(const&n 展开全文
头像 wbc990512
发表于 2021-01-26 16:29:39
思路:读一次字符串确定最短长度和最长长度用两个for循环依次遍历所有字符串,第一个for先输出最短长度的,第二个for再输出最长长度的 #include<stdio.h> #include<string.h> int main() { char str[1000][ 展开全文
头像 牛客440904392号
发表于 2024-10-03 19:04:05
s = [] while True: try: s.append(input()) except: s.sort(key=lambda x: len(x)) min_len = len(s[0]) max_len = l 展开全文
头像 semaxcong
发表于 2023-02-21 09:08:48
#include<iostream> #include<string> #include<map> using namespace std; int main(){ string str; multimap<int,string> 展开全文
头像 在考古的小鱼干很有气魄
发表于 2023-03-08 09:55:59
#include <bits/stdc++.h> #define MAX 1000 using namespace std; int main(){ string data[MAX],n; int len = 0; int maxSize = -1,minSize = MAX; 展开全文
头像 在offer比较的我很能干
发表于 2023-02-28 18:01:41
#include <iostream> #include <vector> #include <string> #include<unordered_map> using namespace std; int main() { string 展开全文
头像 慢热的沸羊羊在创作
发表于 2024-07-17 14:44:06
#include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; bool cmp(pair<string,int> 展开全文
头像 爱吃的懒羊羊离上岸不远了
发表于 2025-03-17 16:48:59
#include <iostream> #include <cstring> #include <algorithm> #include <cmath> #include <vector> #include <string> u 展开全文
头像 牛客745135892号
发表于 2024-03-05 23:06:29
#include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; bool cmp(string &s1, string 展开全文