2022 sector 10 statements

This commit is contained in:
2025-04-05 20:04:28 +03:00
parent 305f89bc3e
commit 9b1df60993
27 changed files with 107 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
#include <iostream>
#include <fstream>
using namespace std;
ifstream input_stream;
ofstream output_stream;
bool is_palindrome(string s) {
uint8_t s_len = s.length();
for (uint8_t i = 0; i < (s_len / 2); i++) {
if (s[i] != s[s_len - i - 1]) {
return false;
}
}
return true;
}
int main() {
input_stream.open("input.txt");
output_stream.open("output.txt");
string max_pal, tmp;
string inp = "";
// File method:
while (true) {
input_stream >> tmp;
if (tmp == "") {
break;
}
inp += " " + tmp;
tmp = "";
}
uint8_t max_pal_len = 0;
uint8_t inp_len = inp.length();
for (uint8_t i = 0; i < (inp_len - 1); i++) {
for (uint8_t j = inp_len - i; j >= 2; j--) {
if (j > max_pal_len) {
string sub = inp.substr(i, j);
if (is_palindrome(sub)) {
max_pal_len = j;
max_pal = sub;
}
}
}
}
// File method:
// if (max_pal_len == 0) {
// output_stream << "Nu se contine" << endl;
// } else {
// output_stream << max_pal << endl;
// }
// Console method:
if (max_pal_len == 0) {
cout << "Nu se contine" << endl;
} else {
cout << max_pal << endl;
}
input_stream.close();
output_stream.close();
return 0;
}