Advertisement
szubert

lab 6

Jun 3rd, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5.  
  6.  
  7. int levenshtein(string const a, string const  b) {
  8.     int lengthA = a.length(), lengthB = b.length;
  9.     int d[lengthA + 1][lengthB + 1];
  10.  
  11.     for (int i = 0; i <= lengthA; i++)
  12.         for (int j = 0; j <= lengthB; j++)
  13.             d[i][j] = -1;
  14.  
  15.     int dist(int i, int j) {
  16.         if (d[i][j] >= 0) return d[i][j];
  17.  
  18.         int x;
  19.         if (i == lengthA)
  20.             x = lengthB - j;
  21.         else if (j == lengthB)
  22.             x = lengthA - i;
  23.         else if (s[i] == t[j])
  24.             x = dist(i + 1, j + 1);
  25.         else {
  26.             x = dist(i + 1, j + 1);
  27.  
  28.             int y;
  29.             if ((y = dist(i, j + 1)) < x) x = y;
  30.             if ((y = dist(i + 1, j)) < x) x = y;
  31.             x++;
  32.         }
  33.         return d[i][j] = x;
  34.     }
  35.     return dist(0, 0);
  36. }
  37.  
  38. int main()
  39. {
  40.  
  41.     using namespace std;
  42.  
  43.     int stop = 0;
  44.     ifstream dictionary;
  45.     dictionary.open ("wrt.dic");
  46.     ifstream text;
  47.     text.open ("ocr_output.txt");
  48.  
  49.     string buffer;
  50.     string wordFromDict;
  51.     dictionary.Replace("\n", "\r\n");
  52.  
  53.     while (text >> buffer)
  54.     {
  55.         if (buffer.length() > 1){
  56.             cout<< buffer << '\n';
  57.             while (dictionary >> wordFromDict) {
  58.                 if (wordFromDict == buffer) {
  59.                     stop = 1;
  60.                 }
  61.             }
  62.  
  63.         }
  64.     }
  65.     if(text.eof()){
  66.     cout << "End of file \n";
  67.     }
  68.  
  69.     text.close();
  70.     dictionary.close();
  71.  
  72.     return 0;
  73.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement