250625

lililllilillll·2025년 6월 25일

개발 일지

목록 보기
213/350

✅ What I did today


  • LeetCode
  • DirectX 12를 이용한 3D 게임 프로그래밍 입문


⚔️ LeetCode


13. Roman to Integer

#include "13.h"

int Thirteen::romanToInt(std::string s)
{
	//int idx = 0;
	//int s_len = s.length();
	//int result = 0;
	//while (idx < s_len)
	//{
	//	char a = s[idx];
	//	char b = '_';
	//	if (idx+1 < s_len) b = s[idx + 1];

	//	if (a == 'I')
	//	{
	//		if (b == 'V') { result += 4; idx += 2; }
	//		else if (b == 'X') { result += 9; idx += 2; }
	//		else { result += 1; idx += 1; }
	//	}
	//	else if (a == 'V') { result += 5; idx += 1; }
	//	else if (a == 'X')
	//	{
	//		if (b == 'L') { result += 40; idx += 2; }
	//		else if (b == 'C') { result += 90; idx += 2; }
	//		else { result += 10; idx += 1; }
	//	}
	//	else if (a == 'L') { result += 50; idx += 1; }
	//	else if (a == 'C')
	//	{
	//		if (b == 'D') { result += 400; idx += 2; }
	//		else if (b == 'M') { result += 900; idx += 2; }
	//		else { result += 100; idx += 1; }
	//	}
	//	else if (a == 'D') { result += 500; idx += 1; }
	//	else if (a == 'M') { result += 1000; idx += 1; }
	//}
	//return result;

	int n = 0;   
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'I') {
            if (s[i+1]=='V' || s[i+1]=='X'){
                n-=1;
            }
            else {
                n+=1;
            }
        }
        else if (s[i]== 'V') {
            n+=5;
        }
        else if (s[i] == 'X') {
            if (s[i+1]=='L' || s[i+1]=='C'){
                n-=10;
            }
            else{
                n+=10;
            }
        }
        else if (s[i] == 'L') {
            n+=50;
        }
        else if (s[i] == 'C') {
            if(s[i+1]=='D' || s[i+1]=='M') {
                n-=100;
            }
            else{
                n+=100;
            }
        }
        else if (s[i] == 'D') {
            n+=500;
        }
        else if (s[i] == 'M') {
            n+=1000;
        }
    }
    return n;
}

굳이 예외 처리 하지 말고 뒤에 예외 조건이 있으면 한 번 빼주면 됐다.
근데 성능만 따지면 내 코드가 더 낫긴 함. 인덱스를 2씩 올라가서 불필요한 연산 안하니까.



📖 DirectX 12를 이용한 3D 게임 프로그래밍 입문


1h

Chapter 3 변환

3.1 선형 변환

비례 변환 : 각 성분에 곱한거
회전 변환

  • 기준축에 평행 성분 수직 성분 나눔 > 수직 성분이랑 평행 선분 외적한 걸로 수직 성분하고 같이 2차원 좌표계 생성 > 평행 성분은 돌릴 필요 없으니까 수직 성분만 2차원 좌표계 생성한 걸로 분해 > 그걸로 평행 성분 수직 성분 나눴던 식 전개 > 스칼라곱이 선형인 건 자명하고, 외적도 선형임. 고로 회전 변환은 선형임.
  • 회전행렬 각 행벡터는 단위 길이이고, 서로 직교함. 직교 행렬이므로 역행렬이 자신의 전치행렬과 같음.
profile
너 정말 **핵심**을 찔렀어

0개의 댓글