Nonamed Develog
[TIL] AI 웹 개발 7기 사전 캠프 5-5 본문
일일 알고리즘/SQL 코드카타
알고리즘33) 정수 left와 right가 매개변수로 주어집니다. left부터 right까지의 모든 수들 중에서, 약수의 개수가 짝수인 수는 더하고, 약수의 개수가 홀수인 수는 뺀 수를 return 하도록 solution 함수를 완성해주세요.
제한사항
1 ≤ left ≤ right ≤ 1,000
def solution(left, right):
answer = 0
for i in range(left, right+1):
count = 0
for j in range(1, i+1):
if i % j == 0:
count += 1
if count % 2 == 0:
answer += i
else:
answer -= i
return answer
아이디어는 좋았지만 count = 0의 위치로 인해 시간을 많이 잡아 먹었던 문제였다. 반복문과 조건문을 이용할 때 count = 0이라는 요소도 같이 적어주는데 이 것의 위치가 중요하다는 사실을 알게 되었다.
SQL33) 상품 별 오프라인 매출 구하기
SELECT product_code,
SUM(p.price*o.sales_amount) sales
FROM product p INNER JOIN offline_sale o ON p.product_id = o.product_id
GROUP BY product_code
ORDER BY SUM(p.price * o.sales_amount) DESC,
product_code
문제를 읽을 때 합계를 보지 못하여 SUM() 함수를 넣지 못했다. 문제를 먼저 이해한 후 문제 풀이를 해보자.
멜로디쉐어
<!Doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap demo</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
<style>
@import url("https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css");
.background-banner {
background-image: linear-gradient(45deg,
rgb(51 43 43 / 75%),
rgb(20 19 20 / 61%)), url("https://s3.ap-northeast-2.amazonaws.com/materials.spartacodingclub.kr/webjong/images/music_festival.jpg");
max-height: 100%;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
}
</style>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
</head>
<body data-bs-theme="dark">
<div class="background-banner">
<nav class="navbar border-bottom border-body d-flex justify-content-space-between" data-bs-theme="dark">
<div class="ms-3">
<img src="https://s3.ap-northeast-2.amazonaws.com/materials.spartacodingclub.kr/webjong/images/sparta-logo.svg"
alt="">
</div>
<nav class="navbar navbar-expand-lg">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link text-white" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="#">Music</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="#">Album</a>
</li>
<li class="nav-item">
<a class="nav-link text-white">Moive</a>
</li>
</ul>
</div>
</div>
</nav>
</nav>
<div class="px-4 py-5 my-5 text-center">
<h1 class="display-6 fw-bold text-body-emphasis">멜로디쉐어</h1>
<div class="col-lg-6 mx-auto">
<p class="lead mb-4">
<br>
노래를 들으면 생각나는 누군가가 있으신가요?
<br>
<br>
당신의 감성이 담긴 인생곡 플레이리스트
<br>
멜로디쉐어에서 소중한 사람과 함께하세요.
</p>
<div class="d-grid gap-2 d-sm-flex justify-content-sm-center">
<!-- Button trigger modal -->
<button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#exampleModal">
음악 추가
</button>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">최애 음악</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form>
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">유저</label>
<input type="text" class="form-control" id="exampleInputEmail1"
aria-describedby="emailHelp">
<div id="emailHelp" class="form-text">사용자(추천인)의 이름을 넣어주세요.</div>
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">노래 제목</label>
<input type="text" class="form-control" id="exampleInputPassword1">
<div id="emailHelp" class="form-text">좋아하는 노래 제목을 넣어주세요.</div>
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">가수</label>
<input type="text" class="form-control" id="exampleInputPassword1">
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">앨범 커버URL</label>
<input type="text" class="form-control" id="exampleInputPassword1">
</div>
<button type="submit" class="btn btn-danger">Submit</button>
</form>
</div>
</div>
</div>
</div>
<div class="row row-cols-1 row-cols-md-4 g-4 mx-auto w-75 pb-5">
<div class="col">
<div class="card">
<img src="https://s3.ap-northeast-2.amazonaws.com/materials.spartacodingclub.kr/webjong/ive.jpg"
class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">러브 다이브</h5>
<p class="card-text">IVE(아이브)</p>
<p class="card-text">추천 by 최지웅</p>
</div>
</div>
</div>
<div class="col">
<div class="card">
<img src="https://s3.ap-northeast-2.amazonaws.com/materials.spartacodingclub.kr/webjong/ive.jpg"
class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">러브 다이브</h5>
<p class="card-text">IVE(아이브)</p>
<p class="card-text">추천 by 최지웅</p>
</div>
</div>
</div>
<div class="col">
<div class="card">
<img src="https://s3.ap-northeast-2.amazonaws.com/materials.spartacodingclub.kr/webjong/ive.jpg"
class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">러브 다이브</h5>
<p class="card-text">IVE(아이브)</p>
<p class="card-text">추천 by 최지웅</p>
</div>
</div>
</div>
<div class="col">
<div class="card">
<img src="https://s3.ap-northeast-2.amazonaws.com/materials.spartacodingclub.kr/webjong/ive.jpg"
class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">러브 다이브</h5>
<p class="card-text">IVE(아이브)</p>
<p class="card-text">추천 by 최지웅</p>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<footer>
<div class="d-flex flex-column flex-sm-row justify-content-between py-4 my-4 border-top">
<p>© 2024 Company, Inc. All rights reserved.</p>
<ul class="list-unstyled d-flex">
<li class="ms-3"><a class="link-body-emphasis" href="https://www.youtube.com/@SpartaCodingClub"><i
class="bi bi-youtube"></i></a></li>
<li class="ms-3"><a class="link-body-emphasis" href="https://www.instagram.com/spartacodingclub/"><i
class="bi bi-instagram"></i></a></li>
<li class="ms-3"><a class="link-body-emphasis" href="https://spartacodingclub.kr/blog"><i
class="bi bi-postcard"></i></a></li>
</ul>
</div>
</footer>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"
integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz"
crossorigin="anonymous"></script>
</body>
</html>
'WHAT I LEARN > TIL' 카테고리의 다른 글
[TIL][240625] 미니 프로젝트, Fetch, jQuery, Flask, venv (0) | 2024.06.25 |
---|---|
[TIL][240624] 서버-클라이언트, 파이썬 웹 스크래핑 (0) | 2024.06.24 |
[TIL] AI 웹 개발 7기 사전 캠프 5-4 (0) | 2024.06.20 |
[TIL] AI 웹 개발 7기 사전 캠프 5-3 (0) | 2024.06.19 |
[TIL] AI 웹 개발 7기 사전 캠프 5-2 (0) | 2024.06.18 |