#2019120700021 回文判断

#include <cstdio>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;
char ch,lett[101];
int main(){
    scanf("%s",lett+1);
    int a=1,b=strlen(lett+1);
    b--;
    while(lett[a]==lett[b]&&(b>=1)) {
        a++;b--;
    }
    if(b==0) printf("Yes");
    else printf("No");
    return 0; 

}
void fetc(){
    int i=1;
    cin>>ch;
    while(ch!='.'){
        lett[i]=ch;
        i++;
        cin>>ch;
    }
    return ;
}

\(fetc\)函数是一种读入字符串的方式

原文地址:https://www.cnblogs.com/liuziwen0224/p/12000536.html

时间: 2024-08-11 09:52:05

#2019120700021 回文判断的相关文章

DS之顺序栈和链队实现回文判断

顺序栈和链队的基本操作就不再一一列举了,要想实现回文判断,先来了解什么是回文?"回文"一字符串正着读和反着读是相同的字符序列,如"abcba","abba"为"回文","abab"则不是"回文". 其次就是顺序栈和链队如何实现回文的判断?将输入的字符串依次入栈和入队,然后再依次出栈和出队,由于入栈和入队是相同的序列,然而出栈和出队是相反的序列,这就实现了回文的判断. 最后考虑要用到顺序栈

2_3 回文判断

#include <stdio.h> #include <string.h> void main() { int x,i; char str[100]; //gets(st1); printf("Please input a string to find out whether the string is palindrome or not\n"); scanf("%s",str); x=strlen(str); for(i = 0; i &

冒泡排序与回文判断

冒泡排序:很简单就不细说了: #include <stdio.h> void bubbleSort(int num[],int len) { int i = 0; int j = 0; int temp = 0; for(j = 0;j<len-1;j++) { for(i = 0;i < len - j-1;i++) { if(num[i] > num[i+1]) { temp = num[i+1]; num[i+1] = num[i]; num[i] = temp; }

回文判断

一个整形数是否是回文 also leetcode 9 Palindrome Number要求空间复杂度O(1)按位判断一般是/和%的游戏,首先取首位 a/h (h是最接近a的10的次方,比如12321,h预计算出是10000), 再取末位a%10; 比较首位和末位是否相等,不等就返回false; 如图: 然后舍弃掉已经比较过的两个位数,从a中去掉首尾 12321 --> 232. a = a % h; // 去掉首 a = a /10; //去掉尾 h = 100; // 因为已经去掉了两位 如

【字符串处理算法】回文判断的算法设计及C代码实现

一.需求描述 输入一个字符串,编写程序判断这个字符串是否是回文串. 为了便于说明,设定输入的字符串分为中文字符串和非中文字符串两种.其中,中文字符串中仅包含中文字符,非中文字符串中不包含中文字符. 所谓回文串,是指正读和反读都一样的字符串.下面举几个例子予以说明: 1."level"是一个非中文字符的回文串,因为正读和反读都是"level". 2."Good"不是一个非中文字符的回文串. 3."我爱我"是一个中文字符的回文串,

一天一算法:回文判断

问题描述: 什么是回文?如,aha, adda,单ahah就不是回文,等等 如何判断一串字符串是回文呢? 这里的想法是:我们利用队列的方式,找到字符的中间的位置,将中间字符之前的全部入栈,然后全部出栈,与中间字符之后的字符进行比较,如果全部一样,那么就是回文. 代码: #include<iostream> #include <queue> #include <string.h> using namespace std; int main() { char str[] =

LeetCode——Valid Palindrome (回文判断)

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example, "A man, a plan, a canal: Panama" is a palindrome. "race a car" is not a palindrome. Note: Have you consider that

小算法:递归实现回文判断

static void Main(string[] args) { DateTime dt1 = DateTime.Now; string text = "abcdedcba"; bool bYes = Recv(text); Console.Write("{0}:{1}回文!", text, bYes ? "是" : "不是"); DateTime dt2 = DateTime.Now; Console.Write(&quo

链表回文判断(C++)

题目描述: 对于一个链表,请设计一个时间复杂度为O(n),额外空间复杂度为O(1)的算法,判断其是否为回文结构. 给定一个链表的头指针A,请返回一个bool值,代表其是否为回文结构.保证链表长度小于等于900. 测试样例: 1->2->2->1 返回:true 思路: 由于空间复杂度要求为O(1),也就是说临时占用空间和输入数据规模无关,因此无法利用数组或者是栈进行判断.因此先找到中间位置将后半部分指针翻转,然后两端分别比较.注意这种方法会修改原链表,但是空间复杂度要求为O(1)也只能这