Break through in 2 minutes. Just write. Continuing from the previous time, duplicate judgment with set.
ABC = list(map(int, input().split()))
if len(set(ABC)) == 2:
print('Yes')
else:
print('No')
Break through in two and a half minutes. Just write.
N = int(input())
A = list(map(int, input().split()))
for a in A:
if a % 2 == 1:
continue
if a % 3 == 0 or a % 5 == 0:
continue
print('DENIED')
exit()
print('APPROVED')
It broke through in 8 and a half minutes. It took me a while to write ... (sweat). When I heard that the C # messenger was in a state of destruction and looked at the code of the AC person, all of them sorted their own string array I was using, so Mono wondered if the string comparison was crazy.
N = int(input())
d = {}
for _ in range(N):
S = input()
if S in d:
d[S] += 1
else:
d[S] = 1
m = max(d.values())
for s in sorted(k for k in d if d[k] == m):
print(s)
Addendum: Everyone who runs in C # sorts using their own comparer, but it works with the standard StringComparer.Ordinal (which is essentially a call to the strcmp function in the C runtime).
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var N = int.Parse(Console.ReadLine());
var d = new Dictionary<string, int>();
for (var i = 0; i < N; i++)
{
var S = Console.ReadLine();
if (!d.ContainsKey(S)) d[S] = 0;
d[S]++;
}
var m = d.Values.Max();
var l = new List<string>();
foreach (var kv in d)
{
if (kv.Value != m) continue;
l.Add(kv.Key);
}
l.Sort(StringComparer.Ordinal);
Console.WriteLine(string.Join("\n", l));
}
}
}
Lost. I went to E because there are many people who understand E. I thought it was a bummer.
Lost. Although Input Example 1 and Input Example 2 broke through, Input Example 3 became 249 instead of 243, and I was thinking of a pattern that would not work with my logic, but I could not think of it.
Addendum 1: Gununu.
N = input()
N = '0' + N
result = 0
carry = 0
for i in range(len(N) - 1, 0, -1):
c = int(N[i]) + carry
n = int(N[i - 1])
if c < 5 or (c == 5 and n < 5):
result += c
carry = 0
else:
result += 10 - c
carry = 1
result += carry
print(result)
Addendum 2: Instead of thinking of a pattern that doesn't work for Clever, I should have tried both paying with that digit bill and paying with the upper digit bill in all digits and taking the smaller one ... Then I didn't need intelligence ...
N = input()
a = 0 #Pay with that digit of banknotes
b = 0 #Pay with the upper digit banknotes
t = int(N[-1])
a, b = a + t, a + (10 - t)
for i in range(len(N) - 2, -1, -1):
t = int(N[i])
a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))
print(min(a, b + 1))
Recommended Posts