TA的每日心情![](source/plugin/dsu_paulsign/img/emot/kx.gif) | 开心 2024-8-31 15:58 |
---|
签到天数: 89 天 [LV.6]常住居民II
管理员
- 积分
- 3366
|
Example:
(encode-rle-list '(a a a a b c c a a d e e e e))
> ((4 A) B (2 C) (2 A) D (4 E))
[code]#include <iostream>
#include <vector>
#include <variant>
#include <string>
using namespace std;
using Values = vector<variant<int32_t, double_t, wstring>>;
int main()
{
const Values l =
{
L"a", L"a", L"a", L"a", L"b", L"c", L"c", L"a",
L"a", L"d", L"e", L"e", L"e", L"e", 4, 4, 4, 4, 5.75
};
auto i = l.begin(), in = i, e = l.end();
while (in != e) {
auto n = 1;
while (++in != e && *i == *in) {
n++;
i++;
}
if (n == 1)
visit([](auto&& x) {std::wcout << x; }, *i);
else
visit([&](auto&& x) {std::wcout << '(' << n << ' ' << x << ')'; }, *i);
i = in;
}
cin.get();
}
[/code] |
|