UVA 1339 Ancient Cipher(映射 | 想法)
来源:互联网 发布:淘宝多久自动好评 编辑:程序博客网 时间:2024/06/09 16:54
UVA 1339 Ancient Cipher
题意
给出两个字符串,可以重新排列可以自由映射,把其中的一个字符映射到另一个字符。询问是否存在一种一一映射方式,使得原来的字符串可以映射到目标字符串
解决
- 由于可以重新排列,所以字符的位置不重要(这点以后会游泳,记住)
- 由于本题中的映射只能一对一,所以要求如果我们记录下26个字符每个字符出现的次数,并对字符出现的次数进行排序,str1(原串)里一个字符出现了n次,那么对应str2(目标串)中也必须存在一个出现n次的字符(且没被用过)。
- 所以我们对两个串中字符出现次数进行排序,比较是否完全相同即可
#include <algorithm>#include <iostream>#include <cstring>#include <vector>#include <cstdio>#include <string>#include <cmath>#include <queue>#include <set>#include <map>#include <complex>using namespace std;typedef long long ll;typedef long double db;typedef pair<int,int> pii;typedef vector<int> vi;#define de(x) cout << #x << "=" << x << endl#define rep(i,a,b) for(int i=a;i<(b);++i)#define all(x) (x).begin(),(x).end()#define sz(x) (int)(x).size()#define mp make_pair#define pb push_back#define fi first#define se second#define E 1e-6#define INF 0x3f3f3f3f#pragma comment(linker, "/STACK:1024000000,1024000000")void open(){freopen("data.txt","r",stdin);}void out(){freopen("out.txt","w",stdout);}const int maxn = 101010;const int MOD = 1e9 + 7;int main(){ char str1[105],str2[105]; int cnt1[30],cnt2[30]; while(~scanf("%s",str1)) { scanf("%s",str2); memset(cnt1,0,sizeof(cnt1)); memset(cnt2,0,sizeof(cnt2)); int len1 = strlen(str1); int len2 = strlen(str2); rep(i,0,len1) cnt1[str1[i]-'A']++; rep(i,0,len2) cnt2[str2[i]-'A']++; sort(cnt1,cnt1+26); sort(cnt2,cnt2+26); bool ok = true; rep(i,0,26) if(cnt1[i]!=cnt2[i]) ok = false; if(ok) puts("YES"); else puts("NO"); }}
阅读全文
0 0
- UVA 1339 Ancient Cipher(映射 | 想法)
- UVA 1339 - Ancient Cipher
- uva 1339 Ancient Cipher
- Uva - 1339 - Ancient Cipher
- UVA 1339 - Ancient Cipher
- UVa:1339 Ancient Cipher
- UVA 1339 - Ancient Cipher
- UVA-1339 - Ancient Cipher
- UVa 1339 Ancient Cipher
- UVa 1339 Ancient Cipher
- UVa 1339 - Ancient Cipher
- UVa 1339 - Ancient Cipher
- uva 1339Ancient Cipher
- UVa 1339 - Ancient Cipher
- Uva 1339 - Ancient Cipher
- 【Uva 1339】 Ancient Cipher
- UVa-1339 - Ancient Cipher
- Uva - 1339 - Ancient Cipher
- 轻松搞定文本公式的计算
- ionic2 之 List
- 条件随机场随记2
- tRNAscan-SE使用说明
- 京东—幸运数
- UVA 1339 Ancient Cipher(映射 | 想法)
- 设置 SSH 使用 hexo deploy 时免输用户名密码
- ORACLE SQL语句优化技术
- Android 事件分发机制
- 使用 TestNG 创建一个数据驱动测试过程中遇到的问题
- Spring定时任务
- 正则_字符组笔记
- hashCode方法和equals方法
- syntax error near unexpected token shell