Programming/C C++

    Find the Merge point of two joined linked lists

    https://www.hackerrank.com/challenges/find-the-merge-point-of-two-joined-linked-lists/problem 두 연결 리스트의 연결지점을 찾는 문제 마지막에 return tmp1->data 또는 return tmp2->data 둘다 된다. (어차피 합병 포인트는 같으니까) int findMergeNode(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2) { SinglyLinkedListNode *temp1=head1; SinglyLinkedListNode *temp2=head2; while(temp1!=temp2){ if(temp1->next==NULL){ temp1=head2; } else ..

    Apple and Orange

    https://www.hackerrank.com/challenges/apple-and-orange/problem #include #include #include #include #include #include #include #include #include char* readline(); char** split_string(char*); // Complete the countApplesAndOranges function below. void countApplesAndOranges(int s, int t, int a, int b, int apples_count, int* apples, int oranges_count, int* oranges) { for(int i=0;i

    Compare two linked lists

    https://www.hackerrank.com/challenges/dynamic-array/editorial 늉늉늉 bool compare_lists(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2) { while(head1->next||head2->next){ if(head1->next == NULL && head2->next != NULL) return false; else if(head1->next != NULL && head2->next == NULL) return false; if(head1->data == head2->data){ head1 = head1->next; head2 = head2->next; } else { return fal..

    Grading Students

    https://www.hackerrank.com/challenges/grading/problem 문제설명 원점수가 38점 미만일 경우 환산 점수는 원점수와 같다 원점수가 38점 이상이고 원점수보다 큰 최소의 5의 배수와 원점수의 차가 3미만일 경우 환산 점수는 그 5의 배수가 된다 차가 3 이상일 경우 원점수를 환산점수로 한다 환산점수가 40점 미만일 경우 Fail이다 int* gradingStudents(int grades_count, int* grades, int* result_count) { *result_count = grades_count; int *result_grade = malloc(sizeof(int)*grades_count); int tmp=0, div=0; for(int i=0;i=3..

    2D Array

    https://www.hackerrank.com/challenges/2d-array/problem 모래 시계에 관한 문제로, 문제가 엄청 복잡한 것처럼 설명이 되어있지만 그냥 단순하게 이차원 배열에서 원소들의 합 중 가장 큰 값을 찾는 문제이다. #include #include #include #include #include #include #include #include #include char* readline(); char** split_string(char*); // Complete the hourglassSum function below. int hourglassSum(int arr_rows, int arr_columns, int** arr) { int temp=-9999, h=0; for(in..

    Time Conversion

    https://www.hackerrank.com/challenges/time-conversion/problem hh:mm:ssAM hh:mm:ssPM 의 12시간 형식으로 사용자가 입력하면 24시간 형식으로 변환해 출력하는 프로그램이다. 문자열 관련 함수를 사용하지 않은지 오래된 것 같아서 최대한 사용하려고 했다. strtok( 자를 문자열, 기준 문자 ): 문자열을 자르는 함수 >> >> 처음에만 자를 문자열의 이름을 넣어주고, 그 다음부터는 NULL을 넣어야 한다. (참고: https://dojang.io/mod/page/view.php?id=376 ) 문자열을 자르고 없애는 것이 아니라 문자열을 자르고 그 시작 부분의 주소값으로 포인터로 반환하는 것이다. strcpy( 복사한 문자열을 붙여넣을 문자..

    Sock Merchant

    [Algorithms > Implementation] https://www.hackerrank.com/challenges/sock-merchant/problem 배열의 크기(n)을 입력하고, 배열의 원소들을 입력한다. 배열들 중 같은 숫자들의 쌍의 개수 (2개씩)를 출력하는 문제 #include #include #include #include #include #include #include #include #include char* readline(); char** split_string(char*); // Complete the sockMerchant function below. int sockMerchant(int n, int ar_count, int* ar) { int pair=0; int a[n]..

    Maximum Element

    https://www.hackerrank.com/challenges/maximum-element/problem stack에서 1, 2, 3번 메뉴를 선택했을 때 각 메뉴에 맞는 명령을 실행하도록 하면 된다. 1번 - push 2번 - pop 3번 - stack의 components 중에서 가장 큰 값을 출력한다 #include #include #include #include int main() { long long i,j,n,x,index,arr[100001],maxs[100001],top; int menu; max = 0; top = -1; scanf("%lld",&n); for(i=0;i max){ max = x; } maxs[top] = max; } else if(menu == 2){ if(top!..

    Bon Appetit

    https://www.hackerrank.com/challenges/bon-appetit/problem Bon Appétit | HackerRank Determine whether or not Brian overcharged Anna for their split bill. www.hackerrank.com #include #include #include #include #include #include #include #include #include #include char* readline(); char* ltrim(char*); char* rtrim(char*); char** split_string(char*); // Complete the bonAppetit function below. void bo..

    Queue using Two Stacks

    [Data Strucutre/Queues/Medium] https://www.hackerrank.com/challenges/queue-using-two-stacks/problem Queue using Two Stacks | HackerRank Create a queue data structure using two stacks. www.hackerrank.com #include #include #include #include int main() { int count; scanf("%d", &count); int *n_queue = malloc(sizeof(int)*count); int *p_queue = malloc(sizeof(int)*count); int top=0, rear=-1, index=0; i..