Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void tokenize (char * source, char ** tokens, int & size_of_tokens)
- {
- char * token = strtok(source, " ,.!?:-\\\t");
- int size = 0;
- while (token)
- {
- bool found = false;
- for (size_t i=0; i<size; i++)
- {
- if (strcmp(token,tokens[i]) == 0)
- found = true;
- }
- if (!found)
- {
- strcpy (tokens[size], token);
- size++;
- }
- token = strtok(NULL, " ,.!?:-\\\t");
- }
- size_of_tokens = size;
- }
- int common_symb_in_order_cnt (char * str1, char * str2, size_t len)
- {
- int cnt = 0;
- for (int i=0; i<len; i++)
- {
- if (str1[i]==str2[i])
- cnt++;
- }
- return cnt;
- }
- void main()
- {
- const size_t Max_Tokens = 64;
- const size_t Max_Token_Size = 16;
- char ** tokens = new char * [Max_Tokens];
- for (int i=0; i<Max_Tokens; i++)
- {
- tokens [i] = new char [Max_Token_Size];
- }
- char source[] = "You can cut all the flowers but you can not keep Spring from coming.";
- puts (source);
- cout << endl;
- int size = 0;
- tokinize (source, tokens, size);
- for (int i=0; i<size; i++)
- {
- cout << tokens[i] << endl;
- }
- cout << endl;
- const size_t len_word=16;
- char * word = new char [len_word];
- cout << "Input word: ";
- cin.getline(word, len_word);
- size_t fact_word_len = strlen(word);
- int max_symbol_match = 0;
- char * correction = new char [Max_Token_Size];
- for (int i=0; i<size; i++)
- {
- if (strlen(tokens[i])==fact_word_len)
- {
- int symbol_match = common_symb_in_order_cnt(tokens[i], word, fact_word_len);
- if (symbol_match > max_symbol_match)
- {
- max_symbol_match = symbol_match;
- strcpy (correction, tokens[i]);
- }
- }
- }
- cout << correction << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement