B. Delete from the Left
Problem Link: Codeforces 1005B
Solution :
#include<bits/stdc++.h>
using namespace std;
int main()
{
char a[200005],b[200005];
scanf("%s",a);
scanf("%s",b);
int la=strlen(a),lb=strlen(b),sum=0;
for(int i=la-1,j=lb-1;i>=0||j>=0;i--,j--)
{
if(a[i]==b[j])
{
sum++;
}
else
{
break;
}
}
cout<<la+lb-sum*2<<endl;
}
s = input()
t = input()
sl=len(s)
tl=len(t)
while sl and tl and s[sl-1]==t[tl-1]:
sl-=1
tl-=1
print(sl+tl)
import java.util.*;
public class DeleteFromLeft {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String s=sc.next();String t=sc.next();
int n=s.length(),l=t.length(),cnt=0;
while(true) {
int i=n-cnt-1,j=l-cnt-1;
if(i>=0 &&j>=0 && s.charAt(i)==t.charAt(j))cnt++;
else break;
}
System.out.println(n+l-2*cnt);
}
}