标签:
Regionals 2004 >> Europe - Northeastern
问题链接:UVA1339 UVALive3213 POJ2159 ZOJ2658 Ancient Cipher。基础训练题,用C语言编写程序。
对两组字符串分别进行字母统计,接着对统计结果进行排序,然后对排序后的结果进行比较。如果相同,说明可以找到一种一一映射,使得两个字符串相同。
AC的C语言程序如下:
/* UVA1339 UVALive3213 POJ2159 ZOJ2658 Ancient Cipher */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <memory.h> #define LETTERNUM 26 #define MAXN 100 int cmp(const void * a, const void * b) { return *(int *)a - *(int *)b; } int main(void) { char s[MAXN+1], t[MAXN+1]; int counts[LETTERNUM], countt[LETTERNUM], len, flag, i; while(scanf("%s", s) != EOF) { scanf("%s", t); memset(counts, 0, sizeof(counts)); memset(countt, 0, sizeof(countt)); len = strlen(s); for(i=0; i<len; i++) { counts[s[i]-'A']++; countt[t[i]-'A']++; } qsort(counts, LETTERNUM, sizeof(counts[0]), cmp); qsort(countt, LETTERNUM, sizeof(countt[0]), cmp); flag = 1; for(i=0; i<LETTERNUM; i++) if(counts[i] != countt[i]) { flag = 0; break; } printf("%s\n", flag ? "YES" : "NO"); } return 0; }
UVA1339 UVALive3213 POJ2159 ZOJ2658 Ancient Cipher
标签:
原文地址:http://blog.csdn.net/tigerisland45/article/details/52058810