Codeforces Round 863 A Quasi-palindrome 水

  题目链接: http://codeforces.com/contest/863/problem/A

  题目描述: 给你一个 串, 问你是不是半回文串, 在前面加若干0是回文串的串是半回文串

  解题思路: 将串的所有尾0去掉, 然后再判断是不是回文串就行了 

  代码: 

By wanglang, contest: Educational Codeforces Round 29, problem: (A) Quasi-palindrome, Accepted, #, hack it!
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;

typedef long long ll;

bool is_p(char * d, int n ) {
    int i = 0;
    int j = n-1;
    while( i < n ) {
        if( d[i] != d[j] ) return false;
        i++, j--;
    }
    return true;
}
int main() {
    char dig[15];
    scanf( "%s", dig );
    int len = (int)strlen(dig);
    int n = len;
    for( int i = len-1; i >= 0; i-- ) {
        if( dig[i] == '0' ) n = i;
        else break;
    }
    if( is_p(dig, n) ) {
        printf( "YES
" );
    }
    else {
        printf( "NO
" );
    }
    return 0;
}
View Code

  思考: 水题

原文地址:https://www.cnblogs.com/FriskyPuppy/p/7576874.html