Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <string>
- #include <vector>
- using namespace std;
- void minLexicographical(vector<string>& v) {
- string result = v[0];
- for (auto& el : v) {
- if (result > el) {
- result = el;
- }
- }
- cout << result << endl;
- }
- void minLength(vector<string>& v) {
- string result = v[0];
- for (auto& el : v) {
- if (result.length() > el.length()) {
- result = el;
- }
- }
- cout << result << endl;
- }
- void maxLength(vector<string>& v) {
- string result = v[0];
- for (auto& el : v) {
- if (result.length() < el.length()) {
- result = el;
- }
- }
- cout << result << endl;
- }
- int main()
- {
- string line, word;
- getline(cin, line);
- istringstream ss(line);
- vector<string> words;
- while (ss >> word) {
- words.push_back(word);
- }
- int n;
- cin >> n;
- n == 1 ? minLexicographical(words) : n == 2 ? minLength(words) : maxLength(words);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement