Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions Algorithm/Code/Week5/week5_20185306_HuHongJune.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "607d8028-d724-489f-96f7-512a4f95d853",
"metadata": {},
"source": [
"문제 1 OX퀴즈 (백준 8958)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a4bccf61-42e2-42ef-be7f-de6f00858488",
"metadata": {},
"outputs": [],
"source": [
"a = input()\n",
"for i in range(int(a)):\n",
" b = input()\n",
" c = 0\n",
" d = 1\n",
" for j in range(len(b)):\n",
" if b[j] == 'O':\n",
" c += d\n",
" d += 1\n",
" else:\n",
" d = 1\n",
" print(c)"
]
},
{
"cell_type": "markdown",
"id": "fc5b5208-6c23-4944-a707-1666c1ea3516",
"metadata": {},
"source": [
"문제 2 피보나치 수 2 (백준 2748)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b0337bed-fa12-408d-9fd3-68e0a0b527f2",
"metadata": {},
"outputs": [],
"source": [
"dp = {}\n",
"\n",
"def fib(n):\n",
" if n == 0:\n",
" return 0\n",
" if n == 1:\n",
" return 1\n",
" if dp.get(n) != None:\n",
" return dp.get(n)\n",
" \n",
" dp[n] = fib(n - 1) + fib(n - 2)\n",
" return dp[n]\n",
"\n",
"a = int(input())\n",
"print(fib(a))"
]
},
{
"cell_type": "markdown",
"id": "c972c5c4-6a1a-473b-9717-ac82dec64130",
"metadata": {},
"source": [
"문제 3 소수찾기 (백준 1978)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cf1f6855-282d-4196-b3cf-bfae13c427ac",
"metadata": {},
"outputs": [],
"source": [
"a = int(input())\n",
"b = input().split()\n",
"c = 0\n",
"for i in range(a):\n",
" if int(b[i]) == 2:\n",
" c += 1\n",
" for j in range(2, int(b[i])):\n",
" if int(b[i]) % j == 0:\n",
" break\n",
" if j == int(b[i])-1:\n",
" c += 1\n",
"print(c)"
]
},
{
"cell_type": "markdown",
"id": "bdcf89d9-93d8-48fa-aab7-2a873cba86a8",
"metadata": {},
"source": [
"문제 4 임진왜란 (백준 3077)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8ab730a5-0164-4dab-88be-4b339061b6f3",
"metadata": {},
"outputs": [],
"source": [
"a = int(input())\n",
"b = input().split()\n",
"dic_b = {s:i for i , s in enumerate(b)}\n",
"c = input().split()\n",
"d = 0\n",
"rv = 0\n",
"for i in c:\n",
" for j in range(d, a):\n",
" if dic_b[i] < dic_b[c[j]]:\n",
" rv += 1\n",
" d += 1\n",
"print(str(rv) + \"/\" + str(int((a*(a-1))/2)))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}