diff --git a/blog/_posts/2024-10-15-algo-w1-1.md b/blog/_posts/2024-10-15-algo-w1-1.md new file mode 100644 index 0000000..187f561 --- /dev/null +++ b/blog/_posts/2024-10-15-algo-w1-1.md @@ -0,0 +1,82 @@ +--- +layout: post +thumbnail: https://github.com/sunbaklee/tech-blog/assets/105528907/61f561c9-a338-41e5-bcba-528b62a79766 +title: "알고리즘 스터디 1주차" +date: 2024-10-15 +tags: [Embedded] +author: 이준혁 +--- + +# 백준 3303번 킹, 퀸, 룩, 비숍, 나이트, 폰 + +## 개선 전 코드 +``` +a, b, c, d, e, f = map(int, input().split()) +aa = bb = cc = dd = ee = ff = 0 + +if a == 1: + aa = 0 +else: + aa = -(a - 1) + + +if b == 1: + bb = 0 +else: + bb = -(b - 1) + +if c == 2: + cc = 0 +else: + cc = -(c - 2) + +if d == 2: + dd = 0 +else: + dd = -(d - 2) + +if e == 2: + ee = 0 +else: + ee = -(e - 2) + +if f == 8: + ff = 0 +else: + ff = -(f - 8) + +print(aa, bb, cc, dd, ee, ff) +``` + + + + + + + + +## 개선 후 코드 +``` +a, b, c, d, e, f = map(int, input().split()) +a = -(a -1) +b = -(b -1) +c = -(c - 2) +d = -(d - 2) +e = -(e - 2) +f = -(f - 8) +print(a, b, c, d, e, f) +``` + + +# 백준 2446 별찍기 + +``` +n = int(input()) +for i in range(n): + for i in range(n): + print(' ' * i, end = '') + print('*' * (2 * (n - i) - 1)) + for i in range(n-1): + print(' ' , end = '') + print('*' * (2*i+1)) +``` \ No newline at end of file