WOJ1288-Changing String
来源:互联网 发布:windows安装git 编辑:程序博客网 时间:2024/06/10 03:10
You are given two Strings A and B that have the same length and contain only lowercase letters ('a'-'z').
The distance between two letters is defined as the absolute value of their difference. The distance between A and B is defined as the sum of the differences between each letter in A and the letter in B at the same position.
For example, the distance between "abcd" and "bcda" is 6 (1 + 1 + 1 + 3).
You must change exactly K characters in A into other lowercase letters. print the minimum possible distance between A and B after you perform that change.
输入格式
There will be multiple test cases. The first line of input contains a positive integer T, indicating the number of cases. In the following T lines, there are two strings A and B, and an integer K seprated by one space in a single line. you can assume A and B have the same length(0<length<=10000), and 1<= K <=A or B's length.
输出格式
For each test case, output an integer indicating the minimum possible distance between A and B after you perform that change.
样例输入
5ab ba 2aa aa 2aaa baz 1fdfdfdfdfdsfabasd jhlakfjdklsakdjfk 8aa bb 2
样例输出
021240
提示
in case 1, you change ab to ba, and then the minimum distance is 0;
in case 2, you change aa to bb, and then the minimum distance is 2;
in case 3, you change aaa to aaz, and then the minimum distance is 1;
...
#include<iostream>#include<algorithm>#include<cstdio>using namespace std;int main() {int t;scanf("%d",&t);while(t--) {string a,b;int k,i;cin >> a >> b >> k;int len = a.length();int ss[len];long int res = 0;for (i=0; i<len; i++) {ss[i] = ((b[i]>a[i]) ? (b[i]-a[i]) : (a[i]-b[i]));res += ss[i];}sort(ss,ss+len);for(i=len-1; i>(len-1-k); --i) {res -= (ss[i]==0) ? -1 : ss[i];}cout << res <<endl;}return 0;}
- WOJ1288-Changing String
- Codeforces Beta Round #52 (Div. 2) D - Changing a String
- codeforces 56D Changing a String 区间dp,字符串
- codeforces 56D Changing a String (dp编辑距离)
- Codeforces 56D Changing a String 编辑距离 记忆化dp
- 【CodeForces】501B - Misha and Changing Handles(STL - string & vector & pair)
- charset changing
- Always Changing
- Changing Bits
- changing environment
- D. Changing a String (编辑距离)(dp+记忆化)(dp后寻找路径大法)
- Programmatically Changing Database Icons
- Changing a Service Configuration
- TOEIC PLAN CHANGING
- Slowly Changing Dimension
- Changing Server Default Collation
- Changing Value's Address
- foj 1432 Coin Changing
- Java RMI 框架(远程方法调用Remote Method Invoke)
- C语言strcpy()库函数的实现
- 任正非致歉华为前程序员:回来吧,公司错了
- springMVC前台传递日期类型到后台
- 设置EditText获得焦点,同时弹出小键盘
- WOJ1288-Changing String
- 基于GPU加速的二维TTI介质一阶拟声波方程有限差分地震正演模拟
- Ruby 日期 & 时间(Date & Time)
- web.xml配置文件标签元素详解
- Spring之组件bean的生命周期
- 蘑菇街小程序开发系统公司
- linux下usb传输实现
- CSDN-markdown编辑器-使用手册
- c++11新特性的简单介绍