0002: Palindromic String

Problem

You have been given a String S. You need to find and print whether this string is a palindrome or not. If yes, print "YES" (without quotes), else print "NO" (without quotes).

Input Format
The first and only line of input contains the String S. The String shall consist of lowercase English alphabets only.

Output Format
Print the required answer on a single line.

Constraints
1≤|S|≤100

Note
String S consists of lowercase English Alphabets only.

Solve

#include <stdio.h>
int main(){
    char str1[99];
    int i,j,k;
    int mul = 1;
    int isPalindromic;
    k=0;
    scanf("%s",str1);
	while(str1[k] != '\0'){
		k++;
	}
	k -= 1;
	for(i=0;i<k;i++) {
		if(str1[i]!=str1[k-i])
			isPalindromic = 0;
		else isPalindromic = 1;
		mul = isPalindromic * mul;
	}
	if(isPalindromic == 0)
		printf("NO\n");
	else printf("YES\n");
    return 0;
}
posted @ 2017-05-31 10:32  Mmsumz  阅读(111)  评论(0编辑  收藏  举报