zoukankan      html  css  js  c++  java
  • JustOj 1927: 回文串

    题目描述

    回文串是从左到右或者从右到左读起来都一样的字符串,试编程判别一个字符串是否为回文串。

    输入

    输入一个字符串。串长度<255.

    输出

    判别输入的字符串是否为回文串,是输出"Y",否则输出"N"。

    样例输入
    abcba
    
    样例输出
    Y

    题解:判断首尾是否一样即可
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <vector>
     6 #include <cstdlib>
     7 #include <iomanip>
     8 #include <cmath>
     9 #include <ctime>
    10 #include <map>
    11 #include <set>
    12 using namespace std;
    13 #define lowbit(x) (x&(-x))
    14 #define max(x,y) (x>y?x:y)
    15 #define min(x,y) (x<y?x:y)
    16 #define MAX 100000000000000000
    17 #define MOD 1000000007
    18 #define pi acos(-1.0)
    19 #define ei exp(1)
    20 #define PI 3.141592653589793238462
    21 #define INF 0x3f3f3f3f3f
    22 #define mem(a) (memset(a,0,sizeof(a)))
    23 typedef long long ll;
    24 ll gcd(ll a,ll b){
    25     return b?gcd(b,a%b):a;
    26 }
    27 bool cmp(int x,int y)
    28 {
    29     return x>y;
    30 }
    31 const int N=10005;
    32 const int mod=1e9+7;
    33 char a[256];
    34 int main()
    35 {
    36     std::ios::sync_with_stdio(false);
    37     scanf("%s",&a);
    38     int len=strlen(a);
    39     int flag=1;
    40     for(int i=0;i<=len/2;i++){
    41         if(a[i]!=a[len-i-1]){
    42             flag=0;
    43             break;
    44         }
    45     }
    46     if(flag) cout<<"Y"<<endl;
    47     else cout<<"N"<<endl;
    48     return 0;
    49 }
     
  • 相关阅读:
    2-5
    2-3
    2-2
    2-1
    1-1
    实验6-1 求数组及其下标
    实验4-2 关于求阶乘的运算
    作业 3-5 switch语句的应用
    作业3-6 查询水果单价
    作业3-4 判断是不是闰年
  • 原文地址:https://www.cnblogs.com/wydxry/p/7268439.html
Copyright © 2011-2022 走看看