728x90

개발 공부/알고리즘 16

HackerRank, C++, Bit Array

data type에 따른 값의 크기와, cycle을 어떻게 처리할지에 대해 고민 할 수 있는 문제 #include #include #include #include #include using namespace std; #include int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ unsigned int N,S,P,Q; cin >> N; cin >> S >> P >> Q; unsigned int bigNumber = pow(2,31); unsigned int a0 = S; unsigned long long a = a0; unsigned long long a1 = a0; unsigned int i = ..

HackerRank, C++, C++ Variadics

비트 연산과 파라미터 팩, variadics를 섞은 문제. variadics를 이해하는데 좀 시간이 들었고, 이후 파라미터 팩이 뭔지, 비트연산에 대해 공부하면서 많은 시간이 들은 문제 이다. 시간을 정해서 비트연산을 따로 정리해봐야 겠다.(문제를 풀면서) #include #include #include #include #include using namespace std; // Code Start ============================================== template int reversed_binary_value(){ int result = 0; bool ary[sizeof...(digits)] = { digits... }; for(int i = 0 ; i < sizeof(a..

HackerRank, C++, Class Template Specialization

class template specialization을 처음 써봤다. Template 변수로 설정해서 모든 타입에 대해서만 사용하는 것이 아니라, 내가 직접 특정 타입을 선택해서 사용 할 수 도 있다. 이때는 template를 써주긴 해야 한다. 예를들어 공통 된 template을 위에서 만들고, 특정 color와 fruit이라는 enum을 위한 특별한 template을 만들었다. #include using namespace std; enum class Fruit { apple, orange, pear }; enum class Color { red, green, orange }; template struct Traits; // Define specializations for the Traits class..

HackerRank, c++, Attending Workshops

greedy algorithm 문제, 이걸 모든 경우의 수를 계산해서 접근하는 방식으로 생각했으나, 말이 안되는 거라 생각했더니 greedy algorithm 이더라, 즉 workshop이 시작하는 시간으로 정렬(예외가 있음) workshop이 진행되는 시간이 가장 낮은 것으로 정렬(예외가 있음) workshop이 마무리 되는 시간으로 정렬.. #include using namespace std; #include //Define the structs Workshops and Available_Workshops. //Implement the functions initialize and CalculateMaxWorkshops struct Workshops{ int startTime; int endTime; ..

HackerRank, c++, Magic Spells

AquaVitae is not, and when you compare it with AruTaVae in your spell journal, you get a sequence: AuaVae => 이 라인때문에 당황함,, 결론은 dynamic_cast와 LCS(longgest common substring) 문제 였음;; 문제 이해 안되서 해답보고 이해한 문제;; void counterspell(Spell *spell) { /* Enter your code here */ Fireball* fireball; Frostbite* frostbite; Waterbolt* waterbolt; Thunderstorm* thunderstorm; Spell* spellPointer; if((fireball = dynam..

HackerRank, C++, Accessing Inherited Functions

간단한 소인수 분해 문제. 2,3,5의 횟수를 세면됨. class D : public A, public B, public C { int val; public: //Initially val is 1 D() { val = 1; } //Implement this function void update_val(int new_val) { while(new_val % 2 == 0) { A::func(val); new_val /= 2; } while(new_val % 3 == 0) { B::func(val); new_val /= 3; } while(new_val % 5 == 0) { C::func(val); new_val /= 5; } } //For Checking Purpose void check(int); //Do..

728x90