C + + brush question--2802: Infer If a string is a palindrome

Source: Internet
Author: User

Description The code to infer whether a string entered is a palindrome.

If the output is "Yes". Otherwise output "No".

A palindrome is a string that reads and reads backwards. Inputoutputsample Inputabcddcbasample Outputyes


/* Copyright (c) 2014, Yantai University School of Computer * All rights reserved. * File name: Test.cpp * Chen Dani * Completion Date: June 1, 2015 * version number: v1.0 * * #include <iostream> #include <cstdio>using namespace s Td;int Main () {    char a[81];    Gets (a);    int i,n=0,s=0;    for (i=0; a[i]!=0; i++)        n++;    for (i=0; i<n/2; i++)    {        if (a[i]==a[n-i-1])            s++;    }    if (S==N/2)        cout<< "Yes" <<endl;    else        cout<< "No" <<endl;    return 0;}

Experience: This time write more simple than the last write. The main thing is to think of a more ingenious method, this is progress!

So before you do the question, think about it with the mathematical thinking, there is no simple solution, this will be much easier! Keep trying.

C + + brush question--2802: Infer If a string is a palindrome

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.