[PYTHON] Today's AtCoder ~ The Road to the Brown Coder ~

As an AtCoder diary, I will describe the problem I solved today. Basically, [here](https://qiita.com/drken/items/fd4e5e3630d0f5859067#5-%E9%81%8E%E5%8E%BB%E5%95%8F%E7%B2%BE%E9% It is in the form of solving the problem described in 81% B8-10-% E5% 95% 8F) * 1. When doing competitive programming, I use Paiza.io, which is easier to execute than the local environment.

It's almost a diary, so don't worry about habits.

The problem solved today

  1. A - RGB Cards
  2. A - Infinite Coins
  3. A - Round Up the Mean
  4. A - Something on It
  5. A - Already 2018
  6. B - i18n
  7. B - Two Anagrams
  8. B - Break Number
  9. B - Maximum Difference

Each code

First question

r,g,b=map(str,input().split())
 
res=int(r+g+b)
if res%4==0:
    print("YES")
 
else:
    print("NO")

The condition was that it was a multiple of 4, so if it was too much, it would be true, right? I thought.

Second question

Correct answer

N=int(input())
A=int(input())
 
s=N%500
 
if s<=A:
    print("Yes")
    exit()
 
print("No")

Incorrect answer

N=int(input())
A=int(input())
 
s=N//500
 
for i in range(A):
    if i+s*500==N:
        print("Yes")
        exit()
 
print("No")

At first, why not give the total amount and ask for it? I implemented it thinking that. WA came out at the last test, so I reassembled it. The second time, it would be nice if we could make about 500 for a total of 1 yen, right? I created it with the image.

Third question

a,b=map(int,input().split())
 
s=a+b
ss=s//2
s2=s%2
 
if s2==1:
    print(ss+1)
    exit()
print(ss)

import mathThe method of using a function would be simpler, but I wanted to improve my ability to write algorithms, so I cut it down and then added +1. (Writing that is not smart at all)

Fourth question

the first

S=input()
 
cou=int(S.count("o"))*100
 
print(700+cou)

Second time

S=input()
 
res=700
for i in S:
    if i=="o":
        res+=100
 
print(res)

third time

res=700
for i in input():
    if i=="o":
        res+=100
 
print(res)

I thought it would be easy to find it if I looked it up using count and calculated it, so I used count. The second time I wrote using if and for in case count cannot be used. I wrote the third time because I thought I could shorten the code a little.

Fifth question

S=input()
S="2018"+S[4:]
print(S)
print("2018"+input()[4:])

I only had to change the first to 2018, so I changed the first few letters to 2018 and output. If I wanted to shorten it, I could output it in one line.

Sixth question

s=input()
 
fir=s[0]
las=s[-1]
 
s=s[1:]
s=s[:-1]
 
print(fir+str(len(s))+las)

The problem was that it would be good to count the characters in between and combine the first and last characters for output. Substitute the first and last characters Erase the first and last characters Count the characters inside I wrote it as a character string and output it.

Seventh question

s=input()
t=input()
 
s=sorted(s)
s="".join(s)
t=sorted(t,reverse=True)
t="".join(t)
# print(s,t)
if s<t:
    print("Yes")
    
else:
    print("No")

The problem that I was able to understand how to use sorted The code is quite wasteful.

Eighth question

N=int(input())
n=1
while True:
    if n>N:
        print(int(n/2))
        break
    
    n=n*2

The number that can be divided by 2 has the largest value of 2 to the nth power, so I doubled it.

Ninth question

N=int(input())
lis=list(map(int,input().split()))
 
lis.sort(reverse=True)
 
print(lis[0]-lis[-1])

I thought it would be good to sort and draw the first and last characters, so I sorted and output. If it's the original article, I'll call it with a for statement! It was written about something, but what should I do?

References

Recommended Posts

Today's AtCoder ~ The Road to the Brown Coder ~
The road to Pythonista
The road to Djangoist
The road to download Matplotlib
Road to the Wizard: 4th Step
[Python] Now a brown coder ~ [AtCoder]
Road to the Wizard: 7th Step
The road to compiling to Python 3 with Thrift
Brown coder tried to solve Panasonic Contest 2020A ~ C
Road to LPIC-1 acquisition
I tried to display the time and today's weather w
Road to the Wizard: Step 8 (Interpret How to become a Hacker)