비트 AND연산 / std::toupper / std::tolower
·
공부/Code Cata
*초기 작성 코드더보기#include #include using namespace std;string ChangeString(string Target){ for(int i = 0; i = 'a' && Target[i] = 'A' && Target[i]  string::find 함수로 공백 문자 단위로 파싱하여 주어진 규칙에 맞게 문자열을 변환하는 함수를 거쳐 다시 solution함수에서 반환된 문자열을 합쳐주는 방식으로 작성하였다.다른 사람의 문제 풀이를 보고 내 코드를 봤는데 가독성이 좋지 않고, 반복문을 2번 돌아야되기에 속도도 느린 것을 확인했다.   *다른 사람 풀이 참고해서 다시 작성한 코드#include #include using namespace std;string solution(st..
24.12.27 (금)
·
내배캠/TIL
객체지향적으로 설계하는 것이 익숙치 않아서 연습이 많이 필요해 보인다..객체 지향 설계 연습: https://dong-grae.tistory.com/70   https://dong-grae.tistory.com/69 3진법 뒤집기*string을 사용한 초기 작성 코드더보기#include #include #include using namespace std;string Trit(int n){ string Result = ""; while(n != 0) { Result += to_string(n % 3); n /= 3; } return Result;}int solution(int n) { // 3진법으로 변환하dong-grae.tistory.com
객체 지향적 설계 연습
·
내배캠/C++
*자동차의 엔진을 인터페이스로 구현하여 결합도가 낮게 설계더보기더보기#include #include #include #include using namespace std;class Engine{public: virtual void Start() = 0; virtual ~Engine() { cout EngineRef;public: Car(unique_ptr engine) : EngineRef(move(engine)) {} void StartCar() { EngineRef->Start(); cout ()); FirstCar.StartCar(); } // SecondCar의 스코프를 제한 { Car SecondCar(make_unique()); SecondCar.StartCar(); } }클래스에 ..
3진법 뒤집기
·
공부/Code Cata
*string을 사용한 초기 작성 코드더보기#include #include #include using namespace std;string Trit(int n){ string Result = ""; while(n != 0) { Result += to_string(n % 3); n /= 3; } return Result;}int solution(int n) { // 3진법으로 변환하며 string에 뒤에 자리부터 저장 string R_Trit = Trit(n); int answer = 0; // 3진법으로 변환하고 뒤집힌 n을 다시 10진법으로 변환 int i = R_Trit.length() - 1; for..
24.12.26 (목)
·
내배캠/TIL
*초기 매개변수 실수한 코드더보기void QuickSort::SortAlgorithm(vector NumList, int Left, int Right){ if (Left NumList, int Left, int Right){ // 임의로 마지막 값을 Pivot으로 설정 int Pivot = NumList[Right]; int i = Left - 1; for (int j = Left; j Pivot) { ++i; swap(NumList[i], NumList[j]); } } } // (i + 1)은 Pivot의 최종 위치 swap(NumList[i + 1], NumList[Right]); // Pivot의 위치 인덱스 반환 return i + 1;}  사용자가 입력한 숫자들을 오름차..
std::rand / std::srand / std::time
·
내배캠/C++
#include #include using namespace std;int main(){ // 현재 시간을 시드 값으로 초기화 srand(time(0)); int RandomNumber[10]; // 0~4 까지의 숫자 중 랜덤으로 배열에 값 넣기 for (int i = 0; i std::rand()C 표준 라이브러리의 난수 생성 함수이다. 헤더에 정의되어 있다.std::srand에서 설정된 시드 값을 기반으로 난수를 생성함으로, std::srand를 먼저 호출해야만 매번 다른 난수를 생성할 수 있다.0부터 RAND_MAX(보통 32767) 사이의 정수를 반환한다. std::srand()std::rand와 마찬가지로 헤더에 정의되어 있다.난수 생성기를 초기화 하는 "시드(s..