-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgangur.cpp
65 lines (51 loc) · 1.43 KB
/
gangur.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* @file gangur.cpp
* @author William Weston
* @brief Gangur Problem From Kattis
* @version 0.1
* @date 2023-09-19
*
* @copyright Copyright (c) 2023
*
* Link: https://open.kattis.com/problems/gangur
*/
#include <algorithm> // count
#include <cstdlib>
#include <iostream>
#include <iterator> // next
#include <string>
#include <vector>
constexpr auto right = '>';
constexpr auto left = '<';
auto get_passes( std::string const& hallway ) -> std::vector<unsigned long long>;
auto
main() -> int
{
auto const hallway = [] { std::string tmp; std::getline( std::cin, tmp ); return tmp; }();
auto const passes = get_passes( hallway );
auto total_passes = 0ull;
for ( auto pos = hallway.find( right, 0 ); pos != std::string::npos; pos = hallway.find( right, pos + 1 ) )
{
total_passes += passes[pos];
}
std::cout << total_passes << '\n';
return EXIT_SUCCESS;
}
auto
get_passes( std::string const& hallway ) -> std::vector<unsigned long long>
{
auto passes = std::vector<unsigned long long>( hallway.size(), 0 );
auto passes_rbegin = passes.rbegin();
auto hallway_rbegin = hallway.rbegin();
auto const hallway_rend = hallway.rend();
auto count = 0ull;
for ( ; hallway_rbegin != hallway_rend; ++passes_rbegin, ++hallway_rbegin )
{
if ( *hallway_rbegin == left )
{
++count;
}
*passes_rbegin = count;
}
return passes;
}