题目链接:http://cpp.zjut.edu.cn/ShowProblem.aspx?ShowID=1885

题面:

Careless Tony 
Time Limit:1000MS  Memory Limit:32768K

Description:

Tony is such a careless typist that he finds himself making mistakes AGAIN. What's worse, the cursor key is not working so that he can only use the backspace key to reach the place where the mistake is, and then type whatever he's deleted on the way AGAIN :(
Now let's help Tony find out at least how long it will cost him to correct his mistake.

Input:

The first line of input contains an integer N, which is the number of test cases. Then N test cases follow.<BR> Each test case consists of 3 lines of input: the 1st line contains a positive integer t (<= 100), which is the time taken for Tony to delete/input a character; the 2nd line contains the correct content of text; and the 3rd line contains the text typed by Tony.<BR> Note: The text contents contain only the readable characters. The total length of each text is no longer than 80 characters.<BR>

Output:

For each test case, print in one line the minimal time taken for Tony to correct his mistake.

Sample Input:

2
1
WishingBone
WashingBone
1
Oops
Oooops

Sample Output:

20
6

题意:

最少用多少时间修改后面那个串到前面那个串。

代码:

#include <iostream>
#include <string>
using namespace std;
int main()
{int n,t;string s1,s2;bool flag;int p;cin>>n;while(n--){cin>>t;cin>>s1>>s2;flag=true;p=0;for(int i=0;i<s1.length()&&i<s2.length();i++){if(s1[i]!=s2[i]){flag=false;p=i;break;}}if(flag){if(s1.length()>=s2.length()){cout<<t*(s1.length()-s2.length())<<endl;}else{cout<<(s2.length()-s1.length())*t<<endl;}}else{cout<<(s1.length()+s2.length()-2*p)*t<<endl;}} return 0;
}

Cpp Careless Tony相关推荐

  1. zoj 1582 Careless Tony(水!)

    题目上说The text contents contain only the readable characters. ..几个WA证明...输入的内容中有空格!!! 第一次用string写,感觉挺方 ...

  2. C++ .h(头文件) 与 .cpp(源文件) 的使用

    .h 文件: .h是头文件 ,里面主要是写类的声明(包括类里面的成员和方法的声明).函数原型.#define常数等, 注意.h文件写的时候有特定的格式就是开头和结尾 #ifndef TEST_HEAD ...

  3. 利用VS+MFC+Opencv显示图像和视频所需添加类(CvvImage.h和CvvImage.cpp的源码)。

    CvvImage.h代码: #pragma once #ifndef CVVIMAGE_CLASS_DEF #define CVVIMAGE_CLASS_DEF #include "open ...

  4. UTF-8 CPP的使用

    UTF-8 CPP是一个简单.小巧.轻量级.跨平台的UTF-8编码字符串库. 下面对其使用方法进行简单的介绍: 1.      从http://sourceforge.net/projects/utf ...

  5. 拇指接龙游戏升级记录03(升级MainScene.cpp)

    MainScene是拇指接龙游戏的主游戏场景文件,拥有近5000行代码. 说实在的,实现自cocos2d-x 2.x版本向当下最新的3.8.1版本的升级过程,其中涉及的技术不是一下能够说明的.有些是形 ...

  6. GATB的使用小例子test.cpp

    1.touch test.cpp,,文件夹中 出现test.cpp touch test.cpp 2. test.cpp的内容 #include <gatb/gatb_core.hpp>i ...

  7. Linux下运行.cpp文件

    如何在Ubuntu16下运行一个简单的.cpp文件呢,做法如下: 假设我在桌面上写了一个hell,world程序; 保存为abc.cpp 然后在终端打开: 1.点击保存的文件的属性,看在哪里,我的是在 ...

  8. 2020-10-26runtime error: member access within null pointer of type ‘struct ListNode‘ (solution.cpp)错

    runtime error: member access within null pointer of type 'struct ListNode' (solution.cpp)错误 /*** Def ...

  9. matlab怎么跑.cpp程序,MATLAB编译cpp文件

    目的:打通MATLAB与VC之间的通道,实现用MATLAB调用VC程序,以及VC调用MATLAB程序. 上篇博客实现了将MATLAB的M文件编译成C/C++文件,exe应用程序.这篇实现MATLAB编 ...

  10. python如何调用cpp文件的接口函数_C++中嵌入Python调用

    python嵌入到C++中 把python嵌入的C++里面需要做一些步骤 安装python程序,这样才能使用python的头文件和库 在我们写的源文件中增加"Python.h"头文 ...

最新文章

  1. cookie和session的理解
  2. 使用Filter跟踪Asp.net MVC页面加载(转)
  3. Android 的全盘加密容易破解
  4. 欧几里德投影(Euclidean projection)
  5. 迷你linux设备,ComputeLab发布MintBox迷你PC:专为Linux系统玩家打造
  6. https无法访问 宝塔_宝塔面板快速开启ssl(https)的方法
  7. eclipse下开发简单的Java Web Service
  8. 数据库实验8 数据库安全性(用户与权限管理)实验
  9. java热门编程题_java经典50编程题(1-10)
  10. win7开机提示由于系统注册表文件丢失或损坏因此无法加载怎么办
  11. JNi调用过程(转载)
  12. Object类型转换为int型
  13. 卖桃者说(1)有效学习
  14. FW: 10家不错的iphone编程资源站
  15. 【生产调度】基于Harmony Search (HSPMS) 和 Shuffled Complex Evolution (SCEPMS) 实现并行机器调度附matlab代码
  16. 不要用战术上的勤奋掩盖战略上的懒惰
  17. excel组合汇总_Excel汇总20140602
  18. 常用运行命令win10
  19. Promise的作用及用法
  20. 数据库日常运维操作手册

热门文章

  1. 扁豆凝集素/红藻凝集素GRFT/蓝藻凝集素CVN/香蕉凝集素H84-植物凝集素
  2. Android配置启动页
  3. EasyGUI-5:文本显示
  4. 小白入门指南|zookeeper快速入门
  5. Ubuntu16.04 安装LSD-SLAM
  6. yum 装包时,提示Peer cert cannot be verified or peer cert invalid
  7. 微众银行电话面试java_微众银行面试经验
  8. couchbase 报 The Content of this Observable is already released. Subscribe earlier or tune the Couch
  9. 从一个帝国的消逝,看商业组织的进化
  10. 服务器交换机在机柜位置,1米2米1.2米机柜22u24u网络服务器交换机图腾机柜