UVA 401 Palindromes
来源:互联网 发布:海口seo外包公司 编辑:程序博客网 时间:2024/05/16 12:59
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342
题意:
给你个字符串叫你判断它是什么样子的字符串(回文镜像、镜像、回文、普通)。
思路:
把题目中的字母打表后直接做。
这题迷之RE,迷之WA。
好吧,RE是因为会有其他字符,但是我把数字和大写字母都特判了还是RE是要闹哪样,把手敲的判断大写字母改为isalpha函数就AC是个什么操作?
心血来潮把那些要打表的字母一个个拆开,怎么交怎么WA,变量放局部WA,放全局AC也很迷。
总之要注意的是用isalpha函数去判断大写字母,或者就我一个遇到这种问题吧。
#include <bits/stdc++.h>using namespace std;char mp[]="A 3 HIL JM O 2TUVWXY51SE Z 8 ";char f(char c){ if(isalpha(c)) { return mp[c-'A']; } else { return mp[26+c-'1']; }}int i,num,num1,n;char s[100000];int main(){ while(scanf("%s",s)!=EOF) { num=0; num1=0; n=strlen(s); for(i=0;(n+1)/2>i;i++) { if(s[i]==f(s[n-i-1])) { num++; } if(s[i]==s[n-i-1]) { num1++; } } printf("%s -- "); if(num1==(n+1)/2) { if(num==(n+1)/2) { printf("is a mirrored palindrome.\n"); } else { printf("is a regular palindrome.\n"); } } else if(num==(n+1)/2) { printf("is a mirrored string.\n"); } else { printf("is not a palindrome.\n"); } printf("\n"); } return 0;}
阅读全文
0 0
- UVa 401 Palindromes
- UVa OJ 401-Palindromes
- UVa:401 - Palindromes
- uva 401 Palindromes //字符串
- uva 401 - Palindromes
- UVa 401 - Palindromes
- UVa 401 - Palindromes
- UVa 401 - Palindromes
- uva-401 - Palindromes
- UVa 401 Palindromes
- uva 401 Palindromes
- uva 401 Palindromes
- UVA 401 - Palindromes
- UVa 401 - Palindromes
- UVA 题目401 - Palindromes
- UVA 401 Palindromes
- UVa 401: Palindromes
- UVA 401 Palindromes
- Spring Boot中使用Redis数据库
- Linux报错ping: https://www.baidu.com: Name or service not known;centos7 无法启动网络(service network restart
- 朴素贝叶斯应用之文本分类
- 安装国际版 WPS
- Spring Boot中使用MongoDB数据库
- UVA 401 Palindromes
- 图的存储
- Python爬虫学习纪要(七):Requests 库学习笔记2
- 好的技术网站收录
- C语言单元小结(1)
- shader总结七
- 什么是重定位?为什么需要重定位?(嵌入式下)
- 第一个项目(游戏)
- Spring Boot中Web应用的统一异常处理