https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4085

两个字符串,判断能否把其中一个字符串重排,然后对每个字母进行映射(比如映射到前一个字母),使得两个字符串相同

这里要转一个弯,既然字母可以重排,那么每个字母最初的顺序并不重要,重要的是每个字母出现的次数,所以只要分别用数组保存每个字母出现的次数,在把这个数组从小到大排序,如果最后两个数组相同,那么这个问题的结果就是YES(可以使两个字符串相同)、

 #include<bits/stdc++.h>
using namespace std;
char s1[],s2[];
int a[],b[];
int main()
{
while(~scanf("%s %s",s1,s2))
{ memset(a,,sizeof(a));
memset(b,,sizeof(b));
for(int i=; i<strlen(s1); i++)
{
a[s1[i]-'A']++;
}
for(int i=; i<strlen(s2); i++)
{
b[s2[i]-'A']++;
}
sort(a,a+);
sort(b,b+);
int ans=;
for(int i=; i<; i++)
{
if(a[i]!=b[i])
{
ans=;
break;
}
}
if(ans)printf("YES\n");
else printf("NO\n");
memset(s1,'\0',sizeof(s1));
memset(s2,'\0',sizeof(s2));
} return ;
}

uvaoj1339 - Ancient Cipher(思维题,排序,字符串加密)的更多相关文章

  1. POJ2159 ancient cipher - 思维题

    2017-08-31 20:11:39 writer:pprp 一开始说好这个是个水题,就按照水题的想法来看,唉~ 最后还是懵逼了,感觉太复杂了,一开始想要排序两串字符,然后移动之类的,但是看了看 好 ...

  2. UVa 1339 Ancient Cipher --- 水题

    UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要, ...

  3. 2017广东工业大学程序设计竞赛初赛 题解&源码(A,水 B,数学 C,二分 D,枚举 E,dp F,思维题 G,字符串处理 H,枚举)

    Problem A: An easy problem Description Peter Manson owned a small house in an obscure street. It was ...

  4. UVa LA 3213 - Ancient Cipher 水题 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  5. 思维题:UVa1334-Ancient Cipher

    Ancient Cipher Ancient Roman empire had a strong government system with various departments, includi ...

  6. poj 2159 D - Ancient Cipher 文件加密

    Ancient Cipher Description Ancient Roman empire had a strong government system with various departme ...

  7. poj 1007:DNA Sorting(水题,字符串逆序数排序)

    DNA Sorting Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 80832   Accepted: 32533 Des ...

  8. hdu 1106:排序(水题,字符串处理 + 排序)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submissi ...

  9. HDU 1029 Ignatius and the Princess IV / HYSBZ(BZOJ) 2456 mode(思维题,~~排序?~~)

    HDU 1029 Ignatius and the Princess IV (思维题,排序?) Description "OK, you are not too bad, em... But ...

随机推荐

  1. Linear Search

    Search I You are given a sequence of n integers S and a sequence of different q integers T. Write a ...

  2. c#返回值的理解

    我感觉没什么用...就是在别的地方用的时候可以直接以Add(a,b)这样的方式赋值就行,不用再用c这个中间变量去接收了,希望有一天有大佬能给我讲讲设置返回值有什么好处

  3. tomcat配置APR

    转载 Windows下配置Tomcat的Apr(包括Https)  tomcat bio nio apr 模式性能测试与个人看法 一.windows 下配置Tomcat的APR: 1.到Apache  ...

  4. java使用类序列化反序列化(读写文件)

    创建类:Role package com.wbg.springRedis.entity; import java.io.Serializable; public class Role implemen ...

  5. openmax component类的继承关系

    向OpenCORE里继承一个新的codec时,需要用到OpenMAX接口规范对该codec进行封装,即要定义一个用于封装的类(wrapper),实现OpenMAX规定的集中核心方法(omx core  ...

  6. Non-Nullable Types vs C#: Fixing the Billion Dollar Mistake (转载)

    One of the top suggestions (currently #15 on uservoice) for improving C# is the addition of non-null ...

  7. bit and sbit---c51

    bit和sbit都是C51扩展的变量类型. bit和int char之类的差不多,只不过char=8位, bit=1位而已.都是变量,编译器在编译过程中分配地址.除非你指定,否则这个地址是随机的.这个 ...

  8. oracle 优化相关

    --选择最有效率的表名顺序:  Oracle的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 driving table)将被最先处理,  在FROM子句中包含多 ...

  9. jQuery 属性操作 - addClass() 和 removeClass() 方法

    实例 向第一个 p 元素添加一个类: $("button").click(function(){ $("p:first").addClass("int ...

  10. window下pip install Scrapy报错解决方案

    1.首先打开https://www.lfd.uci.edu/~gohlke/pythonlibs/#twisted,找到对应版本的Twisted并下载到你的文件夹. 2.利用pip install命令 ...