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(字符串?)的更多相关文章

  1. [LeetCode] Add Strings 字符串相加

    Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. ...

  2. [LeetCode] Multiply Strings 字符串相乘

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  3. 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 ...

  4. 【LeetCode每天一题】Multiply Strings(字符串乘法)

    Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and ...

  5. [LeetCode] 43. Multiply Strings ☆☆☆(字符串相乘)

    转载:43. Multiply Strings 题目描述 就是两个数相乘,输出结果,只不过数字很大很大,都是用 String 存储的.也就是传说中的大数相乘. 解法一 我们就模仿我们在纸上做乘法的过程 ...

  6. LeetCode OJ:Multiply Strings (字符串乘法)

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  7. [Leetcode] Multiply strings 字符串对应数字相乘

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  8. Multiply Strings(字符串乘法模拟,包含了加法模拟)

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  9. [LeetCode] 415. Add Strings 字符串相加

    Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. ...

随机推荐

  1. 《JavaScript模式》读书笔记

    简介 在软件开发过程中,模式是指一个通用问题的解决方案.一个模式不仅仅是一个可以用来复制粘贴的代码解决方案,更多地是提供了一个更好的实践经验.有用的抽象化表示和解决一类问题的模板. 对象有两大类: 本 ...

  2. 从零单排Linux – 3 – 目录结构

    从零单排Linux – 3 – 目录结构 1.FHS标准(filesystem hierarchy standard) why? –> 为了规范,还有为了linux的发展 重点 –> 规范 ...

  3. Java Concurrency - 取消线程执行器中的线程

    When you work with an executor, you don't have to manage threads. You only implement the Runnable or ...

  4. Servlet & JSP - UrlRewriteFilter

    重写 URL 的好处有很多: 静态化页面,有利于搜索引擎收录. 隐藏真实的 URL,提高安全性. 当网站的结构发生变化时,无需要求用户修改书签. UrlRewriteFilter 的简单应用 1. M ...

  5. Linux 命令 - wc: 统计文件的行数、字数和字节数

    命令格式 wc [OPTION]... [FILE]... 命令格式 -c, --bytes 打印字节数. -m, --chars 打印字符数. -l, --lines 打印行数. -L, --max ...

  6. Python基础-简单输出

    很好的一个博客地址:http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014316 ...

  7. 北大ACM(POJ1753-Flip Game)

    Question:http://poj.org/problem?id=1753 问题点:穷举. #include <iostream> using namespace std; ][];/ ...

  8. 第六十四篇、OC_计步器

    计步器的实现方式主要有那么两种 1.通过直接调用系统的健康数据,基于HealthKit框架的,但是貌似是一小时更新一次数据.如果要实时获取步数,这种方式并不是最佳. 2.基于CoreMotion框架, ...

  9. iOS的沙箱目录和文件操作

    一.沙箱 iOS的每一个应用程序都有自己的目录来存放数据,这个目录称为沙箱目录.沙箱目录是一种数据安全策略,它设计的原理是只能允许自己的应用访问目录,而不允许其他的应用访问,这样可以保证数据的安全,应 ...

  10. (转)Ubuntu 12.04 LTS 构建高可用分布式 MySQL 集群

    本文的英文版本链接是 http://www.mrxuri.com/index.php/2013/11/20/install-mysql-cluster-on-ubuntu-12-04-lts.html ...