UVALive 6342 The Mirror of Galadriel (回文串)
2014-07-06 19:56
597 查看
The Mirror of Galadriel
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld
& %llu
SubmitStatusPracticeUVALive
6342
Description
![](https://icpcarchive.ecs.baylor.edu/components/com_onlinejudge/images/button_pdf.png)
With water from the stream Galadriel filled the basin to the brim, and breathed on it, and when the water was still again she spoke. 'Here is the Mirror of Galadriel,' she said. 'I have brought you here so that you may look in it, if you will.
For this is what your folk would call magic, I believe; though I do not understand clearly what they mean; and they seem also to use the same word of the deceits of the Enemy. But this, if you will, is the magic of Galadriel. Did you not say that you wished
to see Elf-magic?'
[align=RIGHT]- Galadriel to Frodo and Sam, describing her Mirror.[/align]
We call a string S magical if every substring of S appears in Galadriel's Mirror (under lateral inversion). In other words, a magical string is a string where every substring has its reverse
in the string.
Given a string S, determine if it is magical or not.
Input
The first line contains T, the number of test cases. The next T lines contain a string each.
Output
For each test case, output `YES' if the string is magical, and `NO' otherwise.
Constraints:
1<=T<=100
1<=| S|<=10
S contains only lower-case characters.
Notes/Explanation of Sample Input:
For the first test case, the list of substrings are : a, b, ab, ba, aba. The reverse of each of these strings is present as a substring of S too.
For the second test case, the list of substring are : a, b, ab. The reverse of `ab', which is `ba' is not present as a substring of the string.
Sample Input
Sample Output
AC代码:
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld
& %llu
SubmitStatusPracticeUVALive
6342
Description
![](https://icpcarchive.ecs.baylor.edu/components/com_onlinejudge/images/button_pdf.png)
With water from the stream Galadriel filled the basin to the brim, and breathed on it, and when the water was still again she spoke. 'Here is the Mirror of Galadriel,' she said. 'I have brought you here so that you may look in it, if you will.
For this is what your folk would call magic, I believe; though I do not understand clearly what they mean; and they seem also to use the same word of the deceits of the Enemy. But this, if you will, is the magic of Galadriel. Did you not say that you wished
to see Elf-magic?'
[align=RIGHT]- Galadriel to Frodo and Sam, describing her Mirror.[/align]
We call a string S magical if every substring of S appears in Galadriel's Mirror (under lateral inversion). In other words, a magical string is a string where every substring has its reverse
in the string.
Given a string S, determine if it is magical or not.
Input
The first line contains T, the number of test cases. The next T lines contain a string each.
Output
For each test case, output `YES' if the string is magical, and `NO' otherwise.
Constraints:
1<=T<=100
1<=| S|<=10
S contains only lower-case characters.
Notes/Explanation of Sample Input:
For the first test case, the list of substrings are : a, b, ab, ba, aba. The reverse of each of these strings is present as a substring of S too.
For the second test case, the list of substring are : a, b, ab. The reverse of `ab', which is `ba' is not present as a substring of the string.
Sample Input
2 aba ab
Sample Output
YES NO
AC代码:
#include <stdio.h> #include <string.h> int main(){ int n,len,i,flag; char a[1000]; scanf("%d",&n); while(n--){ flag=1; scanf("%s",a); len=strlen(a); for(i=0;i<len/2;i++){ if(a[i]!=a[len-1-i]){ flag=0; break; } } if(flag) printf("YES\n"); else printf("NO\n"); } return 0; }
相关文章推荐
- UVALive 6345 The Glittering Caves of Aglarond (找规律求最多)
- UVaLive/LA 6800 The Mountain of Gold?(BellmanFord判负环+记忆化搜索)
- UVALive3523-Knights of the Round Table(BCC+二分图判定)
- UVALive - 3523 Knights of the Round Table(【点双连通分量】+【二分图判定】)
- UVALive - 7484 Association for the Country of Mububa(dp)
- UVAlive 3523 Knights of the Round Table [点双连通分量] [Tarjan]
- UVALive - 6800 The Mountain of Gold?(Bellman-ford找负权回路,dfs)
- UVALive-3972 March of the Penguins (最大流:节点容量)
- UVALive 3523 Knights of the Round Table 圆桌骑士 (无向图点双连通分量)
- UVALive3523 [Knights of the Round Table] tarjan求无向图双联通分量
- UVALive 3523 Knights of the Round Table(BCC+二分图)
- UVALive - 3972 March of the Penguins(最大流+枚举)
- UVALive 3523 Knights of the Round Table(二分图+双连通分量)
- UVAlive3523 Knights of the Round Table(bcc)
- The Mountain of Gold? UVALive - 6800
- UVALive 7661 The Size of the Smallest Hole(dfs)
- uvalive 6800 - The Mountain of Gold? 判负环
- UVAlive3523 Knights of the Round Table(bcc)
- uvalive 3523 Knights of the Round Table 圆桌骑士(强连通+二分图)
- UVALive 5783 Everyone out of the Pool