码迷,mamicode.com
首页 > 其他好文 > 详细

UVa 1339 Ancient Cipher

时间:2018-06-03 19:34:47      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:span   while   div   str   证明   scan   TE   AC   cipher   

题目链接:

https://cn.vjudge.net/problem/UVA-1339

 1 /*
 2 问题
 3 输入两个序列,问两个序列能否通过重排和一个字母照应而形成一个序列。
 4 
 5 解题思路
 6 既然可以通过某种照应使其相等,那么出现的是哪个字母就显得不是那么重要了,重要的是每个字母出现的次数,将每个字母
 7 出现的次数通过重排看是否相同,能够相同就证明可以通过一定的照应使其相等。 
 8 */ 
 9 #include<cstdio>
10 #include<cctype>
11 #include<cstring>
12 #include<algorithm>
13 using namespace std;
14 int OK(int a[],int b[]);
15 int main()
16 {
17     //freopen("E:\\testin.txt","r",stdin);
18     char a[110],b[110];
19     int i,c[26],d[26];
20     while(scanf("%s%s",a,b) != EOF){
21         for(i=0;a[i] != \0;i++)
22             a[i]=tolower(a[i]);
23         for(i=0;b[i] != \0;i++)
24             b[i]=tolower(b[i]);
25             
26         memset(c,0,sizeof(c));
27         for(i=0;a[i] != \0;i++){
28             c[a[i]-a]++;
29         }
30         memset(d,0,sizeof(d));
31         for(i=0;b[i] != \0;i++){
32             d[b[i]-a]++;
33         }
34         sort(c,c+26);
35         sort(d,d+26);
36         
37         if(OK(c,d))
38             printf("YES\n");
39         else
40             printf("NO\n");
41     }
42     return 0;
43 } 
44 
45 int OK(int a[],int b[])
46 {
47     int i;
48     for(i=0;i<26;i++){
49         if(a[i] != b[i])
50             return 0;
51     }
52     return 1;
53 }

 

UVa 1339 Ancient Cipher

标签:span   while   div   str   证明   scan   TE   AC   cipher   

原文地址:https://www.cnblogs.com/wenzhixin/p/9129809.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!