UVa1339 - Ancient Cipher
2015-11-10 22:41
330 查看
题意:给出两个字符串,看是否是经过加密的,主要有两种加密方式,一种是替换加密,一种是排列加密(改变顺序)
思路:统计字符出现的次数,然后将次数排序,看是否相等
代码如下:
思路:统计字符出现的次数,然后将次数排序,看是否相等
代码如下:
#include <iostream> #include <fstream> #include <string> #include <cstring> #include <algorithm> using namespace std; const int N = 26; int c1 , c2 ; int main() { string s1, s2; #ifndef ONLINE_JUDGE ifstream fin("F:\\OJ\\uva_in.txt"); streambuf *old = cin.rdbuf(fin.rdbuf()); #endif while (cin >> s1 >> s2) { if (s1.length() != s2.length()) { cout << "NO" << endl; continue; } memset(c1, 0, sizeof(c1)); memset(c2, 0, sizeof(c2)); for (string::size_type i = 0; i < s1.length(); i++) { c1[s1[i] - 'A']++; c2[s2[i] - 'A']++; } sort(c1, c1 + N); sort(c2, c2 + N); if (memcmp(c1, c2, sizeof(c1)) != 0) { cout << "NO" << endl; } else { cout << "YES" << endl; } } #ifndef ONLINE_JUDGE cin.rdbuf(old); #endif return 0; }
相关文章推荐
- LeetCode 22 Generate Parentheses(生成括号)
- JavaScript学习笔记三
- 诚风老师-十年了,当年那帮做直销的穷小子都成了富豪
- The hidden implementation(被隐藏的具体实现)
- scanf注意事项
- SDWebImage
- leetcode 49:Group Anagrams
- 进击的KFC:UI(一)UIView及其子类
- python学习笔记(1)
- longestSubstring
- HDU 4739 Zhuge Liang's Mines(DP)
- /etc/fstab 只读无法修改的解决办法
- Android Studio 简单设置
- 高斯混合模型EM算法
- 4个Linux服务器监控工具
- Shiro使用和源码分析---6
- Java Spring的IoC和AOP的知识点速记
- JavaScript笔记二
- Java objectOutputStream的用法
- [kuangbin带你飞]专题一 简单搜索M - 非常可乐(HDU 1495)