Guest User

Untitled

a guest
Nov 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #include "pch.h"
  2. #pragma hdrstop
  3. #pragma argsused
  4. #define _CRT_SECURE_NO_WARNINGS
  5. #define _CRT_SECURE_NO_DEPRECATE
  6. #define _CRT_NONSTDC_NO_DEPRECATE
  7. #pragma warning(disable : 4996)
  8.  
  9. #ifdef _WIN32
  10. #include <tchar.h>
  11. #else
  12. typedef char _TCHAR;
  13. #define _tmain main
  14. #endif
  15. #include <iostream>
  16. #include "pch.h"
  17. #include <iostream>
  18. #include <sstream>
  19. #include <fstream>
  20. #include <string>
  21. #include <cstdlib>
  22. #include <Windows.h>
  23.  
  24. using namespace std;
  25.  
  26. inline bool isVozrastanieww(const string& str)
  27. {
  28. return str == string(str.crbegin(), str.crend());
  29. }
  30.  
  31. bool isVozrastanie(const string& s)
  32. {
  33. char * str = new char[s.length() + 1];
  34. strcpy(str, s.c_str());
  35. char *word = strtok(str, ",./?;:");
  36. for (int i = 0; i < strlen(word) - 1; i++)
  37. {
  38. if (int(word[i]) < int(word[i + 1]))
  39. return true;
  40. else
  41. return false;
  42. }
  43.  
  44.  
  45.  
  46. delete[] str;
  47. }
  48.  
  49. int main()
  50. {
  51. setlocale(LC_ALL, ".1251");
  52.  
  53. int max = 0, k;
  54. string s, MaxStr;
  55.  
  56. ifstream fin("input.txt"); //открыли файл для чтения
  57. if (!fin.is_open()) {
  58. cout << "Файл не может быть открыт" << endl;
  59. system("pause");
  60. return 1;
  61. }
  62. if (fin.peek() == EOF) {
  63. cout << "Файл пустой" << endl;
  64. system("pause");
  65. return 1;
  66. }
  67.  
  68. fin.clear();
  69. fin.seekg(0);
  70.  
  71. while (getline(fin, s))
  72. {
  73. istringstream ist(s);
  74. {
  75. size_t MaxLength(0);
  76. for (string temp; ist >> temp;)
  77. if (isVozrastanie(temp) && temp.size() > MaxLength)
  78. MaxStr = temp, MaxLength = temp.size();
  79. }
  80.  
  81.  
  82. }
  83. k = MaxStr.size();
  84. cout << "Строки, содержащие максимальную по длине возрастающую подстроку " << endl;
  85. fin.clear();
  86. fin.seekg(0);
  87. while (getline(fin, s))
  88. {
  89. istringstream ist2(s);
  90. {
  91. for (string temp2; ist2 >> temp2;) {
  92. if (isVozrastanie(temp2) && temp2.size() == k)
  93. {
  94. cout << s << endl;
  95. max = max + 1;
  96. }
  97. }
  98. }
  99. if (max == 10) break;
  100. }
  101. if (max == 0) {
  102. cout << "не обнаружены" << endl;
  103. system("pause");
  104. return 0;
  105. }
  106. fin.close();
  107. system("pause");
  108. return 0;
  109. }
Add Comment
Please, Sign In to add comment