Submission #990678

#TimeUsernameProblemLanguageResultExecution timeMemory
990678Ibrohim0704Palindromes (APIO14_palindrome)C++14
0 / 100
1072 ms1356 KiB
#include <iostream>
#include <string>

using namespace std;

int longest_palindrome_occurrence(const string& s) {
    int max_occurrence = 0;
    for (int i = 0; i < s.length(); ++i) {
        // Odd-length palindromes
        int left = i, right = i;
        while (left >= 0 && right < s.length() && s[left] == s[right]) {
            max_occurrence = max(max_occurrence, (right - left + 1));
            left--;
            right++;
        }
        // Even-length palindromes
        left = i;
        right = i + 1;
        while (left >= 0 && right < s.length() && s[left] == s[right]) {
            max_occurrence = max(max_occurrence, (right - left + 1));
            left--;
            right++;
        }
    }
    return max_occurrence;
}

int main() {
    string input_string;
    cin >> input_string;

    // Calculating and printing the largest occurrence value of palindromic substrings
    int largest_occurrence = longest_palindrome_occurrence(input_string);
    cout << largest_occurrence << endl;

    return 0;
}

Compilation message (stderr)

palindrome.cpp: In function 'int longest_palindrome_occurrence(const string&)':
palindrome.cpp:8:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for (int i = 0; i < s.length(); ++i) {
      |                     ~~^~~~~~~~~~~~
palindrome.cpp:11:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |         while (left >= 0 && right < s.length() && s[left] == s[right]) {
      |                             ~~~~~~^~~~~~~~~~~~
palindrome.cpp:19:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         while (left >= 0 && right < s.length() && s[left] == s[right]) {
      |                             ~~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...