본문 바로가기

개발/코딩29

해커랭크(HackerRank) - Bon Appétit / C++ 문제 : 해커랭크 - Bon Appétit 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 난이도: Easy 언어 : C++ // Complete the bonAppetit function below. void bonAppetit(vector bill, int k, int b) { int annaToChargeSum = 0; int toRefund = 0; for(int i = 0 ;i 2020. 6. 26.
해커랭크(HackerRank) - Insert a Node at the Tail of a Linked List / C++ 문제 : 해커랭크 - Insert a Node at the Tail of a Linked List 난이도: Easy 언어 : C++ SinglyLinkedListNode* insertNodeAtTail(SinglyLinkedListNode* head, int data) { if(head == nullptr ) { head = new SinglyLinkedListNode(data); } else { SinglyLinkedListNode* node = head; while(node->next!= nullptr ) { node= node->next; } node->next = new SinglyLinkedListNode(data); } return head; } 2020. 2. 13.
해커랭크(HackerRank) - Left Rotation / C++ 문제 : 해커랭크 -Left Rotation 난이도: Easy 언어 : C++ int main() { string nd_temp; getline(cin, nd_temp); vector nd = split_string(nd_temp); int n = stoi(nd[0]); int d = stoi(nd[1]); string a_temp_temp; getline(cin, a_temp_temp); vector a_temp = split_string(a_temp_temp); vector a(n); vector r(n); for (int i = 0; i < n; i++) { int a_item = stoi(a_temp[i]); a[i] = a_item; int idx = (n-d +i)%n; r[idx] = a[i.. 2020. 2. 11.
해커랭크(HackerRank) - 2D Array - DS / C++ 문제 : 해커랭크 - 2D Array - DS 난이도: Easy 언어 : C++ int hourglassSum(vector arr) { set sum; for(int i = 0;i 2020. 2. 11.
해커랭크(HackerRank) - Weighted Uniform Strings / C++ 문제 : 해커랭크 - Weighted Uniform Strings 난이도: Easy 언어 : C+ // Complete the weightedUniformStrings function below. vector weightedUniformStrings(string s, vector queries) { vector result; map weight; char prev = 0; int prevWeight = 0; for(int i = 0 ;i 2020. 2. 6.
해커랭크(HackerRank) - Day of the Programmer / C++ 문제 : 해커랭크 - Migratory BirdsDay of the Programmer 난이도: Easy 언어 : C++ // Complete the dayOfProgrammer function below. string dayOfProgrammer(int year) { string day; if(year == 1918) return day="26.09."+ to_string (year); if ((year < 1918 && year % 4 == 0) || (year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { day="12.09."+ to_string (year); }else { day="13.09."+ to_string (year); } return day.. 2020. 2. 5.
해커랭크(HackerRank) - Migratory Birds / C++ 문제 : 해커랭크 - Migratory Birds 난이도: Easy 언어 : C++ // Complete the migratoryBirds function below. int migratoryBirds(vector arr) { int type[6] = {0,}; for(int i = 0 ;i 2020. 2. 4.
해커랭크(HackerRank) - Mini-Max Sum / C++ 문제 : 해커랭크 - Mini-Max Sum 난이도: Easy 언어 : C++ // Complete the miniMaxSum function below. void miniMaxSum(vector arr) { unsigned long totalSum = 0; unsigned long minSum = 0; unsigned long maxSum = 0; for(int i = 0 ;i 2020. 2. 4.
해커랭크(HackerRank) - Divisible Sum Pairs / C++ 문제 : 해커랭크 - Divisible Sum Pairs 난이도: Easy 언어 : C++ // Complete the divisibleSumPairs function below. int divisibleSumPairs(int n, int k, vector ar) { int cnt = 0; for(int i = 0; i< n-1 ; i++) { for(int j=i+1;j 2020. 2. 3.