SDUT OJ 2399 Palindrome
来源:互联网 发布:票据打印的软件 编辑:程序博客网 时间:2024/05/17 20:13
题目描述
A string is said to be a palindrome if it reads the same both forwards and backwards, for example "madam" is a palindrome while "acm" is not.
Now we want to know how many palindrome strings in the given strings.
Now we want to know how many palindrome strings in the given strings.
输入
The first line of the input contains a single integer T, which indicates number of the given strings.
The next T lines contain one string S, whose length is less than 1000 letters.
The next T lines contain one string S, whose length is less than 1000 letters.
输出
One integer indicates the number of palindrome strings.
示例输入
5ababaaabbabccccccAbcd
示例输出
2
题意:就是统计回文串的个数;
给出两个代码 一个是对半查找,能省一点儿时间
对半查找:
#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>char s1[1010];using namespace std;int main(){ int n,i,j; int cnt=0; int flag; scanf("%d",&n); for(i=0;i<n;i++){ flag=0; memset(s1,0,sizeof(s1)); scanf("%s",s1); int len=strlen(s1); for(j=0;j<=(len-1)/2;j++){ if(s1[j]!=s1[len-j-1]){ flag=1; break; } } if(!flag) cnt++; } printf("%d\n",cnt); return 0;}
正常做法
#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>char s1[1010],s2[1010];using namespace std;int main(){ int i,j,k,len,n; int cnt=0; scanf("%d",&n); for(i=1; i<=n; i++) { memset(s2,0,sizeof(s2)); scanf("%s",s1); j=0; len=strlen(s1); for(k=len-1; k>=0; k--) { s2[j]=s1[k]; j++; } if(strcmp(s1,s2)==0) cnt++; } printf("%d\n",cnt); return 0;}
0 0
- SDUT OJ 2399 Palindrome
- SDUT OJ 2718
- SDUT OJ -2892 A
- SDUT OJ-2896
- SDUT OJ 2862 勾股定理
- SDUT OJ 走迷宫
- SDUT OJ 走楼梯
- SDUT oj 玲珑龟
- 二叉排序树 (sdut oj 2482)
- SDUT oj 二叉排序树
- SDUT OJ 3374
- 小鑫追女神 (sdut oj)
- 闰年 (sdut oj)
- 优越数 (sdut oj)
- 相似三角形 (sdut oj)
- 洗衣服 (sdut oj)
- 压岁钱 (sdut oj)
- 数列求和 (sdut oj)
- poj3158 Kickdown
- Web Server技术选型
- Hive-函数
- 指定编码格式读写文件和读取文件夹下所有文件
- mysql主从配置
- SDUT OJ 2399 Palindrome
- JSP连接MySQL数据库
- .net 汉字转拼音
- 素数环(回溯)
- 将汉字转化成首字母序列
- Imatest 测CCM系数的方法
- 词典变位词检索系统【算法实现】
- Uva 1368 DNA Consensus String
- debian中安装virtualbox提示virtualbox 尚未配置时的处理方法