분류 전체보기

    나는야 포켓몬 마스터 이다솜 풀이

    문제 링크: https://www.acmicpc.net/problem/1620 백준 집합과 맵 3단계 - 1620번 나는야 포켓몬 마스터 이다솜을 풀어보았다. 풀이: 입력을 받아, 숫자가 들어오면 이름을 이름이 들어오면 숫자를 내보내면 된다. C++의 경우, https://tree-water.tistory.com/116 이 코드를 참고했다. 파이썬의 경우, 딕셔너리를 써서 시간을 줄였다. C++ #include #include #include using namespace std; int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); map mpInt; map mpStr; int n, m, idx = 0; cin ..

    문자열 집합 풀이

    문제 링크: https://www.acmicpc.net/problem/14425 백준 집합과 맵 2단계 - 14425번 문자열 집합을 풀어보았다. 풀이: 문자열을 받아 거기에 속해있는지 알아보면 된다. C++의 경우, unordered set을 이용했다. 파이썬의 경우, 시간을 줄이기 위해 list보다 set이나 dictionary를 사용해야 한다. C++ #include #include using namespace std; int main() { int n,m,a; int cnt=0; cin>>n>>m; string s; unordered_setus; for(int i=0;i>s; us.insert(s); } for(int i=0;i>s; if(us.find(s)!=us.end()) cnt++; } c..

    숫자 카드 풀이

    문제 링크: https://www.acmicpc.net/problem/10815 백준 집합과 맵 1단계 - 10815번 숫자 카드를 풀어보았다. 풀이: 이진탐색을 써서 풀면 된다. C++의 경우 algorithm 헤더가 제공하는 이진 탐색 함수를 이용했다. 파이썬의 경우, if bisearch(card,num[i],0,n-1) is not False: print(1,end=' ') 에서 is not을 안 쓰고 != 쓰면 틀렸다고 나왔다. 찾아보니 ==는 값을 비교하고, is는 객체를 비교한다고 나왔다. is는 none, false, true 등을 비교할 때만 써야 할 거 같다. C++ #include #include #include using namespace std; int main() { int n,..

    영화감독 숌 풀이

    문제 링크: https://www.acmicpc.net/problem/1436 백준 브루트 포스 5단계 - 1436번 영화감독 숌을 풀어보았다. 풀이: 666이 들어있는 숫자를 표시하면 된다. C++ #include using namespace std; int main() { int n; scanf("%d",&n); int count=0; int num; for(num=666;count0;i/=10) { if(i%1000==666) { count++; break; } } } printf("%d",num-1); } Python n=int(input()) cnt=0 num=666 while cnt0: # i 안에 666이 있는지 확인 if i%1000==666: cnt+=1 break i=i//10 num+..

    체스판 다시 칠하기 풀이

    문제 링크: https://www.acmicpc.net/problem/1018 백준 브루트 포스 4단계 - 1018번 체스판 다시 칠하기를 풀어보았다. 풀이: 첫 칸이 흰색인 경우와 검은색인 경우로 나뉘기 때문에 그 점을 신경 써야 한다. C++의 경우, 체스보드를 만들어놓고 풀었다. C++ #include #include #include using namespace std; const int INF = 987654321; const int MAX = 50; int M, N; string board[MAX]; //(0, 0)이 W인 체스보드 string whiteFirst[8]={{"WBWBWBWB"},{"BWBWBWBW"},{"WBWBWBWB"},{"BWBWBWBW"},{"WBWBWBWB"}, {"BW..

    덩치 풀이

    문제 링크: https://www.acmicpc.net/problem/7568 백준 브루트 포스 3단계 - 7568번 덩치를 풀어보았다. 풀이: 몸무게와 키 둘 다 커야 한다. C++ #include #include using namespace std; int main() { int n,a,b; cin>>n; vector weight; vector height; vector ranks(n); fill(ranks.begin(),ranks.end(),1); for(int i=0;i>a>>b; weight.push_back(a); height.push_back(b); } for(int i=0;iheight[j]) ranks[j]++; } } for(int i=0;i

    분해합 풀이

    문제 링크: https://www.acmicpc.net/problem/2231 백준 브루트 포스 2단계 - 2231번 분해합을 풀어보았다. 풀이: 분해합을 1부터 n까지 구해 비교한다. 파이썬의 경우, sum(map(int,str(i)))로 자릿수의 합을 구할 수 있다는 것을 알게 되었다. C++ #include #include using namespace std; int main() { int n; cin>>n; for(int i=1;i0) { check+=ii%10; ii/=10; } if(check==n) { cout

    블랙잭 풀이

    문제 링크: https://www.acmicpc.net/problem/2798 백준 브루트 포스 1단계 - 2798번 블랙잭을 풀어보았다. 풀이: 카드 세 장을 골라 그 합이 입력값과 최대한 비슷하게 만들면 된다. C++ #include #include using namespace std; int main() { int n,m,inp; cin>>n>>m; int mcheck=0; vector v; for(int i=0;i>inp; v.push_back(inp); } for(int i=0;i

    하노이 탑 이동 순서 풀이

    문제 링크: https://www.acmicpc.net/problem/11729 백준 재귀 6단계 - 11729번 하노이 탑 이동 순서를 풀어보았다. 풀이: 하노이 탑을 재귀함수로 작성하면 된다. C++ #include #include using namespace std; void hanoi(int k,int a, int b, int c) { if(k==1) printf("%d %d\n",a,b); else { hanoi(k-1,a,c,b); printf("%d %d\n",a,b); hanoi(k-1,c,b,a); } } int main() { int n; scanf("%d",&n); cout

    별 찍기 - 10 풀이

    문제 링크: https://www.acmicpc.net/problem/2447 백준 재귀 5단계 - 2447번 별 찍기 - 10를 풀어보았다. 풀이: 별 무늬를 찍는 재귀함수를 만들면 된다. 파이썬의 경우, 입출력 시간을 빠르게 하기 위해 input과 print를 바꾸었다. C++ #include using namespace std; void sol(int a,int b, int c) { if((a/c)%3==1&&(b/c)%3==1) printf(" "); else { if(c/3==0) printf("*"); else sol(a,b,c/3); } } int main() { int n; scanf("%d",&n); for(int i=0;i