본문 바로가기

C++

(226)
[BOJ] 2042번 구간 합 구하기 (C++) https://www.acmicpc.net/problem/2042 2042번: 구간 합 구하기 첫째 줄에 수의 개수 N(1 ≤ N ≤ 1,000,000)과 M(1 ≤ M ≤ 10,000), K(1 ≤ K ≤ 10,000) 가 주어진다. M은 수의 변경이 일어나는 횟수이고, K는 구간의 합을 구하는 횟수이다. 그리고 둘째 줄부터 N+1번째 줄 www.acmicpc.net #include #include #include using namespace std; int N, M, K; long long arr[1000001]; long long *tree; long long init(int node, int start, int end) { if (start == end) { return tree[node] = a..
[BOJ] 12018번 Yonsei TOTO (C++) https://www.acmicpc.net/problem/12018 12018번: Yonsei TOTO 첫째 줄에는 과목 수 n (1 ≤ n ≤ 100)과 주어진 마일리지 m (1 ≤ m ≤ 100)이 주어진다. 각 과목마다 2줄의 입력이 주어지는데 첫째 줄에는 각 과목에 신청한 사람 수 Pi과 과목의 수강인원 Li이 주어 www.acmicpc.net #include #include #include using namespace std; int main() { int n, m, num, p, l; cin >> n >> m; vector vv; for(int i = 0; i > p >> l; vector v; for(int j = 0; j > num;..
[Programmers] 숫자 문자열과 영단어 (C++) https://programmers.co.kr/learn/courses/30/lessons/81301 코딩테스트 연습 - 숫자 문자열과 영단어 네오와 프로도가 숫자놀이를 하고 있습니다. 네오가 프로도에게 숫자를 건넬 때 일부 자릿수를 영단어로 바꾼 카드를 건네주면 프로도는 원래 숫자를 찾는 게임입니다. 다음은 숫자의 일부 자 programmers.co.kr #include #include using namespace std; int solution(string s) { string num[10] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; string str[10] = {"zero", "one", "two", "three", "four", "five",..
[Programmers] 신규 아이디 추천 (C++) https://programmers.co.kr/learn/courses/30/lessons/72410 코딩테스트 연습 - 신규 아이디 추천 카카오에 입사한 신입 개발자 네오는 "카카오계정개발팀"에 배치되어, 카카오 서비스에 가입하는 유저들의 아이디를 생성하는 업무를 담당하게 되었습니다. "네오"에게 주어진 첫 업무는 새로 programmers.co.kr #include #include using namespace std; string solution(string new_id) { bool flag = false; for(int i = 0; i < new_id.length(); i++){ // 1단계 new_id[i] = tolower(new_id[i]); // 2단계 if(!isdigit(new_id[i..
[BOJ] 11508번 2+1 세일 (C++) https://www.acmicpc.net/problem/11508 11508번: 2+1 세일 KSG 편의점에서는 과일우유, 드링킹요구르트 등의 유제품을 '2+1 세일'하는 행사를 하고 있습니다. KSG 편의점에서 유제품 3개를 한 번에 산다면 그중에서 가장 싼 것은 무료로 지불하고 나머지 두 www.acmicpc.net #include #include #include using namespace std; int main() { int n, c; cin >> n; vector v; for(int i = 0; i > c; v.push_back(c); } sort(v.begin(), v.end(), greater()); int sum = 0; for(int i = 0; i < n..
[BOJ] 19637번 IF문 좀 대신 써줘 (C++) https://www.acmicpc.net/problem/19637 19637번: IF문 좀 대신 써줘 첫 번째 줄에는 칭호의 개수 N (1 ≤ N ≤ 105)과 칭호를 출력해야 하는 캐릭터들의 개수 M (1 ≤ M ≤ 105)이 빈칸을 사이에 두고 주어진다. (1 ≤ N, M ≤ 105) 두 번째 줄부터 N개의 줄에 각 칭 www.acmicpc.net #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, m, t, power; string name; vector iv; vector sv; cin >> n >> m; for(int i = 0; i < n; i+..
[BOJ] 1543번 문서 검색 (C++) https://www.acmicpc.net/problem/1543 1543번: 문서 검색 세준이는 영어로만 이루어진 어떤 문서를 검색하는 함수를 만들려고 한다. 이 함수는 어떤 단어가 총 몇 번 등장하는지 세려고 한다. 그러나, 세준이의 함수는 중복되어 세는 것은 빼고 세야 한 www.acmicpc.net #include #include using namespace std; int main() { string s1, s2; getline(cin, s1); getline(cin, s2); int s = 0, cnt = 0; while(1){ int t = s1.find(s2, s); if(t == -1) break; s = t + s2.size(); cnt++; } cout
[BOJ] 1485번 정사각형 (C++) https://www.acmicpc.net/problem/1485 1485번: 정사각형 첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스는 네 줄로 이루어져 있으며, 점의 좌표가 한 줄에 하나씩 주어진다. 점의 좌표는 -100,000보다 크거나 같고, 100,000보다 작거나 같 www.acmicpc.net #include #include #include #include using namespace std; int main() { int n, x, y; cin >> n; for(int i = 0; i > x >> y; v.push_back({x, y}); } for(int j..