-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShortestWord.cpp
More file actions
50 lines (46 loc) · 869 Bytes
/
ShortestWord.cpp
File metadata and controls
50 lines (46 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
#include<algorithm>
#include<vector>
#include <array>
#include<cmath>
#include <string>
#include <unordered_set>
#include <cctype>
using namespace std;
/* if (str.size()-1 != ' '&& counttemp == count)
{
str.push_back(' ');
} */
int find_short(string str)
{
if (str[str.size()] != ' ')
{
str.push_back(' ');
}
int count = numeric_limits<int>::max();
int counttemp = 0;
for (int i = 0; i < str.size(); i++)
{
if (str[i] != ' ')
{
counttemp++;
}
else {
if (counttemp < count)
{
count = counttemp;
}
counttemp = 0;
}
}
return count;
}
int main()
{
cout << find_short("Let's travel abroad shall we");
return 0;
}
/*Description:
Simple, given a string of words, return the length of the shortest word(s).
String will never be empty and you do not need to account for different data types.
Fundamentals*/