-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from TakhyunKim/feature/algorithm
์๊ณ ๋ฆฌ์ฆ ๋ค๋น๊ฒ์ด์ ํญ, ํ์ด์ง ์ถ๊ฐ ๋ฐ ํฌ์คํ ์ถ๊ฐ
- Loading branch information
Showing
9 changed files
with
390 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
--- | ||
title: "๋ฐฑ์ค 10828-stack" | ||
date: "2024-04-09" | ||
tag: "stack" | ||
--- | ||
|
||
## ๋ฌธ์ | ||
|
||
> <a href="https://www.acmicpc.net/problem/10828" target="_blank">๋ฌธ์ ๋งํฌ</a> | ||
์ ์๋ฅผ ์ ์ฅํ๋ ์คํ์ ๊ตฌํํ ๋ค์, ์ ๋ ฅ์ผ๋ก ์ฃผ์ด์ง๋ ๋ช ๋ น์ ์ฒ๋ฆฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. | ||
|
||
๋ช ๋ น์ ์ด ๋ค์ฏ ๊ฐ์ง์ด๋ค. | ||
|
||
push X: ์ ์ X๋ฅผ ์คํ์ ๋ฃ๋ ์ฐ์ฐ์ด๋ค.<br /> | ||
pop: ์คํ์์ ๊ฐ์ฅ ์์ ์๋ ์ ์๋ฅผ ๋นผ๊ณ , ๊ทธ ์๋ฅผ ์ถ๋ ฅํ๋ค. ๋ง์ฝ ์คํ์ ๋ค์ด์๋ ์ ์๊ฐ ์๋ ๊ฒฝ์ฐ์๋ -1์ ์ถ๋ ฅํ๋ค.<br /> | ||
size: ์คํ์ ๋ค์ด์๋ ์ ์์ ๊ฐ์๋ฅผ ์ถ๋ ฅํ๋ค. <br /> | ||
empty: ์คํ์ด ๋น์ด์์ผ๋ฉด 1, ์๋๋ฉด 0์ ์ถ๋ ฅํ๋ค.<br /> | ||
top: ์คํ์ ๊ฐ์ฅ ์์ ์๋ ์ ์๋ฅผ ์ถ๋ ฅํ๋ค. ๋ง์ฝ ์คํ์ ๋ค์ด์๋ ์ ์๊ฐ ์๋ ๊ฒฝ์ฐ์๋ -1์ ์ถ๋ ฅํ๋ค.<br /> | ||
|
||
## ํ์ด | ||
|
||
```ts | ||
const answers = []; | ||
const [n, ...commands] = input; | ||
|
||
function solution(n, commands) { | ||
const stack = []; | ||
|
||
const stackCommand = { | ||
push: (value) => { | ||
stack.push(value); | ||
}, | ||
pop: () => { | ||
return stack.length === 0 ? -1 : stack.pop(); | ||
}, | ||
size: () => { | ||
return stack.length; | ||
}, | ||
empty: () => { | ||
return stack.length === 0 ? 1 : 0; | ||
}, | ||
top: () => { | ||
return stack.length === 0 ? -1 : stack.at(-1); | ||
}, | ||
}; | ||
|
||
for (i = 0; i < n; i++) { | ||
const [command, value] = commands[i].split(" "); | ||
if (command === "push") { | ||
stackCommand.push(parseInt(value)); | ||
} else { | ||
answers.push(stackCommand[command]()); | ||
} | ||
} | ||
|
||
console.log(answers.join("\n")); | ||
} | ||
``` | ||
|
||
## ์ค๋ช | ||
|
||
Stack ๊ตฌํ์ javascript Array method ๋ฅผ ํ์ฉํ์ต๋๋ค.<br /> | ||
๊ตฌํํด์ผํ push, pop, size, empty, top ์ ๊ตฌํ ํ,<br /> | ||
for ๋ฌธ์ ํตํด ํ์ํ ๋ด์ฉ์ ์ํ, split ์ ํตํด ๋ฌธ์์ด ์๋ฅด๊ธฐ๋ฅผ ํตํด ๊ฐ๊ณผ stack command ๋ฅผ ๋ถ๋ฆฌํ์ต๋๋ค.<br /> | ||
push ๋ฅผ ์ ์ธํ ๋๋จธ์ง method ๋ ๊ฐ์ ์ถ๋ ฅํด์ผํ๋ฏ๋ก ๋ฐํ๊ฐ์ ๋ณ๋๋ก ์ ์ฅํ๊ณ ,<br /> | ||
๋ง์ง๋ง์ ์์ ์ถ๋ ฅ์ ๋ง๋๋ก `join("\n")` ์ ํตํด ์ค๋ฐ๊ฟ ํ ์ถ๋ ฅํ๋ ๋ฐฉ์์ ์ ์ฉํ์ต๋๋ค.<br /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
title: "๋ฐฑ์ค 9093-๋จ์ด ๋ค์ง๊ธฐ" | ||
date: "2024-04-10" | ||
tag: "stack,๋ฌธ์์ด ๋ค์ง๊ธฐ" | ||
--- | ||
|
||
## ๋ฌธ์ | ||
|
||
> <a href="https://www.acmicpc.net/problem/9093" target="_blank">๋ฌธ์ ๋งํฌ</a> | ||
๋ฌธ์ฅ์ด ์ฃผ์ด์ก์ ๋, ๋จ์ด๋ฅผ ๋ชจ๋ ๋ค์ง์ด์ ์ถ๋ ฅํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค. ๋จ, ๋จ์ด์ ์์๋ ๋ฐ๊ฟ ์ ์๋ค. ๋จ์ด๋ ์์ด ์ํ๋ฒณ์ผ๋ก๋ง ์ด๋ฃจ์ด์ ธ ์๋ค. | ||
|
||
์ฒซ์งธ ์ค์ ํ ์คํธ ์ผ์ด์ค์ ๊ฐ์ T๊ฐ ์ฃผ์ด์ง๋ค. ๊ฐ ํ ์คํธ ์ผ์ด์ค๋ ํ ์ค๋ก ์ด๋ฃจ์ด์ ธ ์์ผ๋ฉฐ, ๋ฌธ์ฅ์ด ํ๋ ์ฃผ์ด์ง๋ค. ๋จ์ด์ ๊ธธ์ด๋ ์ต๋ 20, ๋ฌธ์ฅ์ ๊ธธ์ด๋ ์ต๋ 1000์ด๋ค. ๋จ์ด์ ๋จ์ด ์ฌ์ด์๋ ๊ณต๋ฐฑ์ด ํ๋ ์๋ค. | ||
|
||
## ํฐ์ด | ||
|
||
```ts | ||
function solution(targetList) { | ||
const answers = []; | ||
|
||
for (i = 0; i < targetList.length; i++) { | ||
const reversedList = []; | ||
const target = targetList[i].split(" "); | ||
|
||
for (j = 0; j < target.length; j++) { | ||
const reversedTarget = target[j].split("").reverse().join(""); | ||
reversedList.push(reversedTarget); | ||
} | ||
|
||
answers.push(reversedList.join(" ")); | ||
} | ||
|
||
console.log(answers.join("\n")); | ||
} | ||
|
||
solution(targetInput); | ||
``` | ||
|
||
## ์ค๋ช | ||
|
||
๋ฌธ์ ์ ํ์ ์คํ์ด๋, ๋ฌธ์์ด ๋ค์ง๊ธฐ๋ split(String method), reverse(Array method) ์ ํตํด ์ฝ๊ฒ ํ ์ ์์ ๊ฒ ๊ฐ์ ํด๋น method ๋ฅผ ํ์ฉํ์ฌ ๋ฌธ์ ๋ฅผ ํ์์ต๋๋ค. ์ ๊ทผ ๋ฐฉ์์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. | ||
|
||
> 1. for ๋ฌธ์ ํตํด ๋ฌธ์์ด ๋ค์ง๊ธฐ ๋์ ๋ฐฐ์ด์ ์ํํฉ๋๋ค. | ||
> 2. ๋์ ๋ฌธ์์ด์ ๋ฌธ์ฅ ๊ตฌ์กฐ๋ฅผ ๊ฐ์ง ์ ์์ผ๋ฏ๋ก, ๋ด๋ถ์ ๋ค์ง๊ธฐํ ๋ฌธ์์ด์ ๋ณด๊ดํ ๋ฐฐ์ด์ ์ ์ธํฉ๋๋ค.<br />(ex: 'I am happy today') | ||
> 3. ๋์ ๋ฌธ์์ด์ ๋์ด์ฐ๊ธฐ ๊ธฐ์ค์ผ๋ก split ํ์ฌ ๋ฐฐ์ดํํฉ๋๋ค. | ||
> 4. ๋ฐฐ์ดํํ ๋ฌธ์์ด์ for ๋ฌธ์ผ๋ก ์ํํฉ๋๋ค. | ||
> 5. ๋์ด์ฐ๊ธฐ๋ก ๋ถ๋ฆฌ๋ ๋ฌธ์์ด์ reverse ํฉ๋๋ค. ๋ฌธ์์ด์ด๋ฏ๋ก split("")์ผ๋ก ๋จ์ด ๋ณ๋ก ๋ถ๋ฆฌํ ํ reverse ํ์ผ๋ฉฐ, ์ด ํ join("")์ ํตํด ๋ค์ง์ ๋ฌธ์์ด์ ํฉ์นฉ๋๋ค. | ||
> 6. ๋ค์ง๊ธฐํ ๋ฌธ์์ด์ ๋ฐฐ์ด์ ๋ณด๊ดํฉ๋๋ค. | ||
> 7. ์ฒ์ for ๋ฌธ์ด ๋๋ ์ง์ ์์ ๋ค์ง์ ๋ฌธ์์ด list ๋ฅผ ๋ณด๊ดํฉ๋๋ค. | ||
> 8. ์ด๋ฅผ ์ถ๋ ฅํฉ๋๋ค. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.list_wrapper { | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: flex-start; | ||
} | ||
|
||
.item_wrapper { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
padding: 8px; | ||
padding-bottom: 0; | ||
border-radius: 8px; | ||
margin-bottom: 12px; | ||
} | ||
|
||
.item_wrapper:hover { | ||
background-color: var(--box-bg-hovered-color); | ||
box-shadow: 10px 20px 20px 0 var(--box-shadow-hovered-color); | ||
transition: 0.5s ease; | ||
} | ||
|
||
.item_header { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
margin-bottom: 6px; | ||
} | ||
|
||
.title { | ||
font-size: 1.3rem; | ||
font-weight: bold; | ||
} | ||
|
||
.date { | ||
margin-left: 0.5rem; | ||
font-size: 0.8rem; | ||
font-weight: 400; | ||
color: var(--description-text-color); | ||
} | ||
|
||
.tag_wrapper { | ||
display: flex; | ||
justify-content: left; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import Link from "next/link"; | ||
import Tag from "@/common/components/PostList/PostItem/Tag"; | ||
|
||
import styles from "./AlgorithmPost.module.css"; | ||
|
||
import type { PostData } from "@/common/utils/posts"; | ||
|
||
interface AlgorithmPostListProps { | ||
algorithmPostList: PostData[]; | ||
} | ||
|
||
const AlgorithmPostList = ({ algorithmPostList }: AlgorithmPostListProps) => { | ||
return ( | ||
<section className={styles.list_wrapper}> | ||
{algorithmPostList.map((algorithmPostData) => ( | ||
<AlgorithmPostItem | ||
key={algorithmPostData.id} | ||
algorithmPostData={algorithmPostData} | ||
href={`/algorithms/${algorithmPostData.id}`} | ||
/> | ||
))} | ||
</section> | ||
); | ||
}; | ||
|
||
interface AlgorithmPostItemProps { | ||
href: string; | ||
algorithmPostData: PostData; | ||
} | ||
|
||
const AlgorithmPostItem = ({ | ||
href, | ||
algorithmPostData, | ||
}: AlgorithmPostItemProps) => { | ||
const { title, date, tagList } = algorithmPostData; | ||
|
||
return ( | ||
<article className={styles.item_wrapper}> | ||
<Link href={href}> | ||
<div className={styles.item_header}> | ||
<div className={styles.title}>{title}</div> | ||
<div className={styles.date}>{date}</div> | ||
</div> | ||
<div className={styles.tag_wrapper}> | ||
{tagList.map((tag) => ( | ||
<Tag key={tag} tag={tag} /> | ||
))} | ||
</div> | ||
</Link> | ||
</article> | ||
); | ||
}; | ||
|
||
export default AlgorithmPostList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
.title { | ||
margin-top: 0; | ||
} | ||
|
||
.date { | ||
margin-bottom: 3rem; | ||
font-size: 1rem; | ||
font-weight: 400; | ||
color: var(--description-text-color); | ||
} | ||
|
||
.html_wrapper { | ||
line-height: 1.7rem; | ||
color: var(--post-text-color); | ||
} | ||
|
||
.html_wrapper h1 { | ||
margin: 3rem 0; | ||
color: var(--post-h-tag-color); | ||
} | ||
|
||
.html_wrapper h2 { | ||
margin-top: 3rem; | ||
color: var(--post-h-tag-color); | ||
} | ||
|
||
.html_wrapper h3 { | ||
margin-top: 2rem; | ||
color: var(--post-h-tag-color); | ||
} | ||
|
||
.html_wrapper a { | ||
color: var(--post-link-tag-color); | ||
text-decoration: underline; | ||
text-underline-position: under; | ||
text-decoration-color: var(--post-link-tag-color); | ||
text-decoration-thickness: 1px; | ||
} | ||
|
||
.html_wrapper strong { | ||
color: var(--post-h-tag-color); | ||
} | ||
|
||
.html_wrapper blockquote { | ||
font-weight: 500; | ||
font-style: italic; | ||
color: var(--post-block-quote-color); | ||
border-left: 3px solid var(--post-block-quote-color); | ||
margin: 2rem 0; | ||
padding-left: 1em; | ||
} | ||
|
||
.html_wrapper li { | ||
margin: 1rem 0; | ||
} | ||
|
||
.html_wrapper code { | ||
color: var(--post-h-tag-color); | ||
font-size: 1rem; | ||
font-weight: bold; | ||
font-family: oblique; | ||
background: none; | ||
} | ||
|
||
.html_wrapper pre { | ||
color: var(--post-h-tag-color); | ||
font-size: 1rem; | ||
line-height: 2rem; | ||
font-family: inherit; | ||
border: 1px solid var(--post-text-color); | ||
border-radius: 10px; | ||
overflow: hidden; | ||
background-color: none; | ||
} | ||
|
||
.html_wrapper pre code { | ||
color: #d1d5db; | ||
font-size: 1rem; | ||
font-weight: initial; | ||
font-family: inherit; | ||
background-color: #292c33; | ||
} | ||
|
||
@media (max-width: 768px) { | ||
.thumbnail_wrapper { | ||
position: relative; | ||
width: 100%; | ||
height: 15rem; | ||
border-radius: 10px; | ||
overflow: hidden; | ||
} | ||
|
||
.html_wrapper img { | ||
width: 90%; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { getAllPostIds, getPostData } from "@/common/utils/posts"; | ||
|
||
import MDXRemote from "@/common/components/MDXRemote"; | ||
import TopScrollButton from "@/common/components/TopScrollButton"; | ||
import TableOfContents from "@/common/components/TableOfContents"; | ||
|
||
import styles from "./page.module.css"; | ||
|
||
import type { Metadata } from "next"; | ||
import type { Params } from "@/common/types/params"; | ||
|
||
const getPost = async (params: Params) => { | ||
const postData = await getPostData({ postType: "algorithms", id: params.id }); | ||
|
||
return postData; | ||
}; | ||
|
||
export const generateMetadata = async ({ | ||
params, | ||
}: { | ||
params: Params; | ||
}): Promise<Metadata> => { | ||
const { title, description, tagList } = await getPost(params); | ||
|
||
return { | ||
title, | ||
description, | ||
keywords: tagList, | ||
}; | ||
}; | ||
|
||
export const generateStaticParams = async () => { | ||
const allPostIds = getAllPostIds({ postType: "algorithms" }); | ||
|
||
return allPostIds; | ||
}; | ||
|
||
const AlgorithmPost = async ({ params }: { params: Params }) => { | ||
const { date, title, mdxSource, tableOfContents } = await getPost(params); | ||
|
||
return ( | ||
<> | ||
<h1 className={styles.title}>{title}</h1> | ||
<div className={styles.date}>{date}</div> | ||
<div className={styles.html_wrapper}> | ||
<MDXRemote {...mdxSource} /> | ||
</div> | ||
<TopScrollButton /> | ||
<TableOfContents tableOfContents={tableOfContents} /> | ||
</> | ||
); | ||
}; | ||
|
||
export default AlgorithmPost; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { getSortedPostsData } from "@/common/utils/posts"; | ||
|
||
import AlgorithmPostList from "./AlgorithmPostList"; | ||
|
||
import type { Metadata } from "next"; | ||
|
||
export const metadata: Metadata = { | ||
title: "์๊ณ ๋ฆฌ์ฆ ํฌ์คํ ", | ||
description: "๋ฌธ์ ํ์ด๋ฅผ ๊ธฐ๋กํ ํฌ์คํ ", | ||
}; | ||
|
||
const Algorithms = () => { | ||
const allAlgorithmsData = getSortedPostsData({ postType: "algorithms" }); | ||
console.log(allAlgorithmsData); | ||
return <AlgorithmPostList algorithmPostList={allAlgorithmsData} />; | ||
}; | ||
|
||
export default Algorithms; |
Oops, something went wrong.