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. ...
随机推荐
- C# 文件的读取、写入和删除
class Program { static void Main(string[] args) { EmployeeDAL DAL = new EmployeeDAL(); List<Sys_E ...
- Linux 命令 - kill: 向进程发送信号
kill 命令通常用来 “杀死”(终止)进程,它可以用来终止运行不正常的程序或者反过来拒绝终止的程序.kill 命令准确地说并不是 “杀死” 进程,而是给进程发送信号(signal). 和文件一样,进 ...
- C#保存上传来的图片示例代码
保存上传图片的方法有很多,在接下来的文章中为大家详细介绍下使用C#是如何做到的,感兴趣的朋友不要错过 复制代码代码如下: [HttpPost] public string UploadImage() ...
- 和阿文一起学H5--设计稿尺寸全攻略
- CSS之Win8界面摸拟
开门见山,先把测试Result放上: <head> <meta charset="UTF-8"> <meta http-equiv="X-U ...
- spring自定义注解
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- jqGrid Tree
CSS: <!--jqGrid--><link rel="stylesheet" href="plugins/jqgird/css/ui.jqgrid. ...
- 问题解决:两台虚拟机不能互相ping通的原因
要是两台虚拟机能够PING通下列要求缺一不可:1.你所设置的虚拟网络的网络号不能跟外面你正在使用的真实的网络号一样2.防火墙必须关闭3.你设置的那俩台虚拟机必须在同一网段内4.两台虚拟机的主机名不能相 ...
- UGUI之在场景中设置、修改标签和按钮
UnityGUI使用一个特殊的OnGUI()函数,在该函数中加入实现UI的脚本. 它一共有两种类型的接口:GUI.xxx()和GUILayout.xxx(). 第一种需要自动手写填写处于屏幕上的位置. ...
- windbg基本命令
1, .reload k 当前调用堆栈.u 当前正在执行的代码. 2, ~ 查看被调试进程中的线程信息每一行是一个线程的信息.第一行中,0 表示这个进程的编号:1ff4.1038 是 16 进制数字, ...