:heavy_check_mark: test/String/run_length_encode/local/string.cpp

Depends on

Code

// competitive-verifier: LOCALCASE ./cases/string

#include "String/run_length_encode.hpp"
#include <bits/stdc++.h>

using namespace std;

int main()
{
    string S;
    cin >> S;

    auto rle = run_length_encode(S);

    string ans;
    for (auto [c, n] : rle)
    {
        ans += c + to_string(n);
    }

    cout << ans;

    return 0;
}
#line 1 "test/String/run_length_encode/local/string.cpp"
// competitive-verifier: LOCALCASE ./cases/string

#line 1 "String/run_length_encode.hpp"
#include <bits/stdc++.h>
using namespace std;

template <typename Container>
vector<pair<typename Container::value_type, int>> run_length_encode(const Container &v)
{
    using T = typename Container::value_type;
    vector<pair<T, int>> result;

    for (const auto &n : v)
    {
        if (result.empty() || result.back().first != n)
        {
            result.push_back({n, 0});
        }

        result.back().second++;
    }

    return result;
}
#line 5 "test/String/run_length_encode/local/string.cpp"

using namespace std;

int main()
{
    string S;
    cin >> S;

    auto rle = run_length_encode(S);

    string ans;
    for (auto [c, n] : rle)
    {
        ans += c + to_string(n);
    }

    cout << ans;

    return 0;
}
Back to top page

This site uses Just the Docs, a documentation theme for Jekyll.