CppLibrary

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub Tiramister/CppLibrary

:warning: Tools/run_length.hpp

Code

#pragma once

#include <vector>
#include <string>

template <class It>
std::vector<std::pair<typename It::value_type, int>> runlength(
    It begin, It end) {
    using T = typename It::value_type;

    std::vector<std::pair<T, int>> res;
    while (begin != end) {
        const T& c = *(begin++);
        if (res.empty() || c != res.back().first) {
            res.emplace_back(c, 1);
        } else {
            ++res.back().second;
        }
    }

    return res;
}
#line 2 "Tools/run_length.hpp"

#include <vector>
#include <string>

template <class It>
std::vector<std::pair<typename It::value_type, int>> runlength(
    It begin, It end) {
    using T = typename It::value_type;

    std::vector<std::pair<T, int>> res;
    while (begin != end) {
        const T& c = *(begin++);
        if (res.empty() || c != res.back().first) {
            res.emplace_back(c, 1);
        } else {
            ++res.back().second;
        }
    }

    return res;
}
Back to top page