Submission #3546

# Submission time Handle Problem Language Result Execution time Memory
3546 2013-08-31T06:31:06 Z pl0892029 Make superpalindrome! (kriii1_M) C++
Compilation error
0 ms 0 KB
#include<stdio.h>
#include<string.h>
char* strRev(char str[]);
bool isOK(char str[]);
bool isP(char str[]);

#define MAX_SIZE 100000

void main(){
 char input[MAX_SIZE];
 scanf("%s", input);

 while(true){
  if(isOK(input)) break;

  int plusIndex=strlen(input)-1;
  while(plusIndex>=0){
   if(input[plusIndex]=='z')
    plusIndex--;
   else break;
  }
  input[plusIndex]++;
  for(int i=plusIndex+1; i<strlen(input); i++)
   input[i]='a';

 }

 printf("%s",input);
 while(true);
}

bool isOK(char str[]){
 char left[MAX_SIZE/2], right[MAX_SIZE/2];
 int i;

 for(i=0; i<strlen(str)/2; i++){
  left[i]=str[i];
 }
 left[i]=NULL;

 if(strlen(str)%2==0){
  for(i=strlen(str)/2; i<strlen(str); i++){
   right[i-strlen(str)/2]=str[i];
  }
  right[strlen(str)/2]=NULL;
 }
 else{
  for(i=strlen(str)/2+1; i<strlen(str); i++){
   right[i-strlen(str)/2-1]=str[i];
  }
  right[strlen(str)/2]=NULL;
 }
 
 if(strlen(str)==1)
  return true;
 else if(!isP(str))
  return false;
 else{
  return isOK(left) && isOK(right);
 }
 
}

char* strRev(char str[]){
 int i;
 int length=strlen(str);
 char result[MAX_SIZE];
 for( i=0; i<length; i++){
  result[i]=str[length-i-1];
 }
 result[i]=NULL;
 return result;

}

bool isP(char str[]){
 char *revert;
 revert=strRev(str);
 if(strcmp(str,revert)==0)
  return true;
 else{
  return false;
 }

}

Compilation message

M.cpp:9:11: error: '::main' must return 'int'
M.cpp: In function 'int main()':
M.cpp:23:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
M.cpp: In function 'bool isOK(char*)':
M.cpp:36:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
M.cpp:39:10: warning: converting to non-pointer type 'char' from NULL [-Wconversion-null]
M.cpp:42:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
M.cpp:45:24: warning: converting to non-pointer type 'char' from NULL [-Wconversion-null]
M.cpp:48:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
M.cpp:51:24: warning: converting to non-pointer type 'char' from NULL [-Wconversion-null]
M.cpp: In function 'char* strRev(char*)':
M.cpp:71:12: warning: converting to non-pointer type 'char' from NULL [-Wconversion-null]
M.cpp:67:7: warning: address of local variable 'result' returned [enabled by default]
M.cpp: In function 'int main()':
M.cpp:11:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]