Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // task_2.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
- //
- /*
- ПРАВИЛЬНОСТЬ ВВЕДЁННЫХ СЛОВ ИСПОЛЬЗУЯ СЛОВАРЬ. УПОРЯДОЧЕННЫЙ ЛИНЕЙНЫЙ СПИСОК ПО ЗАГОТОВЛЕННОМУ ФАЙЛУ. еСЛИ НА 40% И БОЛЬШЕ СОВПАДАЕТ, ТО КОМП КОРРЕКТИРУЕТ
- ИНАЧЕ ГОВОРИТ ШО ВСЁ НЕ ТО.
- */
- #include "pch.h"
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- struct List
- {
- string data;
- List *next;
- };
- List *makeList()
- {
- ifstream file("C:\\Users\\Владимир\\source\\repos\\task_2\\dictionary.txt");
- List *first = new List;
- List *next = new List;
- first->next = nullptr;
- while (!file.eof())
- {
- if (first->next == nullptr)
- {
- file >> first->data;
- first->next = next;
- }
- else
- {
- next->next = new List;
- file >> next->data;
- next = next->next;
- }
- }
- if (file.eof())
- next->next = nullptr;
- return first;
- }
- void correctWord(string input, List *list)
- {
- List *p = list;
- short difference=0;
- float diffPer = 0;
- bool ok = false;
- while (p&&!ok)
- {
- if (input == p->data)
- {
- cout << "OK";
- ok = true;
- }
- else
- p = p->next;
- }
- p = list;
- while (p && !ok)
- {
- if (!ok&&input.length() == p->data.length())
- {
- for (int i = 0; i < input.length(); i++)
- if (input[i] != (char)p->data[i])
- difference++;
- diffPer = difference / (float)input.length();
- if (diffPer <= 0.6f)
- {
- cout << p->data << "\n";
- ok = true;
- }
- diffPer = 0;
- difference = 0;
- }
- p = p->next;
- }
- if (!ok) cout << "не ОК";
- }
- void Print(List *fList)
- {
- List *list = fList;
- cout << "List:" << endl;
- while (list)
- {
- cout << list->data << endl;
- list = list->next;
- }
- }
- int main()
- {
- setlocale(0, "");
- string input;
- cout << "слово: "; cin >> input;
- ///*
- List *first = makeList();
- Print(first);
- correctWord(input, first);
- //*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement