알고리즘
-
Print in Reverse해커랭크(HackerRank) 2018. 8. 19. 17:20
1. 문제 2. 알고리즘키워드 - 구현, 출력 3. 코드 12345678910111213141516171819/* Print elements of a linked list in reverse order as standard output head pointer could be NULL as well for empty list Node is defined as struct Node { int data; struct Node *next; }*/void ReversePrint(Node *head){ // This is a "method-only" submission. // You only need to complete this method. if(head != NULL) { ReversePrint(head->n..
-
Reverse a linked list해커랭크(HackerRank) 2018. 8. 19. 17:20
1. 문제 2. 알고리즘키워드 - 구현, 링크리스트 3. 코드 123456789101112131415161718192021222324252627/* Reverse a linked list and return pointer to the head The input list will have at least one element Node is defined as struct Node { int data; struct Node *next; }*/Node* Reverse(Node *head){ // Complete this method Node *tail, *node; tail = NULL; while (head != NULL) { // 다음 노드를 넣어 준다. node = head->next; // head->..
-
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..