回文数判定
来源:互联网 发布:ug10钻孔编程 编辑:程序博客网 时间:2024/05/22 07:01
给定一个字符串,判定是否是回文数,如abcba是回文数,abc不是
实例输入
abcba
实例输出
abcba是一个回文数
代码:
/*本实验完成验证一个字符串是否为回文字符串*/#include <stdio.h>#include <stdlib.h>#include<string.h>#include<math.h>#define max 10int top = 100;void init_stack(char s[]){top = 1;}int notempty(char s[]){if(top <= 1){return 0;}else return 1;}void push(char s[],char c){s[top] = c;top ++;}char pop(char s[]){if(notempty(s)){top = top - 1;return s[top];}}int main(){ char s[max]; gets(s); int lenth = strlen(s); //printf("%d",lenth); char a[top]; init_stack(a); int i; for(i = 0; i<lenth/2;i++){push(a,s[i]); } int l = (lenth+1)/2,cnt = 1; char temp; while(notempty(a)){temp = pop(a);//printf("%c",temp);if(temp == s[l]){l ++;continue;}else{cnt = 0;break;}break; } if(cnt == 0){printf("%s不是一个回文字符串",s); }else{printf("%s是一个回文字符串",s); } return 0;}
阅读全文
0 0
- 回文数的判定
- 回文数判定
- 回文数的判定
- 回文数判定
- 华为机试题--回文数的判定
- 第十周—C语言 回文数的判定
- 回文判定 Valid Palindrome
- 回文数字判定(nil)
- 判定回文串
- 回文串判定
- 回文串判定
- 回文串判定
- 回文串判定
- 回文串判定
- 回文串判定
- 回文串判定
- 回文串判定
- 回文串判定
- /usr/bin/ld: 找不到 -lippicv
- Linux私房菜学习-第6章Linux文件权限与目录
- Springboot No EntityManager with actual transaction available for current thread
- LeetCode.94 Binary Tree Inorder Traversal
- MATLAB内置常见函数
- 回文数判定
- Advanced Programming in UNIX Environment Episode 16
- Visual Studio Code编辑器的实用插件和工作中实用的技巧
- 代码审查“查”什么?
- javaSwing--容器
- 0/1背包(回溯法求解)-算法设计与分析
- 趋势科技2016校招:下面程序一共会在屏幕上输出多少个“-” ?
- codeforces 853B 思维 差分
- Python小练习(1)