Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include <sstream>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. void toFile(fstream &f, string buff) //Функция записи в файл
  11. {
  12. f.open("word.txt");
  13. if (f.fail())
  14. {
  15. cout << "\n Ошибка открытия файла";
  16. exit(1);
  17. }
  18. f << buff;
  19. f.close();
  20. }
  21.  
  22. void FindWord(string s1, string s2, string &word)
  23. {
  24. int szmax = 0, sz;
  25. istringstream iss1(s1), iss2(s2);
  26. string t1, t2;
  27. while (iss1 >> t1)
  28. {
  29. sz = t1.length();
  30. if (sz > szmax)
  31. {
  32. while (iss2 >> t2)
  33. {
  34. if (t1 != t2)
  35. {
  36. word = t1;
  37. szmax = sz;
  38. }
  39. }
  40. }
  41. }
  42. }
  43.  
  44.  
  45. int main()
  46. {
  47.  
  48. setlocale(0, "");
  49. string s1, s2, word;
  50. fstream f;
  51.  
  52. cout << "Введите предложение 1:" << endl;
  53. cin.ignore();
  54. getline(cin, s1);
  55. cout << "Введите предложение 2:" << endl;
  56. cin.ignore();
  57. getline(cin, s2);
  58. FindWord(s1, s2, word);
  59.  
  60. cout << "Искомое слово" << word << endl; //вывод на экран
  61. toFile(f, word); //вывод в файл
  62.  
  63. //cgetch();// system("pause");
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement