标签:argc fir lob const vector oca clu empty first
#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 ranges::accumulate(o, wstring{}, [](auto& acc, auto& e){return acc + (acc.empty() ? L"" : L"|") + e.second;});
});
for (auto o : rng)
wcout << o << endl;
return 0;
}
/*
低|举|疑|床
头|头|是|前
思|望|地|明
故|明|上|月
乡|月|霜|光
*/
标签:argc fir lob const vector oca clu empty first
原文地址:https://www.cnblogs.com/zwvista/p/10988870.html