-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP58.cpp
More file actions
35 lines (30 loc) · 680 Bytes
/
P58.cpp
File metadata and controls
35 lines (30 loc) · 680 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
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
#include<stack>
using namespace std;
class Solution {
public:
int lengthOfLastWord(string s) {
string::reverse_iterator v,e;
if (s.empty()) return 0;
e=s.rbegin();
while (e!=s.rend() && *e==' ') e++;
for (v=e;v!=s.rend()&&*v!=' ';++v);
return distance(e,v);
}
};
static const auto io_sync_off = []()
{
// turn off sync
std::ios::sync_with_stdio(false);
// untie in/out streams
std::cin.tie(nullptr);
return nullptr;
}();
int main() {
auto res = Solution().lengthOfLastWord("world");
cout << res <<endl;
return 0;
}