I was interested in AtCoder and tried typing the code directly in the browser. So, of course, I wanted to move it locally and check it before uploading it. Then, half a year later, I would like to say to myself, "What, I didn't know this?", So I want to keep the sauce. (Well, locally.) Then, by the way, let's have a sample problem as a part of the code, test it, and wait until it's OK. So I added a mode of operation and created a framework (?) Tick function that is easy to evaluate.
I heard that there is a puzzle that seems to be interesting ... No, I knew the existence itself, but the content was too enthusiastic, and I thought it was a little bit like that, so I gave it up. However, when I heard that I could participate in AtCoder on Scratch, I said, "Well, isn't it a purveyor to experts?" .. ..
Then, I thought I could participate for the first time. Wrong. I thought I'd start.
Make one .py file that can be started independently Normal operation (for submission) with no arguments Enter 1, 2 etc. as arguments and output the test pattern execution result and OK / NG presented in the question sentence
■A - Welcome to AtCoder https://atcoder.jp/contests/practice/tasks/practice_1
practice_1.py
# answer
def practice_1(lines):
a = int(lines[0])
b, c = map(int, lines[1].split(' '))
s = lines[2]
return [str(a+b+c) + ' ' + s]
# Get arguments
def get_input_lines(lines_count):
lines = list()
for _ in range(lines_count):
lines.append(input())
return lines
# test data
def get_testdata(pattern):
if pattern == 1:
lines_input = ['1', '2 3', 'test']
lines_export = ['6 test']
elif pattern == 2:
lines_input = ['72', '128 256', 'myonmyon']
lines_export = ['456 myonmyon']
return lines_input, lines_export
# Operation mode determination
def get_mode():
import sys
args = sys.argv
if len(args) == 1:
mode = 0
else:
mode = int(args[1])
return mode
# Main processing
def main():
mode = get_mode()
if mode == 0:
lines_input = get_input_lines(3)
else:
lines_input, lines_export = get_testdata(mode)
lines_result = practice_1(lines_input)
for line_result in lines_result:
print(line_result)
if mode > 0:
print(f'lines_input=[{lines_input}]')
print(f'lines_export=[{lines_export}]')
print(f'lines_result=[{lines_result}]')
if lines_result == lines_export:
print('OK')
else:
print('NG')
# Start process
if __name__ == '__main__':
main()
(Output result)
(base) ...>python practice_1.py 1
6 test
lines_input=[['1', '2 3', 'test']]
lines_export=[['6 test']]
lines_result=[['6 test']]
OK
(base) ...>python practice_1.py 2
456 myonmyon
lines_input=[['72', '128 256', 'myonmyon']]
lines_export=[['456 myonmyon']]
lines_result=[['456 myonmyon']]
OK
(base) ...>python practice_1.py
3
5 7
abc
15 abc
https://atcoder.jp/contests/abc173/tasks/abc173_a
abc173_a.py
# answer
def abc173_a(lines):
N = int(lines[0])
amari = N % 1000
if amari == 0:
answer = 0
else:
answer = 1000 - amari
return [answer]
# Get arguments
def get_input_lines(lines_count):
lines = list()
for _ in range(lines_count):
lines.append(input())
return lines
# test data
def get_testdata(pattern):
if pattern == 1:
lines_input = ['1900']
lines_export = [100]
elif pattern == 2:
lines_input = ['3000']
lines_export = [0]
return lines_input, lines_export
# Operation mode determination
def get_mode():
import sys
args = sys.argv
if len(args) == 1:
mode = 0
else:
mode = int(args[1])
return mode
# Main processing
def main():
mode = get_mode()
if mode == 0:
lines_input = get_input_lines(1)
else:
lines_input, lines_export = get_testdata(mode)
lines_result = abc173_a(lines_input)
for line_result in lines_result:
print(line_result)
if mode > 0:
print(f'lines_input=[{lines_input}]')
print(f'lines_export=[{lines_export}]')
print(f'lines_result=[{lines_result}]')
if lines_result == lines_export:
print('OK')
else:
print('NG')
# Start process
if __name__ == '__main__':
main()
(Output result)
(base) >python abc173_a.py 1
100
lines_input=[['1900']]
lines_export=[[100]]
lines_result=[[100]]
OK
(base) >python abc173_a.py 2
0
lines_input=[['3000']]
lines_export=[[0]]
lines_result=[[0]]
OK
(base) >python abc173_a.py
2380
620
(
https://atcoder.jp/contests/abc173/tasks/abc173_b
abc173_b.py
# answer
def abc173_b(lines):
labels = ['AC', 'WA', 'TLE', 'RE']
ns = [0, 0, 0, 0]
for line in range(1, len(lines)):
for i, label in enumerate(labels):
if label == lines[line]:
ns[i] += 1
answers = list()
for i, label in enumerate(labels):
answers.append(label + ' x ' + str(ns[i]))
return answers
# Get arguments
def get_input_lines_1stline_as_n_lines():
lines = list()
lines.append(input())
for _ in range(int(lines[0])):
lines.append(input())
return lines
# test data
def get_testdata(pattern):
if pattern == 1:
lines_input = ['6', 'AC', 'TLE', 'AC', 'AC', 'WA', 'TLE']
lines_export = ['AC x 3', 'WA x 1', 'TLE x 2', 'RE x 0']
elif pattern == 2:
lines_input = ['10', 'AC', 'AC', 'AC', 'AC', 'AC', 'AC', 'AC', 'AC', 'AC', 'AC']
lines_export = ['AC x 10', 'WA x 0', 'TLE x 0', 'RE x 0']
return lines_input, lines_export
# Operation mode determination
def get_mode():
import sys
args = sys.argv
if len(args) == 1:
mode = 0
else:
mode = int(args[1])
return mode
# Main processing
def main():
mode = get_mode()
if mode == 0:
lines_input = get_input_lines_1stline_as_n_lines()
else:
lines_input, lines_export = get_testdata(mode)
lines_result = abc173_b(lines_input)
for line_result in lines_result:
print(line_result)
if mode > 0:
print(f'lines_input=[{lines_input}]')
print(f'lines_export=[{lines_export}]')
print(f'lines_result=[{lines_result}]')
if lines_result == lines_export:
print('OK')
else:
print('NG')
# Start process
if __name__ == '__main__':
main()
(Output result)
(base) >python abc173_b.py 1
AC x 3
WA x 1
TLE x 2
RE x 0
lines_input=[['6', 'AC', 'TLE', 'AC', 'AC', 'WA', 'TLE']]
lines_export=[['AC x 3', 'WA x 1', 'TLE x 2', 'RE x 0']]
lines_result=[['AC x 3', 'WA x 1', 'TLE x 2', 'RE x 0']]
OK
(base) >python abc173_b.py 2
AC x 10
WA x 0
TLE x 0
RE x 0
lines_input=[['10', 'AC', 'AC', 'AC', 'AC', 'AC', 'AC', 'AC', 'AC', 'AC', 'AC']]
lines_export=[['AC x 10', 'WA x 0', 'TLE x 0', 'RE x 0']]
lines_result=[['AC x 10', 'WA x 0', 'TLE x 0', 'RE x 0']]
OK
(base) >python abc173_b.py
5
AC
AC
WA
TLE
TLE
AC x 2
WA x 1
TLE x 2
RE x 0
Well, for the time being, this is it. With the attitude of trying to get started rather than making it Best. Maybe if I keep going, I'll make a lot of changes.
For the time being, Welcome has become AC as it is, so let's put this up from today. ABC173 read from A to F, but D didn't come out very well. F was confusing and didn't feel like reading. When I wrote the code for E, it became sober and annoying that I interrupted it. Well, I wonder if it's okay to get used to it after D. C was also a lot of trouble.
I'm wondering if my style will become a Better through logical assembly and thought organization, so I think I'd like to tackle the issues and take a little flow of watching the explanation video ... If you continue. .. ..
Recommended Posts