Submission #471371

#TimeUsernameProblemLanguageResultExecution timeMemory
471371malar회문 (APIO14_palindrome)C++14
0 / 100
1 ms204 KiB
#include <iostream> #include <fstream> 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; } 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; string item_name; ifstream nameFileout; nameFileout.open("palindrome.in"); while (getline(nameFileout, item_name)){ str = item_name; } nameFileout.close(); 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]; } int maxPoints = findMax(points, maxIndex); ofstream outfile("palindrome.out"); outfile << maxPoints; outfile.close(); }

Compilation message (stderr)

palindrome.cpp: In function 'bool isPalindrome(std::string)':
palindrome.cpp:6:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 |  for(int i = 0; i <str.length()/2; i++) {
      |                 ~~^~~~~~~~~~~~~~~
palindrome.cpp: In function 'int arraylength(std::string)':
palindrome.cpp:26:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  while(i <= str.length()) {
      |        ~~^~~~~~~~~~~~~~~
palindrome.cpp: In function 'int main()':
palindrome.cpp:61:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for(int i = 0; i < str.length(); i++) {
      |                 ~~^~~~~~~~~~~~~~
palindrome.cpp:63:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   for(int k=i; k < str.length(); k++) {
      |                ~~^~~~~~~~~~~~~~
#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...