Skip to content

Commit

Permalink
백준 9095번 1, 2, 3 더하기
Browse files Browse the repository at this point in the history
  • Loading branch information
skysign committed Aug 11, 2024
1 parent 0b3efe4 commit 190f986
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 백준 9095번 1, 2, 3 더하기/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import sys
from typing import List


def solve():
cnt = int(sys.stdin.readline().strip())
dt: List[int] = [0 for _ in range(11 + 1)]
ins: List[int] = []

for _ in range(cnt):
n = int(sys.stdin.readline().strip())
ins.append(n)

mx = max(ins)
dt[1] = 1
dt[2] = 2
dt[3] = 4 # 1+1+1+1 1+2 2+1 3

for i in range(4, mx + 1):
dt[i] = dt[i - 1] + dt[i - 2] + dt[i - 3]

for n in ins:
print(dt[n])


if __name__ == '__main__':
solve()
4 changes: 4 additions & 0 deletions 백준 9095번 1, 2, 3 더하기/test1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3
4
7
10
3 changes: 3 additions & 0 deletions 백준 9095번 1, 2, 3 더하기/test1_answer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
7
44
274
32 changes: 32 additions & 0 deletions 백준 9095번 1, 2, 3 더하기/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import sys
from pathlib import Path
from unittest import TestCase
from main import solve


class Test(TestCase):
def my_solve(self, testcase_input):
sys.stdin = open(testcase_input, 'r')
stdout = sys.stdout
sys.stdout = open('stdout.txt', 'w')
solve()
sys.stdout.close()
sys.stdout = stdout

def test_solve(self, testcase_number: str):
self.my_solve('test' + testcase_number + '.txt')
self.assertEqual(
Path('test' + testcase_number + '_answer.txt').read_text().strip(),
Path('stdout.txt').read_text().strip())

def test1_solve(self):
self.test_solve('1')

def test2_solve(self):
self.test_solve('2')

def test3_solve(self):
self.test_solve('3')

def test4_solve(self):
self.test_solve('4')

0 comments on commit 190f986

Please sign in to comment.