bnuoj 29375 Two Strings(字符串?)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=29375
【题意】:可以对两字符串进行如下操作:
1、可以无损耗交换相邻两个字符(可以理解成交换任意字符)
2、可以改变一个字符 x->y ,花费为 x-y 的绝对值
求花费最少,将两字符串变成一样
【题解】:
排序字符串,然后对应相减
【code】:
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm> using namespace std; char str1[],str2[]; int abs(int a)
{
return a<?-a:a;
} int main()
{
int t,cas=;
scanf("%d",&t);
while(t--)
{
int m;
scanf("%d",&m);
scanf("%s",str1);
scanf("%s",str2);
sort(str1,str1+m);
sort(str2,str2+m);
int i,ans=;
for(i=;i<m;i++)
{
ans+=abs(str1[i]-str2[i]);
}
printf("Case %d: %d\n",cas++,ans);
}
return ;
}
bnuoj 29375 Two Strings(字符串?)的更多相关文章
- [LeetCode] Add Strings 字符串相加
Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. ...
- [LeetCode] Multiply Strings 字符串相乘
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- Codeforces Round #358 (Div. 2) D. Alyona and Strings 字符串dp
题目链接: 题目 D. Alyona and Strings time limit per test2 seconds memory limit per test256 megabytes input ...
- 【LeetCode每天一题】Multiply Strings(字符串乘法)
Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and ...
- [LeetCode] 43. Multiply Strings ☆☆☆(字符串相乘)
转载:43. Multiply Strings 题目描述 就是两个数相乘,输出结果,只不过数字很大很大,都是用 String 存储的.也就是传说中的大数相乘. 解法一 我们就模仿我们在纸上做乘法的过程 ...
- LeetCode OJ:Multiply Strings (字符串乘法)
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- [Leetcode] Multiply strings 字符串对应数字相乘
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- Multiply Strings(字符串乘法模拟,包含了加法模拟)
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- [LeetCode] 415. Add Strings 字符串相加
Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. ...
随机推荐
- 【转】ora-00031:session marked for kill(标记要终止的会话)解决方法
今天碰到一个问题,有一张表不能操作,很可能是被锁了,首先想到的是kill session,于是执行了下列的脚本找到是哪个session有问题: select object_name, machine, ...
- JavaScript面试问题:事件委托和this
JavaScript不仅门槛低,而且是一门有趣.功能强大和非常重要的语言.各行各业的人发现自己最混乱的选择是JavaSscript编程语言.由 于有着各种各样的背景,所以不是每个人都对 ...
- SAX - DefaultHandler
org.xml.sax.helpers.DefaultHandler 实现了 org.xml.sax.EntityResolver.org.xml.sax.DTDHandler.org.xml.sax ...
- Android PullToRefresh下拉刷新控件的简单使用
PullToRefresh这个开源库早就听说了,不过一直没用过.作为一个经典的的开源库,我觉得还是有必要认识一下. 打开github上的网址:https://github.com/chrisbanes ...
- 免费主机kilu使用
我也是看了这篇文章:http://www.cnblogs.com/tenny/archive/2011/03/30/1999957.html 采取申请注册. 主机申请地址:http://www.kil ...
- Quartz 第三课 More About Jobs & JobDetails(官方文档翻译)
当学完第二课之后,你欣喜的发现,让jobs工作起来是还是相当简单的.虽然让jobs运行起来很简单,对于其执行的关键内容还是需要知道的.它们是IJob接口中的Execute和JobDetails. 当你 ...
- DOM_节点层次
一.DOM1级定义了一个Node接口,这个接口是由DOM中的所有节点类型实现的.Node接口共有12种节点类型,常见的是元素节点.文本节点和文档节点. Node.ELEMENT_NODE(1);——元 ...
- class不想被复制的两个做法
1,当一个class不想被复制的时候,可以将copy构造函数和copy assignment操作符声明为private.(只声明不定义,因此可以不指定函数参数) 2,或者,继承一个专门为了阻止copy ...
- vs2010创建COM以及调用
1,创建COM组件 2,调用COM 3,MFC调用COM
- 关于RadAsm中GetEnvironmentStrings的BUG。
今天在asm中不通过msvcrt.inc调用c库. 所以.第一时间就在vc的lib中拷贝了libc.lib问价.加入工程后. 声明.调用如下: 然后.链接报错. libc.lib(crt0.obj) ...