자기개발👨‍💻/코딩 알고리즘 119

[c++] 백준 1652 누울 자리를 찾아라

https://www.acmicpc.net/problem/1652 1652번: 누울 자리를 찾아라 첫째 줄에 방의 크기 N이 주어진다. N은 1이상 100이하의 정수이다. 그 다음 N줄에 걸쳐 N개의 문자가 들어오는데 '.'은 아무것도 없는 곳을 의미하고, 'X'는 짐이 있는 곳을 의미한다. www.acmicpc.net #include #include using namespace std; int main() { int n; int cnta = 0; int cntb = 0; int dot = 0; string arr[100]; cin >> n; for (int i = 0; i > arr[i]; } //가로 카운트 시작 for (int i = 0; i < n; i++) { fo..

[python] 백준 6603 로또

https://www.acmicpc.net/problem/6603 6603번: 로또 문제 독일 로또는 {1, 2, ..., 49}에서 수 6개를 고른다. 로또 번호를 선택하는데 사용되는 가장 유명한 전략은 49가지 수 중 k(k>6)개의 수를 골라 집합 S를 만든 다음 그 수만 가지고 번호를 선택하는 www.acmicpc.net from itertools import combinations while(1): inp = list(map(int,input().split())) number = inp[0] if number==0: break inp= inp[1:] arr=inp[:] tmp = list(combinations(arr,6)) for i in range(len(tmp)): for j in rang..

[c++] 백준 1912 연속합

#include #include using namespace std; int arr[100000]; int dp[100000]; int main() { int n; cin >> n; for (int i = 0; i > arr[i]; } //dp는 dp[0] = arr[0]; //기본적으로 첫번째 인덱스는 같다, 먼저 초기화해주기 for (int i = 1; i < n; i++) { dp[i] = max(dp[i - 1] + arr[i], arr[i]); } int Max = dp[0]; //입력조건을 보고 나올 수 없는 수 중에서 가장 작은수로 초기화하기 or 현재 dp배열에서 가장 작은수 for (int i = 0; i < n; i++) if (Max < dp[i]) Ma..

[C++] 백준 12919 A와 B 2

https://www.acmicpc.net/problem/12919 12919번: A와 B 2 수빈이는 A와 B로만 이루어진 영어 단어 존재한다는 사실에 놀랐다. 대표적인 예로 AB (Abdominal의 약자), BAA (양의 울음 소리), AA (용암의 종류), ABBA (스웨덴 팝 그룹)이 있다. 이런 사실에 놀란 수빈 www.acmicpc.net #include #include #include #include using namespace std; int main() { string s, t; queue q; cin >> s; cin >> t; string front1, front2; q.push(t); while (!q.empty()) { front1 = q.front(); front2 = q.fr..

[python] 백준 1543 문서검색

https://www.acmicpc.net/problem/1543 1543번: 문서 검색 세준이는 영어로만 이루어진 어떤 문서를 검색하는 함수를 만들려고 한다. 이 함수는 어떤 단어가 총 몇 번 등장하는지 세려고 한다. 그러나, 세준이의 함수는 중복되어 세는 것은 빼고 세야 한� www.acmicpc.net a=[] a=input() find=[] find=input() cnt=0 for i in range(len(a)): for j in range(i,len(a)): if a[0:len(find)]==find: a=a[len(find):] cnt+=1 else: a=a[1:] print(cnt) 내가 찾으려는 find가 있으면 a를 find만큼 자르고, 그렇지 않으면 맨 앞 글자를 하나씩 지워가면서 문..

[c++] 백준 1085 직사각형에서 탈출

https://www.acmicpc.net/problem/1085 1085번: 직사각형에서 탈출 첫째 줄에 x y w h가 주어진다. w와 h는 1,000보다 작거나 같은 자연수이고, x는 1보다 크거나 같고, w-1보다 작거나 같은 자연수이고, y는 1보다 크거나 같고, h-1보다 작거나 같은 자연수이다. www.acmicpc.net #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int x, y, h, w = 0; cin >> x >> y >> w>> h; int min1,min2 = 0; min1 = h - y; min2 = w-x; int minn,m..

[python] 백준 1026 보물

https://www.acmicpc.net/problem/1026 1026번: 보물 첫째 줄에 N이 주어진다. 둘째 줄에는 A에 있는 N개의 수가 순서대로 주어지고, 셋째 줄에는 B에 있는 수가 순서대로 주어진다. N은 50보다 작거나 같은 자연수이고, A와 B의 각 원소는 100보다 작거� www.acmicpc.net answer =0 inp = int(input()) inp_a=input() inp_b=input() a=inp_a.split() b=inp_b.split() for i in range(inp): a[i]=int(a[i]) b[i]=int(b[i]) a.sort() b.sort(reverse=True) for i in range(inp): answer +=a[i]*b[i] print(an..