In: Computer Science
Python language!!!!!
№1
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if he translated the word correctly.
Input
The first line contains word s, the second line contains word t. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output
If the word t is a word s, written reversely, print YES, otherwise print NO.
Examples
input
code
edoc
output
YES
№2
Anton likes to play chess, and so does his friend Danik.
Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of games played.
The second line contains a string s, consisting of n uppercase English letters 'A' and 'D' — the outcome of each of the games. The i-th character of the string is equal to 'A' if the Anton won the i-th game and 'D' if Danik won the i-th game.
Output
If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes).
Examples
input
6
ADAAAA
output
Anton
№3
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed.
Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx".
You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by 11. For example, if you delete the character in the position 22 from the string "exxxii", then the resulting string is "exxii".
Input
The first line contains integer nn (3≤n≤100)(3≤n≤100) — the length of the file name.
The second line contains a string of length nn consisting of lowercase Latin letters only — the file name.
Output
Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0.
Examples
input
6
xxxiii
output
1
======== NO1 =========
def translation(string1,string2):
if string1 == string2[::-1]: # reverse the second string and check same are not
return 1
else:
return 0
if __name__ == "__main__":
Berland = input()
Birland = input()
if len(Berland) < 1 or len(Birland) < 1 or len(Birland) > 100 or len(Berland) > 100: # if string is not valid
print("Invalid Input")
else:
if translation(Berland,Birland):
print("YES")
else:
print("NO")
======= NO2 ========
def who_won_more_games(string1):
if string1.count('A') > string1.count('D'): # Count the number of A and D and return 1 if greater else 2
return 1
elif string1.count('A') < string1.count('D'):
return 2
else:
return 0
if __name__ == "__main__":
number_of_games = int(input())
s = input()
if len(s) < 1 or len(s) > 1000000:
print("Invalid Input")
else:
s.upper() # Convert to upper letter
if who_won_more_games(s) == 1: # If return value is 1 print Anton or if it is 2 print Danik else Friendship
print("Anton")
elif who_won_more_games(s) == 2:
print("Danik")
else:
print("Friendship")
======= NO3 ======
if __name__ == "__main__":
number_of_games = int(input())
s = input()
if len(s) < 1 or len(s) > 1000000:
print("Invalid Input")
else:
result,s1 = 0,0
for i in range(len(s)):
if s[i] == 'x':
s1 += 1
if s1 > 2: # Check if consecutive 'x' are greater than 2 then add 1 to result
result += 1
else:
s1 = 0
print(result)