CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2020
    Posts
    2

    help, to add greek language support in c++ program

    Hello.I have a program in C++,and test words from wordlist ,to a word game.The program work perfectly,with english words.I want to make it to work with greek words,with a mine greek wordlist.What must be add to the code,to support the greek language?I am new in C++.I search a lot in google without result.if anyone can help, I would appreciate it.

    the code is this:

    Code:
    #include <Windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    main()
    {
    system("chcp 1253");
    
    #include "cursor.cpp"
    #define all(a) a.begin(), a.end()
    #define forn(i,n) for(int i = 0; i < (int) n; i++)
    #define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
    #define x first
    #define y second
    
    using namespace std;
    
    typedef pair<int, int> pii;
    
    /* begin trie */
    struct trie {
      trie(bool e = false): endmarker(e), children( {
        0
      }) {}
      bool endmarker;
      trie* children[26];
    };
    
    bool insert(trie* root, string& s, int i = 0) {
      if (i == s.size() - 1)
        if(root->children[s[i]])
          if (root->children[s[i]]->endmarker)
            return false;
          else {
            root->children[s[i]]->endmarker = true;
            return true;
          }
        else {
          root->children[s[i]] = new trie(true);
          return true;
        }
    
      if (!root->children[s[i]])
        root->children[s[i]] = new trie();
      return insert(root->children[s[i]], s, i + 1);
    }
    /* end trie */
    
    void fix(string& s) {
      forn(i, s.size()) s[i] -= 'a';
    }
    
    vector<vector<int>> board(4, vector<int>(4));
    string decode(vector<pii>& word) {
      string decoded = "";
      for(pii& p : word) decoded += board[p.x][p.y] + 'a';
      return decoded;
    }
    
    void wait() {
      while(!(GetKeyState('Q') & 0x100));
    }
    
    int dx[] = { -1, -1, -1, 0, 1, 1, 1, 0};
    int dy[] = { -1, 0, 1, 1, 1, 0, -1, -1};
    
    int main() {
      /* board position */
    
      POINT tl, br;
      cout << "top left (press Q to mark)?\n";
      wait();
      GetCursorPos(&tl);
      Sleep(300);
      cout << "bottom right (press Q to mark)?\n";
      wait();
      GetCursorPos(&br);
      init(tl, br);
    
      /* BOARD INPUT */
    
      cout << "board state? (input length 16 string)\n";
      string s;
      cin >> s;
      assert(s.size() == 16);
      forn(i, 16) board[i / 4][i % 4] = (s[i] | ' ') - 'a';
    
      /* wordlist input */
    
      ifstream wordlist("wordlist.txt");
      int n;
      wordlist >> n;
      trie *root = new trie();
      forn(i, n) {
        string word;
        wordlist >> word;
        fix(word);
        insert(root, word);
      }
    
      /* get words */
    
      unordered_set<string> donewords;
      vector<vector<pii>> words;
    
      vector<vector<bool>> done(4, vector<bool>(4));
      function<void(trie*, int, int, vector<pii>&)> dfs = [&](trie * root, int x, int y, vector<pii>& word) {
        if (done[x][y]) return;
        if (!root) return;
        if (root->endmarker) {
    
          string decoded = decode(word);
          if (donewords.find(decoded) == donewords.end()) {
            donewords.insert(decoded);
            words.push_back(word);
            cout << "\t" << decoded << "\n";
          }
        }
    
        done[x][y] = 1;
        forn(d, 8) {
          int nx = x + dx[d], ny = y + dy[d];
          if (nx >= 0 && nx < 4 && ny >= 0 && ny < 4) {
            word.push_back({nx, ny});
            dfs(root->children[board[nx][ny]], nx, ny, word);
            word.pop_back();
          }
        }
        done[x][y] = 0;
      };
    
      forn(i, 4) forn(j, 4) {
        cout << "starting at " << i << ", " << j << "\n";
        vector<pii> word{{i, j}};
        dfs(root->children[board[i][j]], i, j, word);
      }
    
      /* input words */
    
      focus();
      Sleep(300);
    
      sort(all(words), [&](const vector<pii>& i, const vector<pii>& j) {
        return i.size() > j.size();
      });
    
      cout << "\n\n";
    
      for(vector<pii>& word : words) {
        if (GetKeyState('E') & 0x100) return 0;
        cout << decode(word) << "\n";
        input_word(word);
        Sleep(35);
      }
    }
    }
    Last edited by 2kaud; July 5th, 2020 at 05:29 AM. Reason: Added code tags

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: help, to add greek language support in c++ program

    Code:
    main()
    {
    system("chcp 1253");
    This doesn't look right?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Jul 2020
    Posts
    2

    Re: help, to add greek language support in c++ program

    yes but it show me an error message:

    bottom right (press Q to mark)?
    init with 277 519
    board state? (input length 16 string)
    ΤΕΛΟΕΠΟΣΞΑΝΑΘΕΟΗ

    Process returned -1073741819 (0xC0000005) execution time : 30.435 s
    Press any key to continue.


    the worldlist txt file is UTF-8
    What is wrong?
    I change only the wordlist file,with greek words.

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: help, to add greek language support in c++ program

    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured