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. ...
随机推荐
- loadrunner做webservice接口之简单调用
今天听大神讲了webservice做接口,我按照他大概讲的意思自己模拟实战了下,可能还有很多不对,一般使用webservice做接口,会使用到soapui,但是用了loadrunner以后发现lr很快 ...
- poj 2524 Ubiquitous Religions(宗教信仰)
Ubiquitous Religions Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 30666 Accepted: ...
- 改变xmind显示中文界面
最近打算迁移到ubuntu系统做为主系统,打算使用xmind这个工具,因为我的ubuntu并没有使用简体中文,xmind是根据系统的语种来自动选择的,所以也直接为英文界面,实在使用不习惯,查到了这篇文 ...
- Servlet & JSP - Servlet API Overview
Servlet & Generic & HttpServlet 类图 Servlet 的生命周期 init.service 和 destroy 是 servlet 的生命周期方法,它们 ...
- Linux 命令 - killall: 通过进程名向进程发送信号
命令格式 killall [-Z CONTEXT] [-u USER] [ -eIgiqrvw ] [ -SIGNAL ] NAME... killall -l, --list killall -V, ...
- Nginx - Additional Modules, Limits and Restrictions
The following modules allow you to regulate access to the documents of your websites — require users ...
- 【分享】.Net有哪些大型项目、大型网站的案例?
.Net开发的部分知名网站案例:http://www.godaddy.com 全球最大域名注册商http://www.ips.com 环迅支付,国内最早的在线支付平台http://www.icbc ...
- From MSI to WiX, Part 4 - Features and Components by Alex Shevchuk
Following content is directly reprinted from : http://blogs.technet.com/b/alexshev/archive/2008/08/2 ...
- Bugzilla 使用指南
Bugzilla安装见前一篇博客,本篇文章主要关注于如何高效合理的使用Bugzilla,作为为公司内部人员的培训使用指南. Bugzilla是一个开源的缺陷跟踪系统,它可以管理软件开发过程中缺陷的提交 ...
- java学习笔记_GUI(3)
如何加入自己定义的Panel import javax.swing.*; import java.awt.event.*; import java.awt.*; 5 class MyPanel ext ...