CF 1005B Delete from the Left 【模拟数组操作/正难则反】
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<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#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<int,int> 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<<a.size()+b.size()-2*c<<endl;
}
}
CF 1005B Delete from the Left 【模拟数组操作/正难则反】的更多相关文章
- 51nod 1050 循环数组最大子段和【环形DP/最大子段和/正难则反】
1050 循环数组最大子段和 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 N个整数组成的循环序列a[1],a[2],a[3],…,a[n],求该 ...
- 使用KFold进行训练集和验证集的拆分,使用准确率和召回率来挑选合适的阈值(threshold) 1.KFold(进行交叉验证) 2.np.logical_and(两bool数组都是正即为正) 3.np.logical_not(bool数组为正即为反,为反即为正)
---恢复内容开始--- 1. k_fold = KFold(n_split, shuffle) 构造KFold的索引切割器 k_fold.split(indices) 对索引进行切割. 参数说明:n ...
- .NET 下 模拟数组越界
前面一篇文章提到过 数组越界行为,虽然编译器为我们做了大量的检查工作让我们避免这些错误. 但是我觉得还是有必要模拟一下数组越界,感受一下这个错误. 那么对于.NET来说我们怎么来模拟数组越界呢? 一. ...
- cf 443 D. Teams Formation](细节模拟题)
cf 443 D. Teams Formation(细节模拟题) 题意: 给出一个长为\(n\)的序列,重复\(m\)次形成一个新的序列,动态消除所有k个连续相同的数字,问最后会剩下多少个数(题目保证 ...
- Leetcode 566. Reshape the Matrix 矩阵变形(数组,模拟,矩阵操作)
Leetcode 566. Reshape the Matrix 矩阵变形(数组,模拟,矩阵操作) 题目描述 在MATLAB中,reshape是一个非常有用的函数,它可以将矩阵变为另一种形状且保持数据 ...
- PHP模拟链表操作
PHP模拟链表操作 一.总结 1.类成员用的是-> 2.对象节点相连的话,因为是对象,所以不用取地址符号 3.数组传递参数的时候传引用的方法 ,& 二.PHP模拟链表操作 代码一: /* ...
- Javascript数组操作
使用JS也算有段时日,然对于数组的使用,总局限于很初级水平,且每每使用总要查下API,或者写个小Demo测试下才算放心,一来二去,浪费不少时间:思虑下,堪能如此继续之?当狠心深学下方是正道. 原文链接 ...
- JavaScript中常见的数组操作函数及用法
JavaScript中常见的数组操作函数及用法 昨天写了个帖子,汇总了下常见的JavaScript中的字符串操作函数及用法.今天正好有时间,也去把JavaScript中常见的数组操作函数及用法总结一下 ...
- jQuery_03之事件、动画、类数组操作
一.事件: 1.模式触发事件: ①DOM:elem.onXXX();只能触发直接用onXXX绑定的事件处理函数:用addEventistener添加的事件监听无法模拟出发触发: ②jQuery:$ ...
随机推荐
- Struts1之html标签
Struts1的html标签主要是为了绘制HTML页面标签元素,通过与Struts1框架的集成,增强功能 首先,在使用前,需要引入tld文件 <%@ taglib prefix="ht ...
- servletContex.getRealPath 获取的是拼接后的地址 是虚假的
servletContex.getRealPath 获取的是拼接后的地址 是虚假的
- python 的sets list dictionary
http://blog.csdn.net/joseph_happy/article/details/6717412 http://blog.csdn.net/joseph_happy/article/ ...
- webstorm中把style的内容隐藏,如何把style的内容展开?
我们经常看到在webstorm中style的内容以...表示如下图所示,只有把光标移到上面时才会看到内容: 如何把上述的style的内容展开呢? 请按一下步骤操作: 第一步:File------> ...
- codeforces2015ICL,Finals,Div.1#J Ceizenpok’s formula 扩展Lucas定理 扩展CRT
默默敲了一个下午,终于过了, 题目传送门 扩展Lucas是什么,就是对于模数p,p不是质数,但是不大,如果是1e9这种大数,可能没办法, 对于1000000之内的数是可以轻松解决的. 题解传送门 代码 ...
- js如何弹出新窗口
js如何弹出新窗口 时间:2012-4-22 弹出新窗口也是在网页设计中会经常用到的,其用法也很简单,是通过调用javascript的内置函数windows.open来产生的. window.ope ...
- 浏览器web端详解
一.背景介绍浏览器是前端工程师或页面重构师工作中必不可少的,WEB页面运行在各种各样的浏览器当中,浏览器载入.渲染页面的速度直接影响着用户体验,特别是浏览器渲染页面的原理,页面渲染就是浏览器将HTML ...
- Django【进阶】FBV 和 CBV
django中请求处理方式有2种:FBV 和 CBV 一.FBV FBV(function base views) 就是在视图里使用函数处理请求. 看代码: urls.py 1 2 3 4 5 6 7 ...
- postman发送post请求,报405 Method Not Allowed
postman发送post请求,报405 Method Not Allowed: 亲测有效的方案一: 检查请求header是否缺少必要信息.如果不清可以把所有的头部信息全部粘贴到header中,尝试是 ...
- ggplot2绘制多图
参考链接:http://www.cnblogs.com/nxld/p/6065237.html ggplot2.multiplot是一个易于使用的功能,将多个图形在同一页面上使用R统计软件和GGPLO ...