-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8530be4
commit 112afc2
Showing
8 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
shift = int(input()) | ||
message = str(input()) | ||
result = [] | ||
|
||
for index, char in enumerate(message): | ||
result.append(chr(ord(message[index]) - shift)) | ||
|
||
resultParsed = ''.join(char for char in result) | ||
print(resultParsed) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# matriz: N x M (N = altura, M = largura; N = y, M = x) | ||
height, width = [int(number) for number in input().split()] | ||
matrix = [] | ||
mainSum = 0 | ||
|
||
# Handle input | ||
for i in range(height): | ||
matrix.append(input().split()) | ||
for number in matrix[i]: | ||
number = int(number) | ||
|
||
# Auxiliary function | ||
def getRightLineSum(y, x): | ||
sum = 0 | ||
for i in range(x, width): | ||
sum += int(matrix[y][i]) | ||
return sum | ||
|
||
# Auxiliary function | ||
def getDownColumnSum(y, x): | ||
sum = 0 | ||
for i in range(y, height): | ||
sum += int(matrix[i][x]) | ||
return sum | ||
|
||
# Main recursive function to find turns potential to increase mainSum | ||
def findPotential(y, x): | ||
global mainSum | ||
|
||
turnRightPotential = 0 | ||
turnDownPotential = 0 | ||
|
||
turnRightCellsCount = 0 | ||
turnDownCellsCount = 0 | ||
|
||
if (y < height) and (x < width): | ||
|
||
mainSum += int(matrix[y][x]) | ||
# print(matrix[y][x]) | ||
|
||
# get turn right potential (x + 1) | ||
for i in range(y, height): | ||
turnRightPotential += getRightLineSum(i, x + 1) | ||
turnRightCellsCount += (width - x) | ||
|
||
# get turn down potential (y + 1) | ||
for i in range(y + 1, height): | ||
turnDownPotential += getRightLineSum(i, x) | ||
turnDownCellsCount += (width - x - 1) | ||
|
||
turnDownAvrgPotential = (turnDownPotential / turnDownCellsCount) if (turnDownCellsCount > 0) else (turnDownPotential) | ||
turnRightAvrgPotential = (turnRightPotential / turnRightCellsCount) if (turnRightCellsCount > 0) else (turnRightPotential) | ||
|
||
if turnRightAvrgPotential >= turnDownAvrgPotential: | ||
findPotential(y, x + 1) | ||
else: | ||
findPotential(y + 1, x) | ||
|
||
findPotential(0, 0) | ||
|
||
print(mainSum) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
roomCount = int(input()) | ||
peopleName = [] | ||
peopleFound = [] | ||
|
||
# handle input | ||
for i in range(roomCount): | ||
peopleName.append(str(input())) | ||
|
||
peopleName = sorted(peopleName) | ||
|
||
currentPerson = '' | ||
|
||
def findMiddleAndCompare(newList): | ||
middleIndex = int(len(newList) - 1) // 2 | ||
|
||
currentPerson = peopleName[middleIndex] | ||
if (currentPerson != 'Henrique'): | ||
if ord('H') > ord(list(currentPerson)[0]): | ||
findMiddleAndCompare(peopleName[middleIndex:(len(newList) - 1)]) | ||
else: | ||
findMiddleAndCompare(peopleName[0:middleIndex]) | ||
peopleFound.append(currentPerson) | ||
|
||
|
||
findMiddleAndCompare(peopleName) | ||
|
||
# print in reverse | ||
# can use reverse(peopleFound) too | ||
for i in range((len(peopleFound) - 1), -1, -1): | ||
print(peopleFound[i]) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
peopleCount = int(input()) | ||
|
||
sumDesks = 0 | ||
|
||
while peopleCount > 0: | ||
if sumDesks > 0: | ||
# when you add another desk, you earn 3 new places but lose one (3 -1 = 2) | ||
peopleCount -= 2 | ||
else: | ||
peopleCount -= 4 | ||
sumDesks += 1 | ||
|
||
print(sumDesks) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
pacientsCount = int(input()) | ||
|
||
badPacients = [] | ||
infectedPacients = [] | ||
|
||
# handle input | ||
for i in range(pacientsCount): | ||
inputLine = input().split() | ||
|
||
currentBadPacientName = inputLine[0] | ||
if currentBadPacientName not in badPacients: | ||
badPacients.append(currentBadPacientName) | ||
|
||
infectedCount = int(inputLine[1]) | ||
if (infectedCount > 0): | ||
# good for handling not-known inline inputs | ||
currentInfectedPacients = inputLine[2:len(inputLine)] | ||
for pacient in currentInfectedPacients: | ||
if pacient not in infectedPacients: | ||
infectedPacients.append(pacient) | ||
|
||
for pacient in badPacients: | ||
if pacient not in infectedPacients: | ||
print(pacient) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
listString = list(input().replace(" ", "")) | ||
# made convertion with list() typecasting | ||
# alternatively we could do: | ||
# listString = char for char in word | ||
# also removed all whitespace with replace() method | ||
|
||
ocurrences = {} | ||
# add ocurrences in dict | ||
for char in listString: | ||
if char not in ocurrences: | ||
ocurrences[char] = 1 | ||
else: | ||
ocurrences[char] += 1 | ||
|
||
|
||
removes = 0 | ||
# to iterate an object (dict) | ||
for i in ocurrences.keys(): | ||
if (ocurrences[i] % 2) != 0: | ||
removes += 1 | ||
|
||
# Check if it's possible to have just only one char in the middle of string | ||
if (len(listString) - removes + 1) % 2 != 0: | ||
removes -= 1 | ||
|
||
print(removes) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
idCount = int(input()) | ||
idList = [] | ||
|
||
# handle input | ||
for i in range(idCount): | ||
currentId = int(input()) | ||
|
||
if currentId not in idList: | ||
idList.append(currentId) | ||
|
||
print(len(idList)) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
numero_do_cartão = [int(charNumber) for charNumber in list(input())] | ||
|
||
def getNumberDigitsSum(number): | ||
sum = 0 | ||
while number != 0: | ||
sum = sum + (number % 10) | ||
number = number // 10 | ||
return sum | ||
|
||
alternate = False | ||
i = len(numero_do_cartão) - 1 | ||
|
||
while i >= 0: | ||
if alternate == True: | ||
new_number = numero_do_cartão[i] * 2 | ||
if new_number >= 10: | ||
new_number = getNumberDigitsSum(new_number) | ||
numero_do_cartão[i] = new_number | ||
alternate = not alternate | ||
i -= 1 | ||
|
||
sum = 0 | ||
for number in numero_do_cartão: | ||
sum += number | ||
|
||
if (sum % 10) == 0: | ||
print("SIM") | ||
else: | ||
print("NAO") | ||
|