点击打开链接uva 1399
题意:给定两个长度分别为n的字符串,判断他们能否一一对应
思路:暴力
分析:
1 首先我们知道这两个字符串的长度最大为100并且相等
2 刚开始我的想法是对两个字符串排序,然后从头开始枚举判断。这个想法妥妥的过了样例,然而等到的确实一顿怒wa。下面举例证明我的思路是错误的
3 假设有两个字符串为ABBCFEA 和 CCGGHJB。排序后为AABBCEF和 BCCGGHJ如果按照我的思路那么我们从头开始枚举得到的是NO,但是实际上这个例子是YES。我们写出两个字符串中字母出现的次数的序列分别为22111和12211,那么我们对这个数字序列进行排序分别为11122和11122可以知道这个比较就可以得到YES
代码:
#include<map>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 110;
bool ok(char *s1 , char *s2){
int len = strlen(s1);
int num1[maxn] , num2[maxn];
memset(num1 , 0 , sizeof(num1));
memset(num2 , 0 , sizeof(num2));
for(int i = 0 ; i < len ; i++){
num1[s1[i]-'A']++;
num2[s2[i]-'A']++;
}
sort(num1 , num1+maxn);
sort(num2 , num2+maxn);
return !memcmp(num1 , num2 , sizeof(num1)) ? true : false;
}
int main(){
char s1[maxn] , s2[maxn];
while(scanf("%s" , s1) != EOF){
scanf("%s" , s2);
printf("%s\n" , ok(s1 , s2) ? "YES" : "NO");
}
return 0;
}
分享到:
相关推荐
北大POJ2159-Ancient Cipher 解题报告+AC代码
pku acm 2159 Ancient Cipher代码 计数排序 解题报告请访问:http://blog.csdn.net/china8848
Cipher
this is document for Hi3520D
Column permutation cipher是基于置换的加密解密方式。利用本程序可实现Column permutation cipher的加密和解密。
加密--Cipher加密
CIPHER加密解密等多种算法
Cipher加密解密
Qt中SQlite数据库加密SqliteCipher 操作实例,打开多个数据库,附着数据库跨库查询, 对应说明:https://blog.csdn.net/woguanni/article/details/120524602
赠送jar包:shiro-crypto-cipher-1.4.0.jar; 赠送原API文档:shiro-crypto-cipher-1.4.0-javadoc.jar; 赠送源代码:shiro-crypto-cipher-1.4.0-sources.jar; 赠送Maven依赖信息文件:shiro-crypto-cipher-1.4.0....
Gronsfeld cipher algorithm.
java实现加密解密算法工具类_Cipher
plexus-cipher-1.4.jar
cipher.exe命令使用方法,有举例。 一、加密目录文件夹和文件 二、查询加密目录和加密文件 三、解密目录文件夹 四、导出证书和私匙 Cipher 命令详解
Cipherlab 9600 API(包含.NET、C#平台),对开发9600应用程序非常有帮助。
AES加密的几张方法包括javax.crypto.Cipher 的net实现方式
Playfair Cipher 普雷費爾的加密程式~ 把一些註解拿掉就可以看到TABLE!
block cipher implementation
CipherLab 8000 DLL,用于程序的二次开发,引用后可从盘点机直接读取其中的数据
欣技 8000 cipherlab C 语言 开发 样例。