def shyam_and_strings(s1, s2, k):
n, m = len(s1), len(s2)
dp = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(n + 1):
for j in range(m + 1):
if i == 0 or j == 0:
dp[i][j] = 0
else:
cnt = 0
if s1[i - 1] != s2[j - 1]:
cnt = min(abs(ord(s1[i - 1]) - ord(s2[j - 1])), 26 - abs(ord(s1[i - 1]) - ord(s2[j - 1])))
if cnt <= k:
dp[i][j] = 1 + dp[i - 1][j - 1]
dp[i][j] = max(dp[i][j], max(dp[i - 1][j], dp[i][j - 1]))
return dp[n][m]
s1 = input().strip()
s2 = input().strip()
k = int(input().strip())
if not s1 or not s2:
print(0)
else:
print(shyam_and_strings(s1, s2, k), end="")
Pls share
https://t.me/TCS_Codevita_Exam_Help
n, m = len(s1), len(s2)
dp = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(n + 1):
for j in range(m + 1):
if i == 0 or j == 0:
dp[i][j] = 0
else:
cnt = 0
if s1[i - 1] != s2[j - 1]:
cnt = min(abs(ord(s1[i - 1]) - ord(s2[j - 1])), 26 - abs(ord(s1[i - 1]) - ord(s2[j - 1])))
if cnt <= k:
dp[i][j] = 1 + dp[i - 1][j - 1]
dp[i][j] = max(dp[i][j], max(dp[i - 1][j], dp[i][j - 1]))
return dp[n][m]
s1 = input().strip()
s2 = input().strip()
k = int(input().strip())
if not s1 or not s2:
print(0)
else:
print(shyam_and_strings(s1, s2, k), end="")
Pls share
https://t.me/TCS_Codevita_Exam_Help
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x, y, x1, y1, x2, y2;
cin >> x >> y >> x1 >> y1 >> x2 >> y2;
x = abs(x);
y = abs(y);
x1 = abs(x1);
y1 = abs(y1);
x2 = abs(x2);
y2 = abs(y2);
int r1 = sqrt(((x1 - x) * (x1 - x)) + ((y1 - y) * (y1 - y)));
int r2 = sqrt(((x2 - x) * (x2 - x)) + ((y2 - y) * (y2 - y)));
int a1 = M_PI * r1 * r1;
int a2 = M_PI * r2 * r2;
if (a2 > a1)
{
int e = a2 - a1;
int f = sqrt(e);
int g = f * f;
int h = g - e;
int i = h * 20;
cout << "Krishna " << i;
}
else if (a1 > a2)
{
int p = a1 - a2;
int q = p * 20;
cout << "Shiva " << q;
}
else if (a1 == a2)
{
cout << "-1";
}
return 0;
}
Fencing Problem
Pls share
https://t.me/TCS_Codevita_Exam_Help
using namespace std;
int main()
{
int x, y, x1, y1, x2, y2;
cin >> x >> y >> x1 >> y1 >> x2 >> y2;
x = abs(x);
y = abs(y);
x1 = abs(x1);
y1 = abs(y1);
x2 = abs(x2);
y2 = abs(y2);
int r1 = sqrt(((x1 - x) * (x1 - x)) + ((y1 - y) * (y1 - y)));
int r2 = sqrt(((x2 - x) * (x2 - x)) + ((y2 - y) * (y2 - y)));
int a1 = M_PI * r1 * r1;
int a2 = M_PI * r2 * r2;
if (a2 > a1)
{
int e = a2 - a1;
int f = sqrt(e);
int g = f * f;
int h = g - e;
int i = h * 20;
cout << "Krishna " << i;
}
else if (a1 > a2)
{
int p = a1 - a2;
int q = p * 20;
cout << "Shiva " << q;
}
else if (a1 == a2)
{
cout << "-1";
}
return 0;
}
Fencing Problem
Pls share
https://t.me/TCS_Codevita_Exam_Help
def max_points(chocolates,initial):
chocolates=sorted(chocolates)
points=1
l=[1]
i=0
while i < len(chocolates):
if chocolates[i]<=initial:
initial=initial-chocolates[i]
points+=1
i+=1
else:
points-=1
initial+=chocolates[-1]
chocolates.pop()
l.append(points)
return max(l)
# Example usage:
chocolates_list = list(map(int, input().split())) # Input list of chocolates
initial_chocolates = int(input()) # Initial chocolates Bittu has
result = max_points(chocolates_list, initial_chocolates)
print(result,end="")
Chocolate Code
Pls share
https://t.me/TCS_Codevita_Exam_Help
chocolates=sorted(chocolates)
points=1
l=[1]
i=0
while i < len(chocolates):
if chocolates[i]<=initial:
initial=initial-chocolates[i]
points+=1
i+=1
else:
points-=1
initial+=chocolates[-1]
chocolates.pop()
l.append(points)
return max(l)
# Example usage:
chocolates_list = list(map(int, input().split())) # Input list of chocolates
initial_chocolates = int(input()) # Initial chocolates Bittu has
result = max_points(chocolates_list, initial_chocolates)
print(result,end="")
Chocolate Code
Pls share
https://t.me/TCS_Codevita_Exam_Help
def pfix(exq):
ta = []
ops = set(['+', '-', '*', '/', '%', '^'])
to = exq.split()
for t1 in reversed(to):
if t1.isdigit():
ta.append(int(t1))
elif t1 in ops:
if t1 == '^':
if len(ta) < 2:
return "expression is not complete or invalid"
ex1 = ta.pop()
be = ta.pop()
ta.append(ex1**be)
elif t1 == '/':
if len(ta) < 2 or ta[-1] == 0:
return "expression is not complete or invalid"
op2 = ta.pop()
op1 = ta.pop()
ta.append(op1 // op2)
elif t1 == '%':
if len(ta) < 2 or ta[-1] == 0:
return "expression is not complete or invalid"
op2 = ta.pop()
op1 = ta.pop()
ta.append(op2 % op1)
else:
if len(ta) < 2:
return "expression is not complete or invalid"
op1 = ta.pop()
op2 = ta.pop()
if t1 == '+':
ta.append(op1 + op2)
elif t1 == '-':
ta.append(op1 - op2)
elif t1 == '*':
ta.append(op1 * op2)
else:
return "expression is not complete or invalid"
if len(ta) == 1:
return ta[0]
else:
return "expression is not complete or invalid"
dn2 = {
"one":1,
"two":2,
"three":3,
"four":4,
"five":5,
"six":6,
"seven":7,
"eight":8,
"nine":9,
"zero":0
}
do1 = {
"add":'+',
"sub":'-',
"mul":'*',
"rem":'%',
"pow":'^'
}
def conv(s):
a1= s.split('c')
nx= 0
for i in a1:
if i in dn2:
nx = nx*10 + dn2[i]
else:
return "-1"
return str(nx)
s= input()
lee = s.split()
st = ""
flag = False
for i in lee:
if i not in do1:
jik = conv(i)
if jik=="-1":
flag = True
print("expression evaluation stopped invalid words present",end='')
break
st = st + jik + ' '
else:
st = st + do1[i] + ' '
if flag != True:
print(pfix(st),end='')
No more symbols Code
Pls share
https://t.me/TCS_Codevita_Exam_Help
ta = []
ops = set(['+', '-', '*', '/', '%', '^'])
to = exq.split()
for t1 in reversed(to):
if t1.isdigit():
ta.append(int(t1))
elif t1 in ops:
if t1 == '^':
if len(ta) < 2:
return "expression is not complete or invalid"
ex1 = ta.pop()
be = ta.pop()
ta.append(ex1**be)
elif t1 == '/':
if len(ta) < 2 or ta[-1] == 0:
return "expression is not complete or invalid"
op2 = ta.pop()
op1 = ta.pop()
ta.append(op1 // op2)
elif t1 == '%':
if len(ta) < 2 or ta[-1] == 0:
return "expression is not complete or invalid"
op2 = ta.pop()
op1 = ta.pop()
ta.append(op2 % op1)
else:
if len(ta) < 2:
return "expression is not complete or invalid"
op1 = ta.pop()
op2 = ta.pop()
if t1 == '+':
ta.append(op1 + op2)
elif t1 == '-':
ta.append(op1 - op2)
elif t1 == '*':
ta.append(op1 * op2)
else:
return "expression is not complete or invalid"
if len(ta) == 1:
return ta[0]
else:
return "expression is not complete or invalid"
dn2 = {
"one":1,
"two":2,
"three":3,
"four":4,
"five":5,
"six":6,
"seven":7,
"eight":8,
"nine":9,
"zero":0
}
do1 = {
"add":'+',
"sub":'-',
"mul":'*',
"rem":'%',
"pow":'^'
}
def conv(s):
a1= s.split('c')
nx= 0
for i in a1:
if i in dn2:
nx = nx*10 + dn2[i]
else:
return "-1"
return str(nx)
s= input()
lee = s.split()
st = ""
flag = False
for i in lee:
if i not in do1:
jik = conv(i)
if jik=="-1":
flag = True
print("expression evaluation stopped invalid words present",end='')
break
st = st + jik + ' '
else:
st = st + do1[i] + ' '
if flag != True:
print(pfix(st),end='')
No more symbols Code
Pls share
https://t.me/TCS_Codevita_Exam_Help