알고리즘/Codewars3 Codewars - [7 kyu] Reverse words Questions space 마다 단어를 반대로 만들어서 리턴해주는 문제이다. space의 개수 만큼 reverse words에도 추가해줘야 한다. Examples "This is an example!" ==> "sihT si na !elpmaxe" "double spaces" ==> "elbuod secaps" Solutions using namespace std; int checkEmptyCount(string str, int startIndex) { int count = 0; for(int i=startIndex; i 2022. 5. 3. Codewars - [5 kyu] Simple assembler interpreter Assembler로 들어온 문자열을 해석하여 실행하여 unordered_map로 구성된 저장된 값들을 반환하는 문제이다! MAIN #include #include Describe(SolutionTest) { It(Simple1) { std::vector program{ "mov a 5", "inc a", "dec a", "dec a", "jnz a -1", "inc a" }; std::unordered_map out{ { "a", 1 } }; Assert::That(assembler(program), Equals(out)); } }; ANSWER #include #include #include std::vector split(const std::string line) { std::vector splite.. 2022. 4. 29. Codewars - [6 kyu] Sum consecutives You are given a list/array which contains only integers (positive and negative). Your job is to sum only the numbers that are the same and consecutive. The result should be one list. Extra credit if you solve it in one line. You can assume there is never an empty list/array and there will always be an integer. Same meaning: 1 == 1 1 != -1 #Examples: [1,4,4,4,0,4,3,3,1] # should return [1,12,0,4,.. 2022. 1. 17. 이전 1 다음 300x250