hdu1318 Palindromes(回文)
2016-03-09 22:03
477 查看
啊哈哈哈哈我记得去年最怕这种题了,这次细心的处理了一次,居然1A!
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/titter.gif)
自从会了字符串反转后,感觉什么都变简单了。。。
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;
const int N = 20000;
const int INF = 1000000;
char s1
= {"ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"};
char s2
= {"A***3**HIL*JM*O***2TUVWXY51SE*Z**8*"};
int pal(char a
)
{
char b
;
strcpy(b, a);
strrev(b);
if(!strcmp(b, a)) return 1;
else return 0;
}
int mir(char a
)
{
int len = strlen(a);
char b
;
strcpy(b, a);
strrev(b);
int flag = 1;
for(int i = 0; i < len; i ++)
{
for(int j = 0; s1[j]; j ++)
{
if(a[i] == s1[j])
{
if(b[i] != s2[j])
{
flag = 0;
// printf("%c %c\n", a[i], b[i]);
break;
}
}
}
if(!flag) break;
}
if(flag) return 1;
else return 0;
}
int main()
{
// freopen("in.txt", "r", stdin);
char s
;
while(~scanf("%s", s))
{
if(!pal(s) && !mir(s)) printf("%s -- is not a palindrome.\n", s);
else if(pal(s) && !mir(s)) printf("%s -- is a regular palindrome.\n", s);
else if(!pal(s) && mir(s)) printf("%s -- is a mirrored string.\n", s);
else printf("%s -- is a mirrored palindrome.\n", s);
printf("\n");
}
return 0;
}
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/titter.gif)
自从会了字符串反转后,感觉什么都变简单了。。。
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <queue>
#include <string.h>
using namespace std;
const int N = 20000;
const int INF = 1000000;
char s1
= {"ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"};
char s2
= {"A***3**HIL*JM*O***2TUVWXY51SE*Z**8*"};
int pal(char a
)
{
char b
;
strcpy(b, a);
strrev(b);
if(!strcmp(b, a)) return 1;
else return 0;
}
int mir(char a
)
{
int len = strlen(a);
char b
;
strcpy(b, a);
strrev(b);
int flag = 1;
for(int i = 0; i < len; i ++)
{
for(int j = 0; s1[j]; j ++)
{
if(a[i] == s1[j])
{
if(b[i] != s2[j])
{
flag = 0;
// printf("%c %c\n", a[i], b[i]);
break;
}
}
}
if(!flag) break;
}
if(flag) return 1;
else return 0;
}
int main()
{
// freopen("in.txt", "r", stdin);
char s
;
while(~scanf("%s", s))
{
if(!pal(s) && !mir(s)) printf("%s -- is not a palindrome.\n", s);
else if(pal(s) && !mir(s)) printf("%s -- is a regular palindrome.\n", s);
else if(!pal(s) && mir(s)) printf("%s -- is a mirrored string.\n", s);
else printf("%s -- is a mirrored palindrome.\n", s);
printf("\n");
}
return 0;
}
相关文章推荐
- 【HDU 5366】The mook jong 详解
- 【HDU 2136】Largest prime factor 详细图解
- 【HDU 1568】Fibonacci 数学公式 详解
- HDU 1568
- HDU1290
- HDU1568(Fobonacci公式)
- HDU ACM Step 2.2.2 Joseph(约瑟夫环问题)
- HDU 1405
- HDU 1297
- hdu 1205
- hdu 2087
- hdu 1016
- HDU 4898 The Revenge of the Princess’ Knight ( 2014 Multi-University Training Contest 4 )
- HDU 5592 ZYB's Premutation 线段树(查找动态区间第K大)
- HDU 5240 Exam (好水的题)
- HDU5237 Base64 大模拟
- HDU 1000
- HDU 1001
- 2015-11-11 hdu新生赛 A题(AC)
- 2015-11-11 hdu新生赛 C题(结束后一发AC)