Guest User

Chinese-English Dictionary

a guest
Jul 5th, 2013
94
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4.  
  5. #include <algorithm>
  6. #include <fstream>
  7. #include <iostream>
  8. #include <string>
  9. #include <utility>
  10. #include <vector>
  11.  
  12. extern "C" int __stdcall MultiByteToWideChar(unsigned int CodePage, unsigned long dwFlags, char const *lpMultiByteStr, int cbMultiByte, wchar_t *lpWideCharStr, int cchWideChar);
  13.  
  14. int main()
  15. {
  16.     clock_t const start = clock();
  17.     using namespace std;
  18.     wstring s;
  19.     {
  20.         string bytes;
  21.         {
  22.             ifstream file("cedict.b5", ios::binary | ios::in);
  23.             file.seekg(0, ios::end);
  24.             bytes.resize(static_cast<size_t>(file.tellg()));
  25.             file.seekg(0, ios::beg);
  26.             file.read(&bytes[0], bytes.size());
  27.         }
  28.         s.resize(static_cast<size_t>(MultiByteToWideChar(950, 0, bytes.data(), static_cast<int>(bytes.size()), NULL, 0)));
  29.         MultiByteToWideChar(950, 0, bytes.data(), static_cast<int>(bytes.size()), &s[0], static_cast<int>(s.size()));
  30.     }
  31.     typedef wstring::const_iterator It;
  32.     typedef pair<It, It> Range;
  33.     vector<pair<pair<Range, Range>, Range> > dict;
  34.     for (It i = s.begin(), end = s.end(); i != end; i = find(i, end, L'\n'), advance(i, i != end))
  35.     {
  36.         if (*i == L'#') { continue; }
  37.         pair<pair<Range, Range>, Range> p;
  38.         p.first.first.first = i;
  39.         p.first.first.second = find(p.first.first.first, end, ' ');
  40.         p.first.second.first = find(p.first.first.second, end, L'[') + 1;
  41.         p.first.second.second = find(p.first.second.first, end, L']');
  42.         p.second.first = find(p.first.second.second, end, L'/');
  43.         p.second.second = find(p.second.first, end, L'\n');
  44.         dict.push_back(p);
  45.     }
  46.     cout << dict.size() << endl;
  47.     cout << clock() - start << endl;
  48. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×