c++
-
Compare two linked lists해커랭크(HackerRank) 2018. 8. 19. 17:19
1. 문제 2. 알고리즘키워드 - 구현, 링크 리스트 3. 코드 123456789101112131415161718192021/* Compare two linked lists A and B Return 1 if they are identical and 0 if they are not. Node is defined as struct Node { int data; struct Node *next; }*/int CompareLists(Node *headA, Node* headB){ // This is a "method-only" submission. // You only need to complete this method if (headA == NULL && headB == NULL) { return 1; } ..
-
Insert a node at a specific position in a linked list해커랭크(HackerRank) 2018. 8. 19. 17:18
1. 문제 2. 알고리즘키워드 - 구현, 자료구조, 링크리스트 3. 코드 123456789101112131415161718192021222324252627282930313233343536/* Insert Node at a given position in a linked list head can be NULL First element in the linked list is at position 0 Node is defined as struct Node { int data; struct Node *next; }*/Node* InsertNth(Node *head, int data, int position){ Node *newNode = new Node();//(Node*)malloc(sizeof(Node));..
-
Counting Valleys해커랭크(HackerRank) 2018. 8. 19. 17:17
1. 문제 2. 알고리즘키워드 - 구현 3. 코드 1234567891011121314151617181920212223242526272829303132333435363738#include using namespace std; int countingValleys(int n, string s) { // Complete this function // 초기 위치는 0 int position = 0; // 깊이 int depth = 0; for(int i =0; i
-
CamelCase해커랭크(HackerRank) 2018. 8. 19. 17:15
1. 문제입력 받은 문자열에서 대문자의 개수를 출력 하는 문제 2. 알고리즘키워드 - 구현 3. 코드 12345678910111213141516171819202122232425262728293031#include using namespace std; int camelcase(string s) { // Complete this function const int size = s.size(); int count = 1; for(int i=0; i= 'a' && ch > s; int result = camelcase(s); cout
-
Codeforces Round #462 (Div. 2) - A. A Compatible Pair코드포스(CodeForce) 2018. 8. 17. 18:30
1. 문제 2. 알고리즘키워드 - 구현 * 최노키오 소견 FACT - 음수 곱하기 음수는 양수가 된다. 3. 코드 1234567891011121314151617181920212223242526272829303132333435363738#include#include#include#include#include using namespace std; long long INF = 1ull n >> m; vector arr(n), brr(m); for (int i = 0; i > arr[i]; for (int i = 0; i > brr[i]; long long tmp = -INF; int selIdx = -1; for (int i = 0; i
-
Educational Codeforces Round 38 (Rated for Div. 2) - Word Correction코드포스(CodeForce) 2018. 8. 17. 18:29
1. 문제 2. 알고리즘키워드 - 구현 문제에 제약 사항을 정확히 파악 해야한다.In this problem letters a, e, i, o, u and y are considered to be vowels. 3. 코드 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849#include#include#include#include#include#include using namespace std; bool isMoum(char ch) { if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y') { return tru..
-
Educational Codeforces Round 38 (Rated for Div. 2) - Run For Your Prize코드포스(CodeForce) 2018. 8. 17. 18:28
1. 문제 2. 알고리즘키워드 - 구현 * 접근 방법 왼쪽에서 시작 하면서 현재 위치에서 도착지점까지 거리를 구한다.오른쪽에서 시작하면서 처음 위치까지 거리를 구한다.왼쪽, 오른쪽에 값에서 최소값을 구한다.구한 최소값으로 합계를 구하고, 합계는 최대 값으로 업데이트 한다. 3. 코드 123456789101112131415161718192021222324252627282930313233343536#include#include#include#include#include#include using namespace std; int main(){ int n; cin >> n; vector arr(n); for (int i = 0; i > arr[i]; int sumLeft = 0; int sumLight = 0;..
-
Educational Codeforces Round 37 (Rated for Div. 2) - A. Water The Garden코드포스(CodeForce) 2018. 8. 17. 18:27
1. 문제 2. 알고리즘키워드 - 구현 * 최노키오 소견 재훈씨 map을 선택한거는 아주 좋은 생각이에요.다만 map을 이터레이터를 사용하지 않고 직접 인덱스로 접근 하려고 하면. 만약 map 에 크기가 4 이고map[5] 접근 하는 순간에map 사이즈는 5로 증가가 됩니다. 항상 map 을 사용할 때는 이터레이터로 순회 하거나find 혹은 count 함수로 접근 하도록 하세요. 누구나 처음에 map 을 사용하면서 실수를 하는 문제 입니다. 3. 코드 123456789101112131415161718192021222324252627282930313233343536373839#include#include #include#include using namespace std; int n, k;int a[250]..