April Fools Contest 2017, problem: (D) Touchy-Feely Palindromes Solution in C

#include <stdio.h>
#include <string.h>

int main(){
int i, num, flag=0;
char str[11];
scanf(“%s”, str);
num = strlen(str);
if(num == 1){
if(str[0] == ‘3’ || str[0] == ‘7’){
printf(“Yes\n”);
}
else
printf(“No\n”);
}
else{
for(i=0; i<num/2; i++){
if(str[i] == ‘1’ || str[i] == ‘2’){
printf(“No\n”);
flag = 1;
break;
}
if(str[i] == ‘0’){
if(str[num-i-1] != ‘8’){
printf(“No\n”);
flag = 1;
break;
}
}
if(str[i] == ‘3’){
if(str[num-i-1] != ‘3’){
printf(“No\n”);
flag = 1;
break;
}
}
if(str[i] == ‘4’){
if(str[num-i-1] != ‘6’){
printf(“No\n”);
flag = 1;
break;
}
}
if(str[i] == ‘5’){
if(str[num-i-1] != ‘9’){
printf(“No\n”);
flag = 1;
break;
}
}
if(str[i] == ‘6’){
if(str[num-i-1] != ‘4’){
printf(“No\n”);
flag = 1;
break;
}
}
if(str[i] == ‘7’){
if(str[num-i-1] != ‘7’){
printf(“No\n”);
flag = 1;
break;
}
}
if(str[i] == ‘8’){
if(str[num-i-1] != ‘0’){
printf(“No\n”);
flag = 1;
break;
}
}
if(str[i] == ‘9’){
if(str[num-i-1] != ‘5’){
printf(“No\n”);
flag = 1;
break;
}
}
}
if(num%2 == 1 && flag == 0){
if(str[num/2] == ‘0’ || str[num/2] == ‘1’ || str[num/2] == ‘2’ || str[num/2] == ‘4’ || str[num/2] == ‘5’ || str[num/2] == ‘6’ || str[num/2] == ‘8’ || str[num/2] == ‘9’){
printf(“No\n”);
flag = 1;
}
}
if(flag == 0){
printf(“Yes\n”);
}
}
return 0;
}

(Visited 50 times, 1 visits today)

About the Author:

Leave A Comment