-
Notifications
You must be signed in to change notification settings - Fork 0
/
2 - A. Anton and Danik.rb
89 lines (71 loc) · 2.25 KB
/
2 - A. Anton and Danik.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# A. Anton and Danik
# 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≤100000) — 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
# Note
# In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
# In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
# In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
###############
# Solution # Three Solutions for this problem
###############
def determine_winner(games_outcome)
anton_wins = games_outcome.count('A')
danik_wins = games_outcome.count('D')
if anton_wins > danik_wins
return "Anton"
elsif anton_wins < danik_wins
return "Danik"
else
return "Friendship"
end
end
# Read input
n = gets.chomp.to_i
games_outcome = gets.chomp
# Determine the winner
puts determine_winner(games_outcome)
################################################
n = gets.chomp.to_i
games_outcome = gets.chomp
nA = games_outcome.count('A')
nD = games_outcome.count('D')
if nA > nD
puts "Anton"
elsif nA < nD
puts "Danik"
else
puts "Friendship"
end
######################################
nA = 0
nD = 0
number_games = gets.chomp.to_i
strings = gets.chomp.upcase
strings.chars.each do |char|
if char == 'A'
nA += 1
elsif char == 'D'
nD += 1
end
end
if nA > nD
puts "Anton"
elsif nA < nD
puts "Danik"
else
puts "Friendship"
end