CSU - 1029 Palindrome(回文串)

来源:互联网 发布:如何进入人工智能行业 编辑:程序博客网 时间:2024/04/28 17:45

题目:

Description

A palindrome is a symmetrical string, that is, a string read the same from left to right as from right to left. You are asked to write a program which, given a string, determines whether it is a palindrome or not.

Input

The first line contain a single integer T, indicates the number of test cases.

T lines follow, each line contain a string which you should judge. The length of the string is at most 1000.

Output

Print one line for each string, if it is a palindrome, output “YES”, else “NO”.

Sample Input

2
aba
ab

Sample Output

YES
NO

判断是否为回文串

代码:

#include<iostream>#include<string.h>using namespace std; int main(){    int t;    cin >> t;    char c[1002];    cin.getline(c, 1002, '\n');    while (t--)    {        cin.getline(c,1002,'\n');        int l = strlen(c);        bool flag = true;        for (int i = 0; i + i < l; i++)        {            if (c[i] != c[l - 1 - i])            {                flag = false;                break;            }        }        if (flag)cout << "YES";        else cout << "NO";        cout << endl;    }    return 0;}

0 0
原创粉丝点击