楽しいプログラミング:ノスタルジア(C ++ 17のレンジバージョン)

#include <iostream>
#include <range/v3/all.hpp>
#include <vector>
#include <locale>
#include <locale.h>
using namespace std;
using namespace ranges;

int main(int argc, const char * argv[]) {
    constexpr char locale_name[] = "en_US.UTF-8";
    setlocale( LC_ALL, locale_name );
    locale::global(locale(locale_name));
    wcout.imbue(locale());
    wstring text = L"床前明月光疑是地上霜举头望明月低头思故乡";
    int offset = 5;
    auto v = text | view::enumerate | to_vector;
    auto v2 =
        action::sort(v, [&](auto& a, auto& b){return pair{a.first % offset, -a.first} < pair{b.first % offset, -b.first};}) |
        view::group_by([&](auto& a, auto& b){return a.first % offset == b.first % offset;}) | to_vector;
    auto rng = v2 | view::transform([](auto& o){
        return o | view::transform([](auto& o2){return o2.second;}) | view::intersperse(L'|');
    });
    for (wstring o : rng)
        wcout << o << endl;
    return 0;
}

/*
低|举|疑|床
头|头|是|前
思|望|地|明
故|明|上|月
乡|月|霜|光
*/

おすすめ

転載: www.cnblogs.com/zwvista/p/10988870.html