Submission #3549

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

#define MAX_SIZE 100000

int main(void){
 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);
 return 0;
}

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;
 }

}

# Verdict Execution time Memory Grader output
1 Execution timed out 200 ms 1156 KB Program timed out
2 Halted 0 ms 0 KB -