Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <time.h>
- #include <algorithm>
- #include <fstream>
- #include <iostream>
- #include <string>
- #include <utility>
- #include <vector>
- extern "C" int __stdcall MultiByteToWideChar(unsigned int CodePage, unsigned long dwFlags, char const *lpMultiByteStr, int cbMultiByte, wchar_t *lpWideCharStr, int cchWideChar);
- int main()
- {
- clock_t const start = clock();
- using namespace std;
- wstring s;
- {
- string bytes;
- {
- ifstream file("cedict.b5", ios::binary | ios::in);
- file.seekg(0, ios::end);
- bytes.resize(static_cast<size_t>(file.tellg()));
- file.seekg(0, ios::beg);
- file.read(&bytes[0], bytes.size());
- }
- s.resize(static_cast<size_t>(MultiByteToWideChar(950, 0, bytes.data(), static_cast<int>(bytes.size()), NULL, 0)));
- MultiByteToWideChar(950, 0, bytes.data(), static_cast<int>(bytes.size()), &s[0], static_cast<int>(s.size()));
- }
- typedef wstring::const_iterator It;
- typedef pair<It, It> Range;
- vector<pair<pair<Range, Range>, Range> > dict;
- for (It i = s.begin(), end = s.end(); i != end; i = find(i, end, L'\n'), advance(i, i != end))
- {
- if (*i == L'#') { continue; }
- pair<pair<Range, Range>, Range> p;
- p.first.first.first = i;
- p.first.first.second = find(p.first.first.first, end, ' ');
- p.first.second.first = find(p.first.first.second, end, L'[') + 1;
- p.first.second.second = find(p.first.second.first, end, L']');
- p.second.first = find(p.first.second.second, end, L'/');
- p.second.second = find(p.second.first, end, L'\n');
- dict.push_back(p);
- }
- cout << dict.size() << endl;
- cout << clock() - start << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement