Created
December 15, 2024 13:12
-
-
Save Suhaib3100/3248e240900609ede3c3655f141f65f2 to your computer and use it in GitHub Desktop.
pythonfinal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.StarCase | |
# Read the size of the staircase | |
n = int(input()) | |
# Loop to build the staircase | |
for i in range(n): | |
# Calculate the number of leading spaces and # symbols | |
spaces = ' ' * (n - i - 1) # Number of spaces | |
hashes = '#' * (i + 1) # Number of hashes | |
# Print the staircase row | |
print(spaces + hashes) | |
2.SHerLock | |
tc =int(input()) | |
for _ in range(tc): | |
n= int(input()) | |
arr = list(map(int,input().strip().split())) | |
result = "NO" | |
lsum = 0 | |
total = sum(arr) | |
for i in range(0,len(arr)): | |
rsum =total -arr[i] -lsum | |
if lsum == rsum: | |
result = "YES" | |
break | |
lsum += arr[i] | |
print(result) | |
3.Roattion | |
n, d = map(int, input().split()) | |
arr = list(map(int, input().split())) | |
# Calculate effective rotations | |
d = d % n # In case d >= n, we only need to rotate d % n times | |
# Perform the rotation using slicing | |
result = arr[d:] + arr[:d] | |
print(" ".join(map(str, result))) | |
4.Electronic Store | |
# Read input values | |
s, t = map(int, input().split()) # Start and end points of the house | |
a, b = map(int, input().split()) # Location of the apple and orange trees | |
m, n = map(int, input().split()) # Number of apples and oranges | |
# Read distances for apples and oranges | |
apples_distances = list(map(int, input().split())) | |
oranges_distances = list(map(int, input().split())) | |
# Initialize counters | |
count_apples = 0 | |
count_oranges = 0 | |
# Count apples that fall on the house | |
for d in apples_distances: | |
if s <= a + d <= t: # Check if the apple falls within the house range | |
count_apples += 1 | |
# Count oranges that fall on the house | |
for d in oranges_distances: | |
if s <= b + d <= t: # Check if the orange falls within the house range | |
count_oranges += 1 | |
# Print the results | |
print(count_apples) | |
print(count_oranges) | |
5.Digits | |
t = int(input()) | |
for _ in range(t): | |
n= input().strip() | |
num = int(n) | |
divCount =0 | |
for digit in n: | |
if digit != '0': | |
if num % int(digit) == 0: | |
divCount +=1 | |
print(divCount) | |
6.Cat and Mouse | |
a = int(input()) | |
for _ in range(a): | |
x,y,z = map(int,input().split()) | |
dista = abs(x-z) | |
distb = abs(y-z) | |
if dista < distb: | |
print("Cat A") | |
elif dista > distb: | |
print("Cat B") | |
else: | |
print("Mouse C") | |
7. Bird SIghtings | |
# Read the number of bird sightings (though we won't necessarily need to use this variable) | |
t = int(input()) | |
# Read the bird types from input as a list of integers | |
birdType = list(map(int, input().split())) | |
# Initialize a dictionary to count occurrences of each bird type | |
birdOccurance = {} | |
# Count the occurrences of each bird type | |
for i in birdType: | |
if i in birdOccurance: | |
birdOccurance[i] += 1 # Increment count if the bird type exists | |
else: | |
birdOccurance[i] = 1 # Initialize count if it's the first sighting | |
# Find the maximum frequency of sightings | |
frequency = max(birdOccurance.values()) | |
# Initialize a list to hold bird types that have the maximum frequency | |
mostFreq = [] | |
# Find all bird types that have the maximum frequency | |
for bird, count in birdOccurance.items(): | |
if count == frequency: | |
mostFreq.append(bird) # Add the bird type to the list | |
# Output the smallest bird type ID among those with maximum frequency | |
print(min(mostFreq)) | |
8.aplle and Orange | |
# Read input values | |
s, t = map(int, input().split()) # Start and end points of the house | |
a, b = map(int, input().split()) # Location of the apple and orange trees | |
m, n = map(int, input().split()) # Number of apples and oranges | |
# Read distances for apples and oranges | |
apples_distances = list(map(int, input().split())) | |
oranges_distances = list(map(int, input().split())) | |
# Initialize counters | |
count_apples = 0 | |
count_oranges = 0 | |
# Count apples that fall on the house | |
for d in apples_distances: | |
if s <= a + d <= t: # Check if the apple falls within the house range | |
count_apples += 1 | |
# Count oranges that fall on the house | |
for d in oranges_distances: | |
if s <= b + d <= t: # Check if the orange falls within the house range | |
count_oranges += 1 | |
# Print the results | |
print(count_apples) | |
print(count_oranges) | |
9.Ice Cream | |
t = int(input()) # Read the number of test cases | |
for _ in range(t): # Loop through each test case | |
m = int(input()) # Total money available | |
n = int(input()) # Number of flavors | |
cost = list(map(int, input().split())) # List of flavor prices | |
c = {} # Initialize a dictionary for storing prices and their indices | |
for i, price in enumerate(cost): # Loop over flavors with index | |
a = m - price # Calculate the required complementary price | |
if a in c: # Check if the complementary price exists in the dictionary | |
# If found, output its index plus one (1-based) and the current index | |
print(c[a] + 1, i + 1) | |
break # Exit after finding the first valid pair | |
c[price] = i # Store the price with its index |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment