Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #pragma hdrstop
- #pragma argsused
- #define _CRT_SECURE_NO_WARNINGS
- #define _CRT_SECURE_NO_DEPRECATE
- #define _CRT_NONSTDC_NO_DEPRECATE
- #pragma warning(disable : 4996)
- #ifdef _WIN32
- #include <tchar.h>
- #else
- typedef char _TCHAR;
- #define _tmain main
- #endif
- #include <iostream>
- #include "pch.h"
- #include <iostream>
- #include <sstream>
- #include <fstream>
- #include <string>
- #include <cstdlib>
- #include <Windows.h>
- using namespace std;
- inline bool isVozrastanieww(const string& str)
- {
- return str == string(str.crbegin(), str.crend());
- }
- bool isVozrastanie(const string& s)
- {
- char * str = new char[s.length() + 1];
- strcpy(str, s.c_str());
- char *word = strtok(str, ",./?;:");
- for (int i = 0; i < strlen(word) - 1; i++)
- {
- if (int(word[i]) < int(word[i + 1]))
- return true;
- else
- return false;
- }
- delete[] str;
- }
- int main()
- {
- setlocale(LC_ALL, ".1251");
- int max = 0, k;
- string s, MaxStr;
- ifstream fin("input.txt"); //открыли файл для чтения
- if (!fin.is_open()) {
- cout << "Файл не может быть открыт" << endl;
- system("pause");
- return 1;
- }
- if (fin.peek() == EOF) {
- cout << "Файл пустой" << endl;
- system("pause");
- return 1;
- }
- fin.clear();
- fin.seekg(0);
- while (getline(fin, s))
- {
- istringstream ist(s);
- {
- size_t MaxLength(0);
- for (string temp; ist >> temp;)
- if (isVozrastanie(temp) && temp.size() > MaxLength)
- MaxStr = temp, MaxLength = temp.size();
- }
- }
- k = MaxStr.size();
- cout << "Строки, содержащие максимальную по длине возрастающую подстроку " << endl;
- fin.clear();
- fin.seekg(0);
- while (getline(fin, s))
- {
- istringstream ist2(s);
- {
- for (string temp2; ist2 >> temp2;) {
- if (isVozrastanie(temp2) && temp2.size() == k)
- {
- cout << s << endl;
- max = max + 1;
- }
- }
- }
- if (max == 10) break;
- }
- if (max == 0) {
- cout << "не обнаружены" << endl;
- system("pause");
- return 0;
- }
- fin.close();
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment