kwakcena / codeplus-sw-competency Goto Github PK
View Code? Open in Web Editor NEW백준 SW 역량테스트 준비 강의
백준 SW 역량테스트 준비 강의
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> vec(5, 1); // 1로 초기화된 5개의 원소
// 방법1
for (int i = 0 ; i < vec.size(); i++)
cout << vec[i] << endl;
// 방법2
vector<int>::iterator it;
for (it = vec.begin(); it != vec.end(); it++)
cout << *it << endl;
// 방법3
for (auto it = vec.begin(); it != vec.end(); it++)
cout << *it << endl;
}
파이썬 인터프리터 소스 코드(C 언어)에는 최대 재귀 깊이가 1,000으로 정의되어 있으며 최대 재귀 깊이는 sys 모듈의 getrecursionlimit 함수로 확인할 수 있습니다.
import sys
sys.getrecursionlimit()
1000
만약 최대 재귀 깊이를 늘리려면 sys 모듈의 setrecursionlimit 함수를 사용하면 됩니다.
sys.setrecursionlimit(10**8) # 최대 재귀호출 횟수를 10의 8승으로 늘림
어떤 리스트에 들어있는 순열의 다음 순열이나 이전 순열을 구하는 코드
1. A[i - 1] < A[i] 를 만족하는 가장 큰 i를 찾는다.
2. j >= i 이면서 A[j] > A[i - 1] 를 만족하는 가장 큰 j를 찾는다.
3. A[i - 1] 과 A[j] 를 swap 한다
4. A[i] 부터 순열을 뒤집는다.
numbers = [7, 2, 3, 6, 5, 4, 1]
def next_permutation(a):
# 1. A[i - 1] < A[i] 를 만족하는 가장 큰 i 를 찾는다.
# 7, 2, 3, 6, 5, 4, 1 (i = 6)
# i
i = len(a) - 1
while i > 0 and a[i - 1] >= a[i]:
i -= 1
# 만약 i가 0보다 작거나 같으면 다음 순열이 없다는 것.
if i <= 0:
return False
# 2. j >= i 이면서 A[j] > A[i - 1]를 만족하는 가장 큰 j를 찾는다.
# 7, 2, 3, 6, 5, 4, 1 (j = 6)
# i j
# 6 ~ 4 사이 숫자 중 A[j] > 3 보다 큰 숫자의 위치인 j를 찾는다.
j = len(a) - 1
while a[j] <= a[i - 1]:
j -= 1
# 3. A[i - 1] 인 3과 A[j] 인 4의 위치를 바꾼다.
# 7, 2, 4, 6, 5, 3, 1
a[i - 1], a[j] = a[j], a[i - 1]
# 4. A[i] 부터 순열을 뒤집는다.
# i = 3, j = 6
j = len(a) - 1
while i < j:
a[i], a[j] = a[j], a[i]
i += 1
j -= 1
def prev_permutation(a):
i = len(a) - 1
while i > 0 and a[i - 1] <= a[i]:
i -= 1
if i <= 0:
return False
j = len(a) - 1
while a[j] >= a[i - 1]:
j -= 1
a[i - 1], a[j] = a[j], a[i - 1]
j = len(a) - 1
while i < j:
a[i], a[j] = a[j], a[i]
i += 1
j -= 1
return True
from collections import OrderedDict
strings = ["ABC", "ABDDDD", "XYZ"]
numbers = [1, 1, 1, 1, 1, 2, 2, 3, 3]
# 리스트의 원소를 한 줄로 이어 붙인다.
string = ''.join(strings) # ABCABDDDDXYZ
num = ''.join(map(str, numbers)) # 111112233
# set을 이용하여 중복을 제거 후 리스트로 바꾼다.
print(list(set(''.join(strings))))
print(list(set(''.join(map(str, numbers)))))
# 문자열을 순서대로 정렬하고 싶다면 OrderedDict를 이용한다.
print(''.join(OrderedDict.fromkeys(string)))
print(''.join(OrderedDict.fromkeys(num)))
#74 단어 수학 - 백준 1339
크기 n * n
의 2차원 vector를 만드는 방법
int n;
scanf("%d", &n);
vector<vector<int>> arr(n, vector<int>(n));
[1, 2, 3]
이나 (1, 2, 3)
같은 리스트나 튜플을 하나로 이어 붙이는 방법은 PS에서 자주 쓰인다.
numbers = [1, 2, 3]
print(str(numbers)[1:-1].replace(', ', ''))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.