Uva1339 - Ancient Cipher

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
char s[105], s2[105];
int t[26], t2[26];
void mycount(int t[], char s[], char alp[]){               //标记是s[]中各字母出现次数
	for (int i = 0; i <strlen(s); i++){
		for (int j = 0; j < 26; j++){
			if (alp[j] == s[i]) {
				t[j]++; break;
			}
		}
	}
}
int cmp(const void*a, const void*b){
	return *(int *)a - *(int *)b;
}
int main(){
	char alp[26]; //creat an alphabet
	int d = 1;
	if (d){
		alp[0] = 'A';
		for (int i = 1; i < 26; i++){
			alp[i] = alp[i - 1] + 1;
		}
		d = 0;
	}
	while (scanf("%s%s", s, s2) != EOF){
		int len = strlen(s);
		mycount(t, s, alp);
		mycount(t2, s2, alp);
		qsort(t, 26, sizeof(int), cmp);//sort
		qsort(t2, 26, sizeof(int), cmp);
		int d2 = 1;
		for (int i = 0; i < 26; i++){
			if (t[i] != t2[i]){
				d2 = 0; break;
			}
		}
		if (d2) printf("YES\n");
		else printf("NO\n");
		memset(t, '\0', 26 * sizeof(int)); 
		memset(t2, '\0', 26 * sizeof(int));
		memset(s, '\0', 105 * sizeof(char));
		memset(s2, '\0',105 * sizeof(char));
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值