例题3-3 回文词 UVa401
来源:互联网 发布:手机藏文输入法软件 编辑:程序博客网 时间:2024/05/22 15:59
例题3-3 回文词 UVa401
感悟。
1、程序写得不好,下次改进。
2、机器判别程序(AC),很是严格,少个空行,少个标点都不行。
3、程序没有明显的结束标志,故while(scanf("%s",s)==1).
4、原文的char r(char ch)函数技巧性比较高
5、原文(len+1)/2巧妙的处理了长度奇偶性。
6、目前水平,离原文还有一定距离,多琢磨。
附上代码:
环境Dev-cpp4.9.9.2
#include <stdio.h>
#include <string.h>
char dict[]="AAB0C0D0E3F0G0HHIIJLK0LJMMN0OOP0Q0R0S2TTUUVVWWXXYYZ5112S3E405Z60708890";
char s[100];
char t[100];
char buf[200];
int ispalind(char *s){//判断是否回文
int length;
int i;
int mid;
int palind=0,mirror=0,flag=0;
length=strlen(s);
if(length%2==0)//字符串长度为偶数时
mid=length/2-1;
else//字符串长度为奇数时
mid=length/2;
for(i=0;i<=mid;i++){
if(s[i]!=s[length-1-i])
return 0;
}
return 1;
}
void reverses(char *s){//反转处理
int length;
int i,j;
int dictlength;
length=strlen(s);
dictlength=strlen(dict);
for(i=0;i<length;i++){
for(j=0;j<dictlength;j++){
if(j%2==0&&s[i]==dict[j])
break;
}
t[i]=dict[j+1];
}
t[i]='\0';//补上字符串结束标志
}
int main(){
int palind,mirror;
while(scanf("%s",s)==1){
palind=ispalind(s);
reverses(s);
strcpy(buf,s);//拼串
strcat(buf,t);//拼串
mirror=ispalind(buf);
if(palind&&mirror){
printf("%s -- is a mirrored palindrome.\n\n",s);
}else if(mirror){
printf("%s -- is a mirrored string.\n\n",s);
}else if(palind){
printf("%s -- is a regular palindrome.\n\n",s);
}else{
printf("%s -- is not a palindrome.\n\n",s);
}
}
return 0;
}
- 例题3-3 回文词 UVa401
- 例题:回文词(UVa401)
- 《算法竞赛入门经典2ndEdition 》例题3-3 回文词(Palindromes, Uva401)
- UVa401 回文词
- 回文词(UVa401)
- 字符串与数组03-例题3 Palindromes,UVa401
- 回文词(Palindromes, UVa401)
- 回文词(Palindromes, UVa401)
- 回文词(Palindromes,UVa401)
- 例题3-3 回文词(Palindromes)
- 例题3-3回文词镜像词
- uva401(回文串)
- uva401回文串
- UVA401(回文串好题)
- 回文字镜像字 (Palindromes, UVa401)
- 小白书 3.3 例题3-4回文串
- 例题3-4 最长回文子串
- 算法竞赛入门经典 回文词 UVa401 msg数组
- 357. Count Numbers with Unique Digits统计各位不同的数字个数
- QT学习之路————QT程序在开发板上显示 中文字体
- HDU-Bone Collector(01背包问题)
- Maven之——插件目标及绑定
- 使用 Collectd + InfluxDB + Grafana 监控主机
- 例题3-3 回文词 UVa401
- HDU-1079 Calendar Game(博弈论)
- Qt+opencv开发笔记(1)
- 整数对查找
- 决策树算法(五)——处理一些特殊的分类
- CubieTruck安装Redis
- 使用springmvc 和nginx 搭建一个文件上传下载服务器
- jquery 那些事
- JsonCpp使用简介