2017年省赛前最后一水 Problem A: String



题目描述

Lucy give you a string s(s1s2s3...sn) .
If(s1s2s3...sn)=(snsn-1sn-2...s1)  ,you tell Lucy YES,otherwise ,you tell Lucy NO.
For example.
Lucy give you “abba”,you should tell her “YES”  
Lucy give you “abbc”,you should tell her “NO”  
Lucy give you “abxba”,you should tell her “YES” 

输入

The first line of the input gives the number of test cases T(1<T<1000). T test cases follow.
For each test case.
One line contains a string s('a'<=si<='z') .The length of s no more than 1000. 

输出

For each test case, output a single line "Case #x: y", where x is the case number, starting from 1. And y is the answer.

样例输入

3

abb
a
abbc

abxba

样例输出

Case #1: YES

Case #2: NO

Case #3: YES




分析:判断是否是回文字符串



代码如下:

#include <stdio.h>
#include <string.h>
int main (){
    char str[1005];
    int Case=1;
    int t;
    scanf ("%d",&t);
    getchar();
    while (t--){
        scanf ("%s",str);
         
        int x=strlen(str);
        int flag=1;
        for (int i=0,j=x-1;i<=j&&flag;i++,j--){
            if(str[i]!=str[j]){
                printf ("Case #%d: NO\n",Case++);
                flag=0;
            }
        }
        if (flag)
            printf ("Case #%d: YES\n",Case++);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值