UVa 401 Palindromes
2016-11-27 11:52
369 查看
//#include <iostream> //#include <iomanip> #include <cstdio> #include <cmath> #include <cstring> #include <cctype> //using namespace std; const char s[] = "A 3 HIL JM O 2TUVWXY51SE Z 8 "; //if the string is a palindrome rev(char string[], char reved[]) { int len = strlen(string); int i; for(i = 0; i < len; i++) { reved[len - i - 1] = string[i]; } } //if the string is a mirrored string mir(char string[], char mired[]) { int len = strlen(string); strcpy(mired, string); int i; for(i = 0; i < len; i++) { int index; if(isalpha(mired[i])) index = mired[i] - 'A'; else if(isdigit(mired[i])) index = mired[i] - '0' + 25; if(s[index]) mired[i] = s[index]; } } int main() { //ios::sync_with_stdio(false); //FILE *f = fopen("in.txt", "r"); char input[30]; int palindrome; int mirrored; char reved[30]; char mirtmp[30]; char mired[30]; while(scanf("%s", input) == 1) { memset(reved, 0, sizeof(reved)); memset(mired, 0, sizeof(mired)); rev(input, reved); mir(input, mirtmp); rev(mirtmp, mired); palindrome = !strcmp(input, reved); mirrored = !strcmp(input, mired); //printf("%s %s %s\n", reved, mired, input); if(mirrored && palindrome) printf("%s -- is a mirrored palindrome.", input); else if(mirrored) printf("%s -- is a mirrored string.", input); else if(palindrome) printf("%s -- is a regular palindrome.", input); else printf("%s -- is not a palindrome.", input); printf("\n\n"); } //fclose(f); return 0; }
相关文章推荐
- uva_401_Palindromes
- UVA 401 Palindromes
- Palindromes - UVa 401 字符串处理
- 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
- UVA 401 - Palindromes(判断回文串和镜像串)