| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 471373 | malar | Palindromes (APIO14_palindrome) | C++14 | 1083 ms | 131076 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
using namespace std;
bool isPalindrome(string str) {
for(int i = 0; i <str.length()/2; i++) {
if(str[i] != str[str.length()-1-i]) {
return false;
}
}
return true;
}
int findPosition(string array[], string str, int size) {
for(int i = 0; i < size; i++) {
if(array[i] == str) {
return i;
}
}
return -1;
}
void printResults(string a[], int b[], int c[], int maxIndex) {
for(int i = 0; i <= maxIndex; i++) {
cout << "substring: " << a[i] << " => no of Occurrence: " << b[i]
<< " => occurrence value: " << c[i] << endl;
}
}
int arraylength(string str) {
int len = 0;
int i = 1;
while(i <= str.length()) {
len = len + i;
i++;
}
return len;
}
int findMax(int array[], int maxPos) {
int max = array[0];
for(int i = 1; i <= maxPos; i++) {
if(array[i] > max) {
max = array[i];
}
}
return max;
}
int main() {
string str;
cin >> str;
string substr[arraylength(str)];
int times[arraylength(str)];
int points[arraylength(str)];
string temp;
int maxIndex = -1;
for(int i = 0; i < str.length(); i++) {
temp = "";
for(int k=i; k < str.length(); k++) {
temp = temp + str[k];
if(isPalindrome(temp)) {
int pos = findPosition(substr, temp, sizeof(substr)/sizeof(substr[0]));
if(pos >= 0) {
times[pos] = times[pos] + 1;
} else{
maxIndex++;
substr[maxIndex] = temp;
times[maxIndex] = 1;
}
}
}
}
for(int i = 0; i <= maxIndex; i++) {
points[i] = substr[i].length() * times[i];
}
printResults(substr, times, points, maxIndex);
int maxPoints = findMax(points, maxIndex);
cout << maxPoints;
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
