#include <cstdio> // for printf, sprintf.
#include <cstdlib> // for EXIT_FAILURE
#include <tchar.h> // for _T.
#include <Windows.h> // for MessageBox.
#include <vector> // for vector.
/*
実行方法:
cmd /u /c "dir /b" > "unique.txt"
test.exe < "unique.txt"
*/
int main()
{
std::vector<char> kuso;
int ch;
while ( ch = std::fgetc(stdin), ch != EOF )
{
kuso.push_back(ch);
}
if ( (kuso.size() % 2) != 0 )
{
_tprintf(_T("Oops...\n"));
return EXIT_FAILURE;
}
TCHAR msg[100];
_stprintf(msg, _T("%02X %02X %02X %02X"), kuso[0], kuso[1], kuso[2], kuso[3]);
::MessageBox(nullptr, msg, nullptr, 0); // 21 9D ....
std::vector<wchar_t> buri;
auto kuso_size = kuso.size();
for ( auto i = 0; i < kuso_size; i += 2 )
{
auto wch = ((kuso[i + 1] & 0xFF) << 8) | (kuso[i] & 0xFF);
buri.push_back(static_cast<wchar_t>(wch));
}
buri.push_back(wchar_t()); // NUL terminated.
_stprintf(msg, _T("%04X %04X %04X %04X"), buri[0], buri[1], buri[2], buri[3]);
::MessageBox(nullptr, msg, nullptr, 0); // 219D ....
::MessageBoxW(nullptr, buri.data(), L"unkoo", 0);
}
I2luY2x1ZGUgPGNzdGRpbz4gICAgLy8gZm9yIHByaW50Ziwgc3ByaW50Zi4KI2luY2x1ZGUgPGNzdGRsaWI+CS8vIGZvciBFWElUX0ZBSUxVUkUKI2luY2x1ZGUgPHRjaGFyLmg+CS8vIGZvciBfVC4KI2luY2x1ZGUgPFdpbmRvd3MuaD4JLy8gZm9yIE1lc3NhZ2VCb3guCiNpbmNsdWRlIDx2ZWN0b3I+CS8vIGZvciB2ZWN0b3IuCgovKgoK5a6f6KGM5pa55rOVOgpjbWQgL3UgL2MgImRpciAvYiIgPiAidW5pcXVlLnR4dCIKdGVzdC5leGUgPCAidW5pcXVlLnR4dCIKCiovCgppbnQgbWFpbigpCnsKCXN0ZDo6dmVjdG9yPGNoYXI+IGt1c287CgoJaW50IGNoOwoJd2hpbGUgK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