1️⃣ 오늘 할 일

<aside>

2️⃣ 공부한 내용 정리

코드카타

<aside>

정수 → 문자열 변환(to_string)을 고려하는 경우


#include <iostream>
#include <string> //to_string, stoll ...
#include <algorithm>

int main() {
    long long n = 14275;
    std::string s = std::to_string(n); // "14275"
    
    // 각 자리 출력 or 각 자리수 합
    int sum = 0;
    for(char c : s){
        std::cout << c << " "; // 1 4 2 7 5
        sum += (c - '0'); // // '0' = 48 ASCII
    }
    
    //자리수 뒤집기 or 팰린드롬 검사
    std::string r = s;
    std::reverse(r.begin(), r.end()); // "57241"
    bool isPalindrome = (s == r); // false
		long long rev = std::stoll(r);    // 숫자로 다시 변환 가능 //string to long long
		
		
		std::string a = "100000000000000000000";
		std::string b = "99999999999999999999";

		// long long으로 표현할 수 있는 (약 9×10^18)을 넘어간 수끼리 비교
		if(a.length() > b.length()){
				std::cout << "a is bigger\n";
		}else if(a.length() < b.length()){
				std::cout << "b is bigger\n";
		}else if(a > b){ // 자리수 같으면 사전순 비교
				std::cout << "a is bigger\n";
		}else {
				std::cout << "b is bigger\n";
		}
		
		return 0;
}

<algorithm>


#include <string>
#include <vector>
#include <algorithm>

// std::sort 예시
// n번째 char로 오름차순 정렬하는데, 같으면 사전식 오름차순하는 sorting
// [capture] (parameter) -> return_type { body } 
// [capture] (parameter) { body } // 리턴타입은 컴파일러가 return 문을 보고 자동 추론

std::vector<std::string> solution(std::vector<std::string> strings, int n) {
    std::sort(
        strings.begin(),
        strings.end(),
        [&n](std::string a, std::string b) //바깥변수 n을 볼 수 있도록
        {
            if(a[n] == b[n]){
                return a < b; //bool 반환
            }
            return a[n] < b[n]; //bool 반환
        }
    );
    return strings;
}
// std::transform 예시
// [capture] (parameter) -> return_type { body } // 익명 함수
#include <string>
#include <vector>
#include <algorithm>
#include <cctype> //::toupper()

std::vector<int> src = {1, 2, 3, 4};
std::vector<int> dst(src.size()); //사이즈 미리 지정해주기

std::transform(
		src.begin(),
    src.end(),
    dst.begin(),
    [](int x) { return x * 2; }
);

//대문자 변환 안전 ver.
std::transform(
    s.begin(),
    s.end(),
    s.begin(),
    [](unsigned char c) //UB(Undefined Behavior) 방지용, 양수만 받기
    {
        return std::toupper(c); //int toupper(int ch); 이어서 UB 발생 가능
    }
);
// std::count_if 예시

// 'a' 이상 'e' 이하인 문자 개수
int cnt = std::count_if(s.begin(), s.end(),
    [](char c){ return c >= 'a' && c <= 'e'; });

<cmath>


C++

<aside>

**객체지향 프로그래밍 (**Object-Oriented Programming)


<aside>

</aside>

3️⃣ 오늘의 이슈와 해결 방법

<aside>

</aside>

4️⃣ 내일 할 일

<aside>

</aside>