전체 글(331)
-
[C++] lambda 함수
[capture](parameters) -> return_type { body } capture: 람다 함수가 외부 범위에서 변수를 "캡처"할 수 있게 합니다.parameters: 함수의 매개변수 목록입니다.return_type: 함수의 반환형을 명시적으로 지정할 수 있습니다 (생략 가능).body: 함수의 본체로, 수행할 코드를 작성합니다.
2024.08.30 -
[BOJ] 1181번 : 단어 정렬
1. problem : https://www.acmicpc.net/problem/1181 2. solution 1 :#include using namespace std;int n;bool cmpw(const string& a, const string& b) { if (a.size() != b.size()) return a.size() > n; vector v; for (int i = 0; i > x; v.push_back(x); } sort(v.begin(), v.end(),cmpw); int cnt = 1; int idx = 1; while (cnt 3. solution 2 :// Authored by : tongnamuu// Co-authored by : -// http://boj.kr/e36..
2024.08.30 -
[BOJ] 5648번 : 역원소 정렬
1. problem : https://www.acmicpc.net/problem/5648 2. solution 1 :#include using namespace std;int n;vector v; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i > x; v.push_back(x); } vector nums; for (string& s : v) { string temp; for (int i = s.size() - 1; i >= 0; i--) { if (!(temp.empty() && s[i] == 0)) temp.push_back(s[i]); } nums.push_back(stoll(te..
2024.08.30 -
[BOJ] 1914번 : 하노이 탑
1. problem : https://www.acmicpc.net/problem/1914 2. solution 1 :#include using namespace std;int n; string multiply(string a, string b) { int n = a.size(); int m = b.size(); vector result(n + m, 0); // a자리 * b자리 최대수는 a+b자리 for (int i = n - 1; i >= 0; i--) { for (int j = m - 1; j >= 0; j--) { int mul = (a[i] - '0') * (b[j] - '0'); int sum = mul + result[i + j + 1]; result[i + j] += su..
2024.08.29 -
[BOJ] 11652번 : 카드
1. problem : https://www.acmicpc.net/problem/11652 2. solution 1 :#include using namespace std;int n;vector v; // number, cntint main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i > x; v.push_back(x); } sort(v.begin(), v.end()); int idx = 0; int cnt = 0; long long maxVal = -(1ll 이 코드는 100% 정확한 코드가 아니다. 왜냐하면, 마지막 숫자에대해서는 고려하지 않았기때문이다. 물론, 마지막 숫자가 1개라면 영향이 없기때문에 , 정..
2024.08.29 -
[C++] sort
출처 : https://blog.encrypted.gg/966 [실전 알고리즘] 0x0F강 - 정렬 II안녕하세요, 정렬 두 번째 시간입니다. 첫 시간에는 머지 소트와 퀵 소트를 배웠고 이번에는 카운팅 소트랑 라딕스 소트를 배울 예정입니다. 아마 전 시간보다는 더 쉬울거라 걱정을 조금 덜어blog.encrypted.gg
2024.08.29