博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF 1005B Delete from the Left 【模拟数组操作/正难则反】
阅读量:6540 次
发布时间:2019-06-24

本文共 3497 字,大约阅读时间需要 11 分钟。

You are given two strings s and t. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by 1. You can't choose a string if it is empty.

For example:

by applying a move to the string "where", the result is the string "here",

by applying a move to the string "a", the result is an empty string "".
You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings.

Write a program that finds the minimum number of moves to make two given strings s and t equal.

Input

The first line of the input contains s. In the second line of the input contains t. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and 2⋅105, inclusive.

Output

Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.

Examples

Input
test
west
Output
2
Input
codeforces
yes
Output
9
Input
test
yes
Output
7
Input
b
ab
Output
1
Note
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".

In the second example, the move should be applied to the string "codeforces" 8 times. As a result, the string becomes "codeforces" → "es". The move should be applied to the string "yes" once. The result is the same string "yes" → "es".

In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty.

In the fourth example, the first character of the second string should be deleted.

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define debug() puts("++++")#define gcd(a,b) __gcd(a,b)#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define fi first#define se second#define pb push_back#define sqr(x) ((x)*(x))#define ms(a,b) memset(a,b,sizeof(a))#define sz size()#define be begin()#define pu push_up#define pd push_down#define cl clear()#define lowbit(x) -x&x#define all 1,n,1#define rep(i,x,n) for(int i=(x); i<(n); i++)#define in freopen("in.in","r",stdin)#define out freopen("out.out","w",stdout)using namespace std;typedef long long ll;typedef unsigned long long ULL;typedef pair
P;const int INF = 0x3f3f3f3f;const ll LNF = 1e18;const int N = 1e3 + 20;const int maxm = 1e6 + 10;const double PI = acos(-1.0);const double eps = 1e-8;const int dx[] = {-1,1,0,0,1,1,-1,-1};const int dy[] = {0,0,1,-1,1,-1,1,-1};int dir[4][2] = { {0,1},{0,-1},{-1,0},{1,0}};const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};string a,b;/*给你两个字符串,只能选其中一个的最左字符删除,若不能删到相等就输出两串长之和,否则输出删除字符数*/int main(){ while(cin>>a>>b) { int c=0; reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); rep(i,0,min(a.size(),b.size())) { if(a[i]==b[i]) c++; else break; } cout<
<

转载于:https://www.cnblogs.com/Roni-i/p/9347994.html

你可能感兴趣的文章
mysql 缓存开启及测试
查看>>
自己写的进度条###
查看>>
windows磁盘扩容(动态磁盘)
查看>>
在jsp页面中添加富文本编译器(ueditor)+ 图片上传功能
查看>>
fedora12下安装oracle11客户端
查看>>
实现批量添加20个用户,用户名为user1-50,密码为user后面跟5个随机字符
查看>>
LVM磁盘管理
查看>>
Net命令详解
查看>>
CentOS linux 高可用集群之heartbeat
查看>>
用bat更改hosts文件批处理
查看>>
Logwatch日志分析工具
查看>>
docker 基本操作Ⅱ(关于镜像操作)
查看>>
分工與合作
查看>>
轻松设置站点对ASP危险组件的调用权限
查看>>
看懂“拜占庭容错”,也就看懂了区块链的核心技术
查看>>
APMServ 5.2.6 Win7 Apache启动失败,请检查相关配置
查看>>
了解痘痘起因才能彻底告别痘痘烦恼
查看>>
Zabbix安装
查看>>
Java 日志 详解
查看>>
openstack虚拟化技术和镜像制作
查看>>