Advertisement
SkeptaProgrammer

Untitled

Oct 6th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. // task_2.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
  2. //
  3. /*
  4.     ПРАВИЛЬНОСТЬ ВВЕДЁННЫХ СЛОВ ИСПОЛЬЗУЯ СЛОВАРЬ. УПОРЯДОЧЕННЫЙ ЛИНЕЙНЫЙ СПИСОК ПО ЗАГОТОВЛЕННОМУ ФАЙЛУ. еСЛИ НА 40% И БОЛЬШЕ СОВПАДАЕТ, ТО КОМП КОРРЕКТИРУЕТ
  5.     ИНАЧЕ ГОВОРИТ ШО ВСЁ НЕ ТО.
  6. */
  7.  
  8. #include "pch.h"
  9. #include <iostream>
  10. #include <string>
  11. #include <fstream>
  12. using namespace std;
  13.  
  14. struct List
  15. {
  16.     string data;
  17.     List *next;
  18. };
  19.  
  20. List *makeList()
  21. {
  22.     ifstream file("C:\\Users\\Владимир\\source\\repos\\task_2\\dictionary.txt");
  23.     List *first = new List;
  24.     List *next = new List;
  25.     first->next = nullptr;
  26.     while (!file.eof())
  27.     {
  28.         if (first->next == nullptr)
  29.         {
  30.             file >> first->data;
  31.             first->next = next;
  32.         }
  33.         else
  34.         {
  35.             next->next = new List;
  36.             file >> next->data;
  37.             next = next->next;
  38.         }
  39.     }
  40.     if (file.eof())
  41.         next->next = nullptr;
  42.     return first;
  43. }
  44.  
  45. void correctWord(string input, List *list)
  46. {
  47.     List *p = list;
  48.     short difference=0;
  49.     float diffPer = 0;
  50.     bool ok = false;
  51.     while (p&&!ok)
  52.     {
  53.         if (input == p->data)
  54.         {
  55.             cout << "OK";
  56.             ok = true;
  57.         }
  58.         else
  59.             p = p->next;
  60.     }
  61.     p = list;
  62.     while (p && !ok)
  63.     {
  64.         if (!ok&&input.length() == p->data.length())
  65.         {
  66.             for (int i = 0; i < input.length(); i++)
  67.                 if (input[i] != (char)p->data[i])
  68.                     difference++;
  69.             diffPer = difference / (float)input.length();
  70.             if (diffPer <= 0.6f)
  71.             {
  72.                 cout << p->data << "\n";
  73.                 ok = true;
  74.             }
  75.             diffPer = 0;
  76.             difference = 0;
  77.         }
  78.         p = p->next;
  79.     }
  80.     if (!ok) cout << "не ОК";
  81.  
  82. }
  83.  
  84. void Print(List *fList)
  85. {
  86.     List *list = fList;
  87.     cout << "List:" << endl;
  88.     while (list)
  89.     {
  90.         cout << list->data << endl;
  91.         list = list->next;
  92.     }
  93.  
  94. }
  95. int main()
  96. {
  97.     setlocale(0, "");
  98.     string input;
  99.     cout << "слово: "; cin >> input;
  100.     ///*
  101.     List *first = makeList();
  102.     Print(first);
  103.     correctWord(input, first);
  104.     //*/
  105.     return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement