-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
683 additions
and
11 deletions.
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
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,28 @@ | ||
#include <iostream> | ||
#include <stack> | ||
|
||
int main(void) | ||
{ | ||
std::ios_base::sync_with_stdio(false); | ||
std::cin.tie(NULL); | ||
|
||
int n; | ||
char ch; | ||
std::string str; | ||
std::stack <char> stk1, stk2; | ||
|
||
std::cin >> str >> n; | ||
for (int i = 0; i < str.size(); i++) stk1.push(str[i]); | ||
|
||
for (int i = 0; i < n; i++) { | ||
std::cin >> ch; | ||
if (ch == 'L' && !stk1.empty()) stk2.push(stk1.top()), stk1.pop(); | ||
else if (ch == 'D' && !stk2.empty()) stk1.push(stk2.top()), stk2.pop(); | ||
else if (ch == 'B' && !stk1.empty()) stk1.pop(); | ||
else if (ch == 'P') std::cin >> ch, stk1.push(ch); | ||
} | ||
|
||
while(stk1.size() > 0) stk2.push(stk1.top()), stk1.pop(); | ||
while(stk2.size() > 0) std::cout << stk2.top(), stk2.pop(); | ||
return 0; | ||
} |
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,43 @@ | ||
#include <iostream> | ||
#include <stack> | ||
|
||
int main(void) | ||
{ | ||
char ch; | ||
std::stack <char> stk; | ||
std::string res; | ||
|
||
ch = getchar(); | ||
while (ch != '\n') { | ||
if (ch == '+' || ch == '-') { | ||
while(!stk.empty() && stk.top() != '(') { | ||
res.push_back(stk.top()); | ||
stk.pop(); | ||
} | ||
stk.push(ch); | ||
} | ||
else if (ch == '*' || ch == '/') { | ||
if (!stk.empty() && (stk.top() == '*' || stk.top() == '/')) { | ||
res.push_back(stk.top()); | ||
stk.pop(); | ||
} | ||
stk.push(ch); | ||
} | ||
else if (ch == ')') { | ||
while (!stk.empty() && stk.top() != '(') { | ||
res.push_back(stk.top()); | ||
stk.pop(); | ||
} | ||
if (!stk.empty()) stk.pop(); | ||
} | ||
else if (ch == '(') stk.push(ch); | ||
else res.push_back(ch); | ||
ch = getchar(); | ||
} | ||
while (!stk.empty()) { | ||
res.push_back(stk.top()); | ||
stk.pop(); | ||
} | ||
std::cout << res; | ||
return 0; | ||
} |
37 changes: 37 additions & 0 deletions
37
YIM2UL2ET/์์ ์ ๋ฐ๋, ํฐ ์ ์ฐ์ฐ/9์ฐจ์ - BOJ 1914.cpp
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,37 @@ | ||
#include <iostream> | ||
|
||
std::string FindValue(int n) | ||
{ | ||
std::string result = "1"; | ||
for (int i = 0; i < n; i++) { | ||
for (int j = 0; j < result.size(); j++) { | ||
result[j] = (result[j] - '0') * 2 + '0'; | ||
if (result[j] > '9') { | ||
result[j] -= 10; | ||
if (j == 0) result.insert(result.begin(), '1'), j++; | ||
else result[j-1]++; | ||
} | ||
} | ||
} | ||
result[result.size()-1]--; | ||
return result; | ||
} | ||
|
||
void Hanoi(int level, int start, int between, int end) | ||
{ | ||
if (level == 1) std::cout << start << " " << end << "\n"; | ||
else { | ||
Hanoi(level-1, start, end, between); | ||
std::cout << start << " " << end << "\n"; | ||
Hanoi(level-1, between, start, end); | ||
} | ||
return; | ||
} | ||
|
||
int main(void) { | ||
int n; | ||
std::cin >> n; | ||
std::cout << FindValue(n) << "\n"; | ||
if (!(n > 20)) Hanoi(n, 1, 2, 3); | ||
return 0; | ||
} |
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,23 @@ | ||
#include <iostream> | ||
|
||
int ary[1000] = {0}; | ||
|
||
int solve(int n) | ||
{ | ||
if (ary[n-1] != 0) return ary[n-1]; | ||
for (int i = 0; n-i*2 > 1;) ary[n-1] += solve(++i); | ||
return ++ary[n-1]; | ||
} | ||
|
||
int main(void) | ||
{ | ||
int n, input; | ||
ary[0] = 1; | ||
|
||
std::cin >> n; | ||
for (int i = 0; i < n; i++) { | ||
std::cin >> input; | ||
std::cout << solve(input) << std::endl; | ||
} | ||
return 0; | ||
} |
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,42 @@ | ||
#include <iostream> | ||
|
||
void cover1(int n, int level) | ||
{ | ||
for (int i = 0; i < level; i++) std::cout << "* "; | ||
for (int i = 0; i < 4*(n-level)-3; i++) std::cout << "*"; | ||
for (int i = 0; i < level; i++) std::cout << " *"; | ||
std::cout << "\n"; | ||
} | ||
|
||
void cover2(int n, int level) | ||
{ | ||
for (int i = 0; i < level; i++) std::cout << "* "; | ||
std::cout << "*"; | ||
for (int i = 0; i < 4*(n-level)-5; i++) std::cout << " "; | ||
std::cout << "*"; | ||
for (int i = 0; i < level; i++) std::cout << " *"; | ||
std::cout << "\n"; | ||
} | ||
|
||
void star(int n, int level) | ||
{ | ||
if (n == level+1) { | ||
for (int i = 0; i < n*2-2; i++) std::cout << "* "; | ||
std::cout << "*\n"; | ||
} | ||
else { | ||
cover1(n, level); | ||
cover2(n, level); | ||
star(n, level+1); | ||
cover2(n, level); | ||
cover1(n, level); | ||
} | ||
} | ||
|
||
int main(void) | ||
{ | ||
int n; | ||
std::cin >> n; | ||
star(n, 0); | ||
return 0; | ||
} |
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,16 @@ | ||
def dfs(my_word): | ||
global dic | ||
vowel = ['A','E','I','O','U'] | ||
|
||
if len(my_word)<=5: | ||
dic.append(my_word) | ||
|
||
for v in vowel: | ||
dfs(my_word + v) | ||
|
||
def solution(word): | ||
global dic | ||
dic = [] | ||
dfs('') | ||
answer = dic.index(word) | ||
return answer |
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
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,39 @@ | ||
def MakeSet(s): #2๊ธ์์ฉ ๋์ ์ํ๋ฒณ๋ง ๋ฆฌ์คํธ๋ก ์ถ๋ ฅ | ||
lst = [] | ||
for i,_ in enumerate(s[:-1]): | ||
a = s[i:i+2] | ||
if a.isalpha(): | ||
lst.append(a.lower()) | ||
return lst | ||
|
||
def func(l1, l2): #์ค๋ณต ๊ต์งํฉ๊ณผ ์ค๋ณต ํฉ์งํฉ์ ๊ธธ์ด๋ฅผ ๊ฐ๊ฐ ์ถ๋ ฅ | ||
intersection_set, union_set = [], [] | ||
inter = set(l1) & set(l2) | ||
union = set(l1) | set(l2) | ||
|
||
for n in union: | ||
intersection_num = min(l1.count(n),l2.count(n)) | ||
union_num = max(l1.count(n),l2.count(n)) | ||
|
||
for _ in range(intersection_num): | ||
intersection_set.append(n) | ||
|
||
for _ in range(union_num): | ||
union_set.append(n) | ||
|
||
return len(intersection_set), len(union_set) | ||
|
||
def solution(str1, str2): #๋ฉ์ธ ์ฝ๋ | ||
answer = 0 | ||
|
||
arr1 = MakeSet(str1) | ||
arr2 = MakeSet(str2) | ||
|
||
a,b = func(arr1,arr2) | ||
|
||
if b: | ||
answer = int((a/b)*65536) | ||
else: | ||
answer = 65536 | ||
|
||
return answer |
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,25 @@ | ||
def solution(cacheSize, cities): | ||
answer = 0 | ||
cities = [city.lower() for city in cities] | ||
cache, cache_hit = [], [] | ||
|
||
for i,city in enumerate(cities): | ||
if len(cache)<cacheSize and city not in cache: | ||
cache.append(city) | ||
cache_hit.append(i) | ||
answer +=5 | ||
|
||
elif city in cache: | ||
cache_hit[cache.index(city)] =i | ||
answer +=1 | ||
|
||
elif cache: | ||
idx = cache_hit.index(min(cache_hit)) | ||
cache[idx] = city | ||
cache_hit[idx] = i | ||
answer +=5 | ||
|
||
else: | ||
answer+=5 | ||
|
||
return answer |
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 @@ | ||
def solution(s): | ||
answer = [] | ||
dic = {} | ||
s = s.replace('{','').replace('}','').split(',') | ||
|
||
for n in s: | ||
n = int(n) | ||
if n not in dic: | ||
dic[n] = 1 | ||
else: | ||
dic[n]+= 1 | ||
|
||
dic_sorted = sorted(dic.items(), key=lambda x:x[1], reverse=True) | ||
|
||
for d in dic_sorted: | ||
answer.append(d[0]) | ||
|
||
return answer |
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,27 @@ | ||
def func(bracket): | ||
stk = [] | ||
for b in bracket: | ||
if b in ["[","{","("]: | ||
stk.append(b) | ||
elif b in ["]","}",")"]: | ||
if not stk: | ||
return False | ||
if stk[-1]=="[" and b=="]": | ||
stk.pop() | ||
elif stk[-1]=="{" and b=="}": | ||
stk.pop() | ||
elif stk[-1]=="(" and b==")": | ||
stk.pop() | ||
else: | ||
return False | ||
return not stk | ||
|
||
def solution(s): | ||
answer = 0 | ||
l = len(s) | ||
for i in range(l): | ||
x = s[i:]+s[:i] | ||
if func(x): | ||
answer +=1 | ||
|
||
return answer |
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,16 @@ | ||
from collections import deque | ||
|
||
def solution(people, limit): | ||
answer = 0 | ||
people = deque(sorted(people)) | ||
|
||
while len(people)>1: | ||
if people[0]+people[-1]<=limit: | ||
people.pop() | ||
people.popleft() | ||
answer+=1 | ||
else: | ||
people.pop() | ||
answer+=1 | ||
|
||
return answer+1 if people else answer |
Oops, something went wrong.