CF 1005B Delete from the left "analog array operation/hard to reverse"

Source: Internet
Author: User
Tags first string

You are given-strings s and T. In a single move, you can choose any of the strings and delete the first (which 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" and the result is the string "here",
By applying a move to the string "a" and the result is an empty string "".
You is required to make given strings equal using the fewest number of moves. It is possible that, in the end, both strings'll be a equal to the empty string, and so, was equal to each other. The answer is obviously the sum of the lengths of the initial strings.

Write A program This finds the minimum number of moves to make, given strings s and T equal.

Input
The first line of the input contains S. 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'll be a equal to the empty string, and so, was equal to each other. 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 is equal to "est".

In the second example, the move should is applied to the string "Codeforces" 8 times. As a result, the string becomes "codeforces" → "es". The move should is 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's, in the end, both strings'll be empty.

In the fourth example, the first character of the second string should is 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 Doub Le 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, 29, 31, 30, 3, +, 0, +,, +, +,, + 1, +,----31};string a,b;/* give you two strings, you can only select one of the leftmost characters to delete, if you can not delete the same output two strings long, otherwise the output deleted characters */int main () {while (cin>        &GT;A&GT;&GT;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 "analog array operation/hard reverse"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.