fork download
  1.  
  2.  
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <string>
  6. #include <vector>
  7. using namespace std;
  8.  
  9. string shortest_string(vector<string> strings) {
  10. string shortest = strings[0];
  11.  
  12. for (int i = 1; i < strings.size(); i++) {
  13. if (strings[i].length() < shortest.length()) {
  14. shortest = strings[i];
  15. }
  16. }
  17.  
  18. return shortest;
  19. }
  20.  
  21. int main() {
  22. int n;
  23. cout << "Enter number of strings ";
  24. cin >> n;
  25.  
  26. vector<string> strings(n);
  27.  
  28. cout << "Enter the strings:" << endl;
  29. for (int i = 0; i < n; i++) {
  30. cin >> strings[i];
  31. }
  32.  
  33. cout << "Shortest string is -> " << shortest_string(strings);
  34. return 0;
  35.  
  36. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Enter number of strings Enter the strings:
Shortest string is ->