xxxxxxxxxx
"""
coronavirus
3
abcde
crnas
onarous
"""
# Iterative Python program to check if a
# string is a subsequence of another string
# Returns true if str1 is a subsequence of str2
def main(str1, str2):
m = len(str1)
n = len(str2)
j = 0 # Index of str1
i = 0 # Index of str2
# Traverse both str1 and str2
# Compare the current character of str2 with
# first unmatched character of str1
# If matched, then move ahead in str1
while j < m and i < n:
if str1[j] == str2[i]:
j = j+1
i = i + 1
# If all characters of str1 matched,
# then j is equal to m
return j == m
# Driver Program
str2 = str(input())
N = int(input())
for i in range(N):
str1 = str(input())
if main(str1, str2):
print("POSITIVE")
else:
print( "NEGATIVE")
xxxxxxxxxx
#include<stdio.h>
using namespace std;
void main()
{
for (int i=1, i<=5, i++)
{
for(int j=1, j<=i,j++)
{
printf("%c",64+j)
}
printf("\n")
}
}
xxxxxxxxxx
a=[]
def knapsack(pro,wt,c,n,ans):
global a
if n==0 or c==0:
a+=ans,
elif wt[n-1]>c:
knapsack(pro,wt,c,n-1,ans)
else:
knapsack(pro,wt,c-wt[n-1],n-1,ans+pro[n-1])
knapsack(pro,wt,c,n-1,ans)
n=int(input())
profit=list(map(int,input().split()))
weights=list(map(int,input().split()))
capacity=int(input())
knapsack(profit,weights,capacity,n,0)
a.sort(reverse=True)
print(a[1 if a[0]<=10 and a[0]%3 else 0])
xxxxxxxxxx
n=int(input())
for i in range (n):
a,b,k=(map(int,input().split()))
if a>=b:
print(k//b)
else:
print(k//a)
xxxxxxxxxx
import random
from collections import defaultdict
def main_roll():
dice_amount = int(input("Enter the number of dice: ")) # Total Number of Dice Being Rolled
sides_of_dice = int(input("Enter the number of sides: ")) # Total Number of Sides per Die
rolls_of_dice = int(input("Enter the number of rolls to simulate: ")) # Total Number of Times Each Die Rolled
result = roll(dice_amount, sides_of_dice, rolls_of_dice) # This stores the results
maxH = 0 # Used for formulating
for i in range(dice_amount, dice_amount * sides_of_dice + 1):
if result[i] / rolls_of_dice > maxH: maxH = result[i] / rolls_of_dice
for i in range(dice_amount, dice_amount * sides_of_dice + 1):
print('{:2d}{:10d}{:8.2%} {}'.format(i, result[i], result[i] / rolls_of_dice, '#' * int(result[i] / rolls_of_dice / maxH * 40)))
def roll(dice_amount, sides_of_dice, rolls):
d = defaultdict(int)
for _ in range(rolls):
d[sum(random.randint(1, sides_of_dice) for _ in range(dice_amount))] += 1
return d
main_roll()
xxxxxxxxxx
def djikstra(graph, initial):
visited_weight_map = {initial: 0}
nodes = set(graph.nodes)
# Haven't visited every node
while nodes:
next_node = min(
node for node in nodes if node in visited
)
if next_node is None:
# If we've gone through them all
break
nodes.remove(next_node)
current_weight = visited_weight_map[next_node]
for edge in graph.edges[next_node]:
# Go over every edge connected to the node
weight = current_weight + graph.distances[(next_node, edge)]
if edge not in visited_weight_map or weight < visited_weight_map[edge]:
visited_weight_map[edge] = weight
return visited
xxxxxxxxxx
# cook your dish here
tc = int(input())
for _ in range(tc):
c = 0
n = int(input())
n = pow(2,n)
for x in range(0,n):
a = x ^ (x+1)
b = (x+2) ^ (x+3)
if(a==b):
c+=1
print(c)
xxxxxxxxxx
if number == 2 : prime_con = True
if number>2 and number%2==0 : prime_con = False
stopper = math.floor(math.sqrt(number))
for j in range(3,100,2):
if number%j==0:
prime_con = False
break