C - Palindromes——常量数组运用
2017-03-30 18:45
162 查看
think:
1常量数组运用
2isalpha(char ch)——判断是否为英文字母
Presentation error错误
Hint:In addition, after each output line, you must print an empty line.
Vjudge题目链接
以下为Presentation error代码——每组数据输出后应输出换行
以下为accepted代码
1常量数组运用
2isalpha(char ch)——判断是否为英文字母
Presentation error错误
Hint:In addition, after each output line, you must print an empty line.
Vjudge题目链接
以下为Presentation error代码——每组数据输出后应输出换行
#include <bits/stdc++.h> using namespace std; char st[] = "A 3 HIL JM O 2TUVWXY51SE Z 8 "; char tra(char ch) { if(isalpha(ch)) return st[ch-'A']; else return st[ch-'0'+25]; } int main() { char st1[24]; int i, p, m; while(scanf("%s", st1) != EOF) { int len = strlen(st1); p = 1, m = 1; for(i = 0; i < (len+1)/2; i++) { if(st1[i] == '0') st1[i] = 'O'; if(st1[i] != st1[len-1-i]) p = 0; if(st1[i] != tra(st1[len-1-i])) m = 0; } if(p == 0 && m == 0) printf("%s -- is not a palindrome.\n", st1); else if(p == 1 && m == 0) printf("%s -- is a regular palindrome.\n", st1); else if(p == 0 && m == 1) printf("%s -- is a mirrored string.\n", st1); else printf("%s -- is a mirrored palindrome.\n", st1); } return 0; }
以下为accepted代码
#include <bits/stdc++.h> using namespace std; char st[] = "A 3 HIL JM O 2TUVWXY51SE Z 8 "; char tra(char ch) { if(isalpha(ch)) return st[ch-'A']; else return st[ch-'0'+25]; } int main() { char st1[24]; int i, p, m; while(scanf("%s", st1) != EOF) { int len = strlen(st1); p = 1, m = 1; for(i = 0; i < (len+1)/2; i++) { if(st1[i] == '0') st1[i] = 'O'; if(st1[i] != st1[len-1-i]) p = 0; if(st1[i] != tra(st1[len-1-i])) m = 0; } if(p == 0 && m == 0) printf("%s -- is not a palindrome.\n", st1); else if(p == 1 && m == 0) printf("%s -- is a regular palindrome.\n", st1); else if(p == 0 && m == 1) printf("%s -- is a mirrored string.\n", st1); else printf("%s -- is a mirrored palindrome.\n", st1); printf("\n"); } return 0; }
相关文章推荐
- UVa401-Palindromes-回文词-字符函数,常量数组
- 38. C# -- 常量\枚举\结构及数组的运用
- UVa 401 Palindromes(常量数组+遍历)
- C#中常量\枚举\结构及数组的运用
- 常量指针运用, 指针和数组名的赋值,以及各自的内存空间问题 浅谈 !
- JAVA中运用数组的四种排序方法
- 运用数组求平均值
- jvm原理(3)编译期常量与运行期常量的区别及数组创建本质分析
- 不爱学习的小W HNUST 1881(数组开小点的灵活运用)
- MATLAB中矩阵与数组的区别,点运算符的运用
- 数组的基础及运用
- C字符串常量数组,ACC_MODE详解
- 对象调用数组运用 学习很吃力
- C++ 中常量字符串与字符数组
- Ajax运用json数组传输数据
- 指针数组、数组指针、常指针、指向常量的指针、指针函数、函数指针等概念的区分
- MATLAB中矩阵与数组的区别,点运算符的运用
- Delphi的动态数组,以及在复旦天翼学生收费管理软件的基础运用
- j2se之数组的运用
- 运用分治法和动态规划方法求解最大子数组问题