본문 바로가기

codewars3

Row of the odd triangle Given a triangle of consecutive odd numbers: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 ... find the triangle's row knowing its index (the rows are 1-indexed), e.g.: odd_row(1) == [1] odd_row(2) == [3, 5] odd_row(3) == [7, 9, 11] Note: your code should be optimized to handle big inputs. Solution #include std::vector odd_row(unsigned long long n) { std::vector vResult; unsigned long long c = n * (n-.. 2022. 2. 14.
Row Weights Scenario Several people are standing in a row divided into two teams. The first person goes into team 1, the second goes into team 2, the third goes into team 1, and so on. Task Given an array of positive integers (the weights of the people), return a new array/tuple of two integers, where the first one is the total weight of team 1, and the second one is the total weight of team 2. Notes Array .. 2021. 10. 13.
Simple multiplication This kata is about multiplying a given number by eight if it is an even number and by nine otherwise. Solution int simpleMultiplication(int a) { return a * (a % 2 == 0 ? 8 : 9); } 후기 아침에 출근해서 간단하게 하나 해결해봤다. 곱하기를 하는 함수인데, 짝수이면 8을 홀수이면 9를 곱하라고 한다. 나의 코드를 올리니 이미 많은 다른 사람들도 이렇게 짰더라.. 하나 고민인 것이 있는데 Google C++ Style Guide에서는 삼항 연산자를 사용하지 말라고 했었다. 하지만 편하게 사용할 수 있고, 한눈에 확 들어오는데 왜 사용하지 말하고 하는지 이유가 기억이 안 .. 2021. 10. 13.