char arr[2][2][3] = {
    'A','T','B','C','C','B','A','A','A','B','B','C'
};

int main()
{
    char c;
    cin >> c;

    for (int i = 0; i < sizeof(arr) / sizeof(char); ++i)
    {
        if (c == *((**arr) + i))
        {
            cout << "발견";
            return 0;
        }
    }

    cout << "미발견";
    return 0;
}

 


// idx번째 사람의 데이트 유무 결정 하는 함수
int cMax = 0;
char stack[10] = { 0 };
void Func(int idx)
{
    if (idx == cMax)
    {
        cout << stack << endl;
        return;
    }

    stack[idx] = 'x';
    Func(idx + 1);

    stack[idx] = 'o';
    Func(idx + 1);

    return;
}


int main()
{
    cin >> cMax;
    Func(0);

    return 0;
}

 


char buf[3][3][3] = { 0 };


int main()
{
    char c; cin >> c;

    for (int i = 0; i < 3; ++i)
    {
        for (int j = 0; j < sizeof(buf[0]); ++j)
        {
            *(buf[i][0] + j) = (c + i);
        }
    }

    for (int i = 0; i < 3; ++i)
    {
        for (int j = 0; j < 3; ++j)
        {
            for (int k = 0; k < 3; ++k)
            {
                cout << buf[i][j][k] << " ";
            }
            cout << endl;
        }
    }

    return 0;
}

 


int a, b;
int arr[3][2][3] = { 0 };

int main()
{
    cin >> a >> b;

    int flag = 0;
    for (int i = 0; i < (sizeof(arr) / sizeof(int)); ++i)
    {
        if (flag < 3)
        {
            arr[0][0][i] = a;
        }
        else
        {
            arr[0][0][i] = b;
        }

        ++flag;
        if (6 <= flag)
        {
            flag = 0;
        }
    }

    for (int i = 0; i < 3; ++i)
    {
        for (int j = 0; j < 2; ++j)
        {
            for (int k = 0; k < 3; ++k)
            {
                cout << arr[i][j][k] << " ";
            }
            cout << endl;
        }
    }

    return 0;
}

 


int map[3][6] = {
	3,5,4,2,2,3,
	1,3,3,3,4,2,
	5,4,4,2,3,5
};
char price[6] = "TPGKC";
char a, b;

int main()
{
	cin >> a >> b;
	int idx = map[a - 'A'][b - '1'];
	cout << price[idx - 1];

	return 0;
}

 


// [글자수][중복 글자수의 목록개수]
int DT[11][4] = { 0 };

int main()
{
	memset(DT, -1, sizeof(DT));

	char strings[4][11] = { 0 };
	int i = 0;
	for (char(&d)[11] : strings)
	{
		cin >> d;
		int length = strlen(d);

		int idx;
		for (idx = 0; DT[length][idx] != -1; ++idx);
		DT[length][idx] = i++;
	}

	for (int i = 0; i < 11; ++i)
	{
		for (int j = 0; j < 4; ++j)
		{
			if (DT[i][j] != -1) cout << strings[DT[i][j]] << endl;
		}
	}

	reuturn 0;
}

 


char arr[4][5][3] = {
	' ','#',' ',
	'#',' ','#',
	'#','#','#',
	'#',' ','#',
	'#',' ','#',

	'#','#','#',
	'#',' ','#',
	'#','#','#',
	'#',' ','#',
	'#','#','#',

	'#','#','#',
	'#',' ','#',
	'#',' ',' ',
	'#',' ','#',
	'#','#','#',

	'#','#',' ',
	'#',' ','#',
	'#',' ','#',
	'#',' ','#',
	'#','#',' '
};

int main()
{
	int a; cin >> a;

	for (int i = 0; i < 5; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			cout << arr[a][i][j];
		}
		cout << endl;
	}

	return 0;
}

'코딩 테스트 > 알고리즘 풀이' 카테고리의 다른 글

[LV7] 연습 문제  (0) 2025.04.29
[LV6] 복습 문제  (0) 2025.04.27
[LV6] 연습 문제  (0) 2025.04.26
[LV5] 훈련 문제  (0) 2025.04.21
[LV5] 연습 문제  (0) 2025.04.21

char path[10] = "";
char name[10] = "ABC";

void Recursive(int level)
{
	if (level == 2)
	{
		std::cout << path << endl;
		return;
	}

	for (size_t i = 0; i < 3; i++)
	{
		path[level] = name[i]; // 이 함수의 level
		Recursive(level + 1);
		path[level] = 0;
	} 
}

int main()
{
    Recursive(0);
    return 0;
}

 


int main()
{
	char strings[3][11];
	for (auto& d : strings)
	{
		cin >> d;
	}

	int cnt = 0;
	if (strcmp(strings[0], strings[1]) == 0) ++cnt;
	if (strcmp(strings[0], strings[2]) == 0) ++cnt;
	if (strcmp(strings[1], strings[2]) == 0) ++cnt;

	if (3 <= cnt) cout << "WOW";
	else if (2 <= cnt) cout << "GOOD";
	else if (cnt <= 0) cout << "BAD";

    return 0;
}

 


char path[10] = { 0 };
char name[10] = "BGTK";

int cMaxLevel = 0;

void Recursive(int level)
{
	if (level == cMaxLevel)
	{
		cout << path << endl;
		return;
	}

	for (int i = 0; i < 4; ++i)
	{
		path[level] = name[i]; 
		Recursive(level + 1);
	}
}

int main()
{
	cin >> cMaxLevel;

	Recursive(0);

    return 0;
}

 


 

char cmds[5][6] = { 0 };
int currentPos = 0;
int main()
{
	for (auto& d : cmds)
	{
		cin >> d;
		if (strcmp(d, "up") == 0) ++currentPos;
		if (strcmp(d, "down") == 0) --currentPos;
	}

	if (currentPos < 0)
	{
		currentPos *= -1;
		cout << "B";
	}
	else ++currentPos;

	cout << currentPos;
    return 0;
}

 


char path[10] = { 0 };
int n = 0;

void Recursive(int level)
{
	if (level == 4)
	{
		cout << path << endl;
		return;
	}

	for (int i = 1; i <= n; ++i)
	{
		path[level] = (i + '0');
		Recursive(level + 1);
	}
}

int main()
{
	cin >> n;
	Recursive(0);

    return 0;
}

 


string strs[4];
int main()
{
	int max = -1, min =  999;
	int maxIdx, minIdx;

	for (int i = 0; i <4; ++i)
	{
		cin >> strs[i];
		int length = strs[i].length();
		if (max < length)
		{
			max = length;
			maxIdx = i;
		}
		if (length < min)
		{
			min = length;
			minIdx = i;
		}
	}


	cout << "긴 문장 : " << maxIdx << endl;
	cout << "짧은 문장 : " << minIdx;


    return 0;
}

 


char toFind[4] = { 0 };

// 특정 경로를 찾는 함수
char path[4] = { 0 };
char pathName[5] = "ABCD";
int cnt = 0;
bool Recursive(int level)
{
    // BaseCase
    if (level == 3)
    {
        ++cnt;
        if (strcmp(toFind, path) == 0)
        {
            return true;
        }

        return false;
    }
    
    // Body
    for (int i = 0; i < 4; ++i)
    {
        path[level] = pathName[i];
        if (Recursive(level + 1) == true) return true;
    }

    return false;
}

int main()
{
    cin >> toFind;
    Recursive(0);
    cout << cnt;
    return 0;
}

 


int arr[3][2][2] = { 
    2,4,1,5,2,3,3,6,7,3,1,5
};

int main()
{
    int n; cin >> n;

    int max = -1;
    int min = 10;
    for (int i = 0; i < 2; ++i)
    {
        for (int j = 0; j < 2; ++j)
        {
            int t = arr[n][i][j];
            if (max < t) max = t;
            if (t < min) min = t;
        }
    }

    cout << "MAX = " << max << endl;
    cout << "MIN = " << min << endl;

    return 0;
}

 


char arr[5][10] = {
    "Jason",
    "Dr.tom",
    "EXEXI",
    "GK12P",
    "POW"
};

int main()
{
    char str[10];
    cin >> str;

    for (char(&d)[10] : arr)
    {
        if (strcmp(str, d) == 0)
        {
            cout << "암호해제";
            return 0;
        }
    }

    cout << "암호틀림";
    return 0;
}

'코딩 테스트 > 알고리즘 풀이' 카테고리의 다른 글

[LV7] 복습 문제  (0) 2025.05.02
[LV6] 복습 문제  (0) 2025.04.27
[LV6] 연습 문제  (0) 2025.04.26
[LV5] 훈련 문제  (0) 2025.04.21
[LV5] 연습 문제  (0) 2025.04.21

char cMap[4][3] =
{
	'D','T','K',
	'E','A','P',
	'C','Q','G',
	'P','H','B'
};


int main()
{
	int ay, ax;
	int by, bx;
	for (int y = 0; y < 4; ++y)
	{
		for (int x = 0; x < 4; ++x)
		{
			if (cMap[y][x] == 'A')
			{
				ay = y; ax = x;
			}
			if (cMap[y][x] == 'B')
			{
				by = y; bx = x;
			}
		}
	}
	
	int ry = 0;
	if (by < ay) ry = ay - by;
	else ry = by - ay;

	int rx = 0;
	if (bx < ax) rx = ax - bx;
	else rx = bx - ax;

	cout << ry + rx;

	return 0;
}

 


int cMap[3][4] =
{
	3,4,1,5,
	3,4,1,3,
	5,2,3,6
};
int sum[4] = { 0 };

int main()
{
	for (int y = 0; y < 3; ++y)
	{
		for (int x = 0; x < 4; ++x)
		{
			sum[x] += cMap[y][x];
		}
	}
	
	int index = 0;
	cin >> index;

	cout << sum[index];
	return 0;
}

 


char str[100] = { 0 };
char tokens[2] = { 0 };
int idxs[4] = { 0 };

int main()
{
	cin >> str;
	cin >> tokens[0] >> tokens[1];
	int len = strlen(str);

	int lastIdx = 0;
	for (int i = 0; str[i] != '\0'; ++i)
	{
		if (str[i] == tokens[0] || str[i] == tokens[1])
		{
			idxs[lastIdx++] = i - 1;
			idxs[lastIdx++] = i + 1;
		}
	}

	for (int i = 0; i < 4; ++i)
	{
		if (idxs[i] < 0 || len <= idxs[i]) continue;
		str[idxs[i]] = '#';
	}

	cout << str;

	return 0;
}

 


char str[4][3] = {0};

int main()
{
	for (auto d : str)
	{
		cin >> d;
	}
	
	for (int x = 0; x < 3; ++x)
	{
		// 역순으로 순회
		for (int y = 3; -1 < y; --y)
		{
			// a. 문자를 찾지 못함
			if (str[y][x] == '_') continue;

			// b. 문자를 찾음
			int lastY = 4;
			do{
				--lastY;
			} while (y <= lastY && str[lastY][x] != '_');

			if (lastY < y) continue;

			str[lastY][x] = str[y][x];
			str[y][x] = '_';
		}
	}
    
	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			cout << str[i][j];
		}
		cout << endl;
	}

	return 0;
}

 


int bucket[10] = { 0 };

int main()
{
	for (int i = 0; i < 8; ++i)
	{
		int t; cin >> t;
		++bucket[t];
	}

	for (int i = 0; i < 10; ++i)
	{
		for (int j = 0; j < bucket[i]; ++j)
		{
			cout << i << " ";
		}
	}

	return 0;
}

 


 

int arr[4][3] = {
	1,5,3,
	4,5,5,
	3,3,5,
	4,6,2
};

int main()
{
	int a, b;
	cin >> a >> b;

	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			if (a <= arr[i][j] && arr[i][j] <= b)
			{
				arr[i][j] = 0;
			}

			if (arr[i][j] == 0)
				cout << '#' << " ";
			else
				cout << arr[i][j] << " ";

		}
		cout << endl;
	}

	return 0;
}

 


 


struct S
{
	S() = default;
	S(char name, int y, int x)
		:Name(name), Y(y), X(x) {};

	char Name;
	int Y;
	int X;
};

// GLOBAL
S models[3];

char arr[5][3] = {
	'_','_','_',
	'_','_','_',
	'A','T','K',
	'_','_','_',
	'_','_','_',
};

bool DoCommand(char c, const char* str)
{
	// Find model what apply command
	S* target = nullptr;
	for (auto& d : models)
	{
		if (d.Name == c)
		{
			target = &d;
		}
	}

	// Apply command
	if (strcmp(str, "UP") == 0)
	{
		--(target->Y);
	}
	if (strcmp(str, "DOWN") == 0)
	{
		++(target->Y);
	}
	if (strcmp(str, "LEFT") == 0)
	{
		--(target->X);
	}
	if (strcmp(str, "RIGHT") == 0)
	{
		++(target->X);
	}

	return true;
}


int main() 
{
	// 1. Find modles
	int lastIdx = 0;
	for (int y = 0; y < 5; ++y)
	{
		for (int x = 0; x < 3; ++x)
		{
			if ('A' <= arr[y][x] && arr[y][x] <= 'Z')
			{
				models[lastIdx++] = S(arr[y][x], y, x);
				arr[y][x] = '_';
			}
		}
	}

	// 2. Apply command
	for (int i = 0; i < 7; ++i)
	{
		char target;
		char cmd[100] = { 0 };
		cin >> target >> cmd;

		DoCommand(target, cmd);
	}

	// 3. Replace modles
	for (int i = 0; i < 3; ++i)
	{
		arr[models[i].Y][models[i].X] = models[i].Name;
	}


	// Print
	for (int y = 0; y< 5; ++y)
	{
		for (int x = 0; x < 3; ++x)
		{
			cout << arr[y][x] << " ";
		}
		cout << endl;
	}

	return 0;
}

'코딩 테스트 > 알고리즘 풀이' 카테고리의 다른 글

[LV7] 복습 문제  (0) 2025.05.02
[LV7] 연습 문제  (0) 2025.04.29
[LV6] 연습 문제  (0) 2025.04.26
[LV5] 훈련 문제  (0) 2025.04.21
[LV5] 연습 문제  (0) 2025.04.21

void Func(int level)
{
	if (level == 2)
	{
		return;
	}

	for (int i = 0; i < 3; ++i)
	{
		Func(level + 1);
	}
}

int main()
{
	Func(0);

	return 0;
}

 


int main()
{
	char id[100] = { 0 };
	char ps[100] = { 0 };

	cin >> id >> ps;

	if (strcmp(id, ps) == 0)
	{
		cout << "LOGIN";
	}
	else
	{
		cout << "INVALID";
	}

	return 0;
}

 


int l, b;

void Func(int level)
{
	if (level == l)
	{
		return;
	}

	for (int i = 0; i < b; ++i)
	{
		Func(level + 1);
	}
}

int main()
{
	cin >> l >> b;
	Func(0);

	return 0;
}

 


int l;

void Func(int level)
{
	cout << level;
	if (level == l)
	{
		return;
	}

	Func(level + 1);
	Func(level + 1);
}

int main()
{
	cin >> l;
	Func(0);

	return 0;
}

 


int main()
{
	char strs[3][11];
	
	int max = 0, maxIdx = 0;
	int min = 0, minIdx = 0;

	for (int i = 0; i < 3; ++i)
	{
		cin >> strs[i];
		int t = strlen(strs[i]);

		if (max < t)
		{
			max = t;
			maxIdx = i;
		}
		if (t < min)
		{
			min = t;
			minIdx = i;
		}
	}

	// Swap
	char t[11] = { 0 };
	strcpy(t, strs[maxIdx]);
	strcpy(strs[maxIdx] , strs[minIdx]);
	strcpy(strs[minIdx], t);

	for (auto d : strs)
	{
		cout << d << endl;
	}

	return 0;
}

 


int b, l;
int cnt = 0;

void Func(int level)
{
	++cnt;

	if (level == l)
	{
		return;
	}
	for (int i = 0; i < b; ++i)
	{
		Func(level + 1);
	}

}

int main()
{
	cin >> b >> l;
	Func(0);

	cout << cnt;
	return 0;
}

 

 


 

void Func(int len)
{
	cout << len << " ";
	if (len == 1)
	{
		return;
	}
	
	Func(len - 1);
	cout << len << " ";

	return;
}

int main()
{
	char str[100];
	cin >> str;
	int len = strlen(str); // 널문자 제외 문자 개수 (0 <= i < len)

	Func(len);
	
	return 0;
}

 


int y = 5;
int x = 5;

void Func(const char* str)
{
	if (strcmp("up", str) == 0)
	{
		y--;
	}
	if (strcmp("down", str) == 0)
	{
		y++;
	}
	if (strcmp("left", str) == 0)
	{
		x--;
	}
	if (strcmp("right", str) == 0)
	{
		x++;
	}
	if (strcmp("click", str) == 0)
	{
		cout << y << "," << x << endl;
	}
}

int main()
{
	int n;
	cin >> n;
	
	for (int i = 0; i < n; ++i)
	{
		char cmd[100] = { 0 };
		cin >> cmd;
		Func(cmd);
	}

	return 0;
}

'코딩 테스트 > 알고리즘 풀이' 카테고리의 다른 글

[LV7] 연습 문제  (0) 2025.04.29
[LV6] 복습 문제  (0) 2025.04.27
[LV5] 훈련 문제  (0) 2025.04.21
[LV5] 연습 문제  (0) 2025.04.21
[LV4] 복습 문제  (1) 2025.04.21

void BBQ()
{
	BBQ();
}

int main()
{
	BBQ();
	return 0;
}

 


char str[11] = { 0 };

// 널 문자를 제외한 문자의 개수
int StrLen(const char* str)
{
	int i;
	for (i = 0; str[i] != '\0'; ++i);
	return i;
}

int main()
{
	cin >> str;
	int nullIdx = StrLen(str);

	// i : 0 ~ nullIdx - 1
	for (int i = 0; i < nullIdx; ++i)
	{
		for (int j = nullIdx - 1 - i; j < nullIdx; ++j)
		{
			cout << str[j];
		}
		cout << endl;
	}
	return 0;
}

 


char str[11] = { 0 };

// 널 문자를 제외한 문자의 개수
int StrLen(const char* str)
{
	int i;
	for (i = 0; str[i] != '\0'; ++i);
	return i;
}

int main()
{
	cin >> str;
	int charCnt = StrLen(str); // 문자의 개수

	// 문자열이 홀수일 경우
	if (charCnt % 2 == 1)
	{
		cout << "다른 문장";
		return 0;
	}

	// 문자열이 짝수일 경우
	int idxB = charCnt / 2;

	for (int i = 0; i < idxB; ++i)
	{
		if (str[i] != str[idxB + i])
		{
			cout << "다른 문장";
			return 0;
		}
	}

	cout << "동일한 문장";
	return 0;
}

 


int arr[2][4][4] = {0};

// 널 문자를 제외한 문자의 개수
int StrLen(const char* str)
{
	int i;
	for (i = 0; str[i] != '\0'; ++i);
	return i;
}

int main()
{
	// 1. Input
	for (int i = 0; i < 32; ++i)
	{
		cin >> *((**arr) + i);
	}

	// 2. Solve
	for (int i = 0; i < 16; ++i)
	{
		//arr[0]와 arr[1]의 각 원소 16개 비교
		if (*(*(arr[0]) + i) == *(*(arr[1]) + i))
		{
			cout << "걸리다";
			return 0;
		}
	}

	cout << "걸리지 않는다";
	return 0;
}

 


const int dist = 'Z' - 'A' + 1;

int main()
{
	char c; 
	cin >> c;

	for (int i = c - 3; i <= c + 3; ++i)
	{
		char temp = i;
		while (temp < 'A')
		{
			temp += dist;
		}
		while ('Z'< temp)
		{
			temp -= dist;
		}
		
		cout << temp;
	}

	return 0;
}

 


int arr[7] = { 0 };
const int eleCnt = 7;

int main()
{
	for (auto& d : arr)
	{
		cin >> d;
	}

	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 4 + i; ++j)
		{
			cout << arr[j] << " ";
		}
		cout << endl;
	}

	return 0;
}

 


// 널 문자를 제외한 문자의 개수
int StrLen(const char* str)
{
	int i;
	for (i = 0; str[i] != '\0'; ++i);
	return i;
}

char str[100] = { 0 };

int main()
{
	cin >> str;
	const int eleNum = StrLen(str);

	for (int i = 0; i < eleNum; ++i)
	{
		for (int j = 0; j <= 0 + i; ++j)
		{
			cout << str[j];
		}
		cout << endl;
	}

	return 0;
}

 


int A[4] = { 0 };
int B[4] = { 0 };
int Ret[8] = { 0 };

int main()
{
	for (auto& d : A)
		cin >> d;

	for (auto& d : B)
		cin >> d;

	int aIdx = 0;
	int bIdx = 0;

	for (int i = 0; i < 8; ++i)
	{
		// 1. A배열 끝났는지
		if (3 < aIdx)
		{
			Ret[i] = B[bIdx];
			++bIdx;
			continue;
		}
		// 2. B배열 끝났는지
		if (3 < bIdx)
		{
			Ret[i] = A[aIdx];
			++aIdx;
			continue;
		}

		// 3. A와 B 비교
		if (A[aIdx] < B[bIdx])
		{
			Ret[i] = A[aIdx];
			++aIdx;
		}
		else
		{
			Ret[i] = B[bIdx];
			++bIdx;
		}
	}

	for (auto& d : Ret)
		cout << d << " ";

	return 0;
}

 


int arr[4][5] = {
	3,5,4,2,5,
	3,3,3,2,1,
	3,2,6,7,8,
	9,1,1,3,2
};

int px = 0;
int py = 0;

int Sum(int _y, int _x)
{
	int ret = 0;

	for (int dy = 0; dy < py; ++dy)
	{
		for (int dx = 0; dx < px; ++dx)
		{
			const int ty = dy + _y;
			const int tx = dx + _x;

			if (ty < 0 || 4 <= ty || tx < 0 || 5 <= tx) continue;

			ret += arr[ty][tx];
		}
	}

	return ret;
}

int main()
{
	cin >> py >> px;

	int max = INT_MIN;
	int my = -1;
	int mx = -1;

	for (int i = 0; i < 5; ++i)
	{
		for (int j = 0; j < 5; ++j)
		{
			const int t = Sum(i, j);
			if (max < t)
			{
				max = t;
				my = i;
				mx = j;
			}
		}
	}

	cout << my << mx;
	return 0;
}

 


class Tower
{
public:

	Tower() = default;
	Tower(int height)
		:mHeight(height){}

	const int getHeight()
	{
		return mHeight;
	}

private:
	int mHeight = 0;
};

int main()
{
	Tower myTower;
	Tower seoulTower(100);
	cout << "높이는 " << myTower.getHeight() << "미터" << endl;
	cout << "높이는 " << seoulTower.getHeight() << "미터" << endl;
	return 0;
}

 


class Person
{
public:
    Person() = default;

    string getName() { return mName; }
    string getTel() { return mTel; }
    void set(string name, string tel) 
    {
        mName = name;
        mTel= tel;
    }

private:
    string mName;
    string mTel;
};

int main()
{
    Person arr[3];
    for (auto& d : arr)
    {
        string tn, tt;
        cin >> tn >> tt;
        d.set(tn, tt);

        cout << "이름 : " << d.getName() << " / 번호 : " << d.getTel() << endl;
    }

	return 0;
}

'코딩 테스트 > 알고리즘 풀이' 카테고리의 다른 글

[LV6] 복습 문제  (0) 2025.04.27
[LV6] 연습 문제  (0) 2025.04.26
[LV5] 연습 문제  (0) 2025.04.21
[LV4] 복습 문제  (1) 2025.04.21
[LV4] 연습 문제  (0) 2025.04.19

void BBQ(void)
{
	BBQ();
	return;
}

// cout -> 호출 -> cout
void Func(int i)
{
	cout << i << " ";
	if (i == 0) return;
	BBQ(i - 1);
	cout << i << " ";

	return;
}

int main()
{
	int n;
	cin >> n;
	Func(n);

	return 0;
}

 


 

const int arrSize = 6;
int arr[arrSize] = { 0 };

void MoonWalk(int idx)
{
	cout << arr[idx] << " ";
	if (idx == arrSize - 1) return;

	MoonWalk(idx + 1);
	cout << arr[idx] << " ";
	return;
}

int main()
{
	for (auto& d : arr)
	{
		cin >> d;
	}
	
	MoonWalk(0);
	return 0;
}

 


int cnt = 0;
int ABC(int a)
{
	if (cnt == 3) return a;
	++cnt;

	return ABC(a + 2);
}

int main()
{
	int a; cin >> a;
	
	cout << ABC(a);
	return 0;
}

 


const int arrSize = 5;
char str[arrSize] = { 0 };

// 출력 -> 호출 -> 출력
void Output(int idx)
{
	cout << str[idx];
	if (idx == arrSize - 1)
	{
		cout << endl;
		cout << str[idx];
		return;
	}

	Output(idx + 1);
	cout << str[idx];
}

int main()
{
	for (auto & d : str)
	{
		cin >> d;
	}

	Output(0);

	return 0;
}

 


int a, b;

// 출력 -> 호출 -> 출력
void Output(const int start, const int end)
{
	cout << start << " ";
	if (start == end) return;
	
	Output(start + 1, end);
	cout << start << " ";
}

int main()
{
	int a, b;
	cin >> a >> b;


	Output(a, b);

	return 0;
}

 


int arr[] = { 3,7,4,1,9,4,6,2 };

// idx부터 0까지 출력해주는 함수
// 출력 -> 호출 -> 출력
void Output(int idx)
{
	cout << arr[idx] <<" ";
	if (idx == 0)
	{
		return;
	}

	Output(idx - 1);
	cout << arr[idx] <<" ";

	return;
}

int main()
{
	int a; cin >> a;

	Output(a);

	return 0;
}

 


int arr[] = { 3,7,4,1,9,4,6,2 };

// i를 2로 나누어 전달
void Output(int i)
{
	//Base case
	if (i == 0)	return;

	Output(i / 2);
	cout << i <<" ";

	return;
}

int main()
{
	int a; cin >> a;

	Output(a);

	return 0;
}

 

'코딩 테스트 > 알고리즘 풀이' 카테고리의 다른 글

[LV6] 연습 문제  (0) 2025.04.26
[LV5] 훈련 문제  (0) 2025.04.21
[LV4] 복습 문제  (1) 2025.04.21
[LV4] 연습 문제  (0) 2025.04.19
[LV3] 복습 문제  (0) 2025.04.15

void BBQ(int* a, int* b)
{
	int min = INT_MAX;
	int max = INT_MIN;

	for (int i = 0; i <5; ++i)
	{
		int t; 
		cin >> t;

		if (t < min) min = t;
		if (max < t) max = t;
	}

	*a = max;
	*b = min;
}

int main()
{
	int a, b;
	BBQ(&a, &b);
	cout << "a = " << a << endl;
	cout << "b = " << b << endl;
	return 0;
}

 


int map[5][4] = { 0 };

struct CD
{
	CD() = default;
	CD(int ax, int ay)
	{
		x = ax;
		y = ay;
	}

	int x = 0;
	int y = 0;

	CD operator+(const CD& cd) const
	{
		CD ret;
		ret.x = this->x + cd.x;
		ret.y = this->y + cd.y;
		return ret;
	}
};

CD dir[8] =
{
	// x, y
	CD(-1,  0), // 좌
	CD(-1,-1), // 좌측 상단
	CD(0, -1), // 상
	CD(1, -1), // 우측 상단
	CD(1,  0), // 우
	CD(1,  1), // 우측 하단
	CD(0,  1), // 하
	CD(-1,  1) // 좌측 하단
};

bool Check(const CD& cd)
{
	for (const auto& d : dir)
	{
		CD t = cd + d;

		// 예외 처리
		if (t.x < 0 || 3 < t.x || t.y < 0 || 4 < t.y)
		{
			continue;
		}
		if (map[t.y][t.x] == 1)
		{
			return false;
		}
	}

	return true;
}

int main()
{
	for (int i = 0; i < 5; ++i)
	{
		for (int j = 0; j < 4; ++j)
		{
			cin >> map[i][j];
		}
	}

	for (int i = 0; i < 5; ++i)
	{
		for (int j = 0; j < 4; ++j)
		{
			if (map[i][j] == 1)
			{
				if (Check(CD(j, i)) == false)
				{
					cout << "불안정한 상태";
					return 0;
				}
			}
		}
	}

	cout << "안정된 상태";
	return 0;
}

 


 

int map[4][4] = { 0 };

int main()
{
	int input[4];
	for (int i = 0; i < 4; ++i)
	{
		cin >> input[i];
	}

	int cnt = 1;
	for (const auto& d: input)
	{
		*(*map + (d - 1)) = cnt++;
	}

	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 4; ++j)
		{
			std::cout << map[i][j];
		}
		std::cout << endl;
	}

	return 0;
}

 


int map[4][4] = { 0 };


struct Cmd
{
	friend::istream& operator>>(istream& in, Cmd& cmd)
	{
		in >> cmd.c >> cmd.i;
		return in;
	}

	char c;
	int i;
};

void Coloring(const Cmd& cmd)
{
	int x, y;
	int ax, ay;
	if (cmd.c == 'G')
	{
		x = 0;
		ax = 1;
		y = cmd.i;
		ay = 0;
	}
	else
	{
		x = cmd.i;
		ax = 0;
		y = 0;
		ay = 1;
	}

	for (int i = 0; i < 4; ++i)
	{
		map[y + (ay * i)][x + (ax * i)] = 1;
	}

	return;
}

int main()
{
	Cmd cmd[3];
	for (auto&d: cmd)
	{
		cin >> d;
		Coloring(d);
	}
	
	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 4; ++j)
		{
			cout << map[i][j];
		}
		cout << endl;
	}

	return 0;
}

 


int DAT[256] = { 0 };

struct sketchbook
{
	char image[3][3] = { 0 };

	friend::istream& operator>>(istream& in, sketchbook& sb)
	{
		for (int i = 0; i < 3; ++i)
		{
			for (int j = 0; j < 3; ++j)
			in >> sb.image[i][j];
		}
		return in;
	}

	void SetDat()
	{
		for (int i = 0; i < 9; ++i)
		{
			++(DAT[(*image)[i]]);
		}
	}
};

int main()
{
	sketchbook sb;
	cin >> sb;
	sb.SetDat();

	for (int i = 0; i < 256; ++i)
	{
		if (1 <= DAT[i])
		{
			cout << (char)i;
		}
	}

	return 0;
}

 


 

char map[3][4] = {
	'A','B','G','K',
	'T','T','A','B',
	'A','C','C','D'
};

char pattern[2][2] = { 0 };

bool Check(int y, int x)
{
	for (int my = 0; my < 2; ++my)
	{
		for (int mx = 0; mx < 2; ++mx)
		{
			if (map[my + y][mx + x] != pattern[my][mx])
			{
				return false;
			}
		}
	}
	return true;
}

int main()
{
	for (int i = 0; i < 4; ++i)
	{
		cin >> (*pattern)[i];
	}

	int cnt = 0;
	for (int y = 0; y <= 1; ++y)
	{
		for (int x = 0; x <= 2; ++x)
		{
			if (Check(y, x) == true)
			{
				++cnt;
			}
		}
	}

	if (cnt == 0)
	{
		cout << "미발견";
		return 0;
	}

	cout << "발견(" << cnt << "개)";
	return 0;
}

 


int map[3][3] = {
	3,5,1,
	3,8,1,
	1,1,5
};

int bitarray[2][2] = { 0 };

int Check(int y, int x)
{
	int ret = 0;
	for (int my = 0; my < 2; ++my)
	{
		for (int mx = 0; mx < 2; ++mx)
		{
			if (bitarray[my][mx] == 1)
			{
				ret += map[y + my][x + mx];
			}
		}
	}
	return ret;
}

int main()
{
	for (int i = 0; i < 4; ++i)
	{
		cin >> (*bitarray)[i];
	}

	int max = -1;
	int mx = -1;
	int my = -1;
	for (int y = 0; y <= 1; ++y)
	{
		for (int x = 0; x <= 1; ++x)
		{
			int temp = Check(y, x);
			if (max < temp)
			{
				max = temp;
				mx = x;
				my = y;
			}
		}
	}

	cout << "(" << my << "," << mx << ")";
	return 0;
}

 


class Account
{
public:
	Account(const char* str, int num, int amount)
		: mNum(num), mAmount(amount)
	{
		int strLen;
		for (strLen = 0; str[strLen] != '\0'; ++strLen);

		mOwner = new char[strLen + 1];
		for (int i = 0; i < strLen; ++i)
		{
			mOwner[i] = str[i];
		}
		mOwner[strLen] = '\0';
	}
	~Account()
	{
		delete[] mOwner;
	}

	// 입금
	void deposit(int amount)
	{
		mAmount += amount;
	}

	// 출금
	int withdraw(int amount)
	{
		mAmount -= amount;

		return mAmount;
	}

	// 현재 잔액 반환
	int inquiry()
	{
		return mAmount;
	}

	const char* getOwner()
	{
		return mOwner;
	}

private:
	char* mOwner = nullptr;
	int mNum = 0;
	int mAmount = 0;

};


int main()
{
	Account a("kitae", 1, 5000);
	a.deposit(50000);
	cout << a.getOwner() << "의 잔액은 " << a.inquiry() << endl;
	int money = a.withdraw(20000);
	cout << a.getOwner() << "의 잔액은 " << a.inquiry() << endl;

	return 0;
}

 


class CoffeeMachine
{
public:
	CoffeeMachine(int coffee, int water, int suger) noexcept
		:mCoffee(coffee), mWater(water), mSuger(suger), mMaxC(coffee),mMaxW(water),mMaxS(suger)
	{	};

	void DrinkEspresso()
	{
		cout << "에스프레소 마시기" << endl << endl;
		mCoffee -= 1;
		mWater -= 1;
		return;
	}
	void DrinkAmericano()
	{
		cout << "아메리카노 마시기" << endl << endl;
		mCoffee -= 1;
		mWater -= 2;
	}
	void DrinkSugerCoffee()
	{
		cout << "설탕 커피 마시기" << endl << endl;
		mCoffee -= 1;
		mWater -= 2;
		mSuger -= 1;
	}

	void Fill()
	{
		cout << endl << "재료 보충" << endl << endl;
		mCoffee = mMaxC;
		mWater = mMaxW;
		mSuger = mMaxS;
	}

	void Show()
	{
		cout << "남은 원두: " << mCoffee << endl;
		cout << "남은 물: " << mWater << endl;
		cout << "남은 설탕 : " << mSuger << endl << endl;
	}

private:
	int mCoffee;
	int mWater;
	int mSuger;

	int mMaxC;
	int mMaxW;
	int mMaxS;
};

int main()
{
	CoffeeMachine java(5, 10, 3);
	java.DrinkEspresso();
	java.Show();
	java.DrinkAmericano();
	java.Show();
	java.DrinkSugerCoffee();
	java.Show();
	java.Fill();
	java.Show();

	return 0;
}

'코딩 테스트 > 알고리즘 풀이' 카테고리의 다른 글

[LV5] 훈련 문제  (0) 2025.04.21
[LV5] 연습 문제  (0) 2025.04.21
[LV4] 연습 문제  (0) 2025.04.19
[LV3] 복습 문제  (0) 2025.04.15
[LV3] 연습 문제  (0) 2025.04.14

int map[3][3] =
{
	3,5,4,
	1,1,2,
	1,3,9
};

int dir[4][2] =
{
	// x, y
	-1, 0, // 좌
	0, -1, // 상
	1, 0, // 우
	0, 1 // 하
};

int sum(int y, int x)
{
	int ret = 0;

	for (int i = 0; i < 4; ++i)
	{
		int dx = x;
		int dy = y;

		dx += dir[i][0];
		dy += dir[i][1];

		if (dx < 0 || 2 < dx || dy < 0 || 2 < dy)
		{
			continue;
		}

		ret += map[dy][dx];
	}

	return ret;
}

int main()
{
	int x, y;
	cin >> x >> y;
	cout << sum(y, x);

	return 0;
}

 


struct Data
{
	Data() = default;
	Data(int x, int y, int z)
		:mx(x), my(y), mz(z) {}
	int mx, my, mz;
};

int main()
{
	Data a, b;

	cin >> a.mx >> a.my >> a.mz;
	cin >> b.mx >> b.my >> b.mz;

	cout << a.mx + b.mx << endl;
	cout << a.my + b.my << endl;
	cout << a.mz + b.mz << endl;
}

 


int StrLen(const char* str)
{
	int len = 0;
	while (str[len]!= '\0')
	{
		++len;
	}

	return len;
}

struct MC
{
	char bugger1[8] = { 0 };
	char bugger2[8] = { 0 };
};

int main()
{
	MC bob, tom;
	cin >> bob.bugger1 >> bob.bugger2;
	cin >> tom.bugger1 >> tom.bugger2;

	cout << "bob.buger1=" << StrLen(bob.bugger1)<<endl;
	cout << "bob.buger2=" << StrLen(bob.bugger2)<<endl;
	cout << "tom.buger1=" << StrLen(tom.bugger1)<<endl;
	cout << "tom.buger2=" << StrLen(tom.bugger2)<<endl;
}

 


int main()
{
	int G;
	cin >> G;

	int* P, * K;
	P = K = &G;

	int** T, ** Q;
	T = &P;
	Q = &K;

	cout << **T << " " << **Q;

	return 0;
}

 


int vect[4][3] = { 0 };

struct CD
{
	int x = 0;
	int y = 0;

	friend istream& operator>>(istream& in, CD& cd)
	{
		in >> cd.x >> cd.y;
		return in;
	}
};

int main()
{
	CD input[4];
	for (auto& d : input)
	{
		cin >> d;
		vect[d.x][d.y] = 5;
	}

	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			cout << vect[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

 


bool Compare(const char* a, const char* b)
{
	int i;
	for (i = 0; a[i] != '\0'; ++i)
	{
		if (a[i] != b[i])
		{
			return false;
		}
	}

	if (b[i] != '\0')
	{
		return false;
	}

	return true;
}

struct S
{
	S() = default;
	S(int win, const char* name)
		:mWin(win)
	{
		for (int i = 0; name[i] != '\0'; ++i)
		{
			mName[i] = name[i];
		};
	}; 

	int mWin = 0;
	char mName[100] = { 0 };

	bool operator==(const S& s)
	{
		return (this->mWin == s.mWin && Compare(this->mName, s.mName));
	}

	friend::istream& operator>>(istream& in, S& s)
	{
		in >> s.mWin >> s.mName;
		return in;
	};
};

int main()
{
	S train[7] =
	{
		S(15,"summer"),
		S(33,"cloe"),
		S(24,"summer"),
		S(28,"niki"),
		S(32,"jenny"),
		S(20,"summer"),
		S(40,"coco")
	};

	S tom;
	cin >> tom;

	for (int i = 0; i < 7; ++i)
	{
		if (train[i] == tom)
		{
			cout << i;
			return 0 ;
		}
	}
	return 0;
}

 


#include <iostream>
using namespace std;

int map[5][5] =
{
	3,3,5,3,1,
	2,2,4,2,6,
	4,9,2,3,4,
	1,1,1,1,1,
	3,3,5,9,2
};

int dir[4][2] =
{
	// x, y
	-1, -1, // 좌측상단
	-1, 1, // 좌측 하단
	1, -1, // 우측 상단
	1, 1 // 우측 하단
};

int sum(int y, int x)
{
	int ret = 0;

	
	for (int i = 0; i < 4; ++i)
	{
		// 4방향 합
		int dx = x;
		int dy = y;

		// 좌표 계산
		dx += dir[i][0];
		dy += dir[i][1];

		if (dx < 0 || 4 < dx || dy < 0 || 4 < dy)
		{
			continue;
		}

		ret += map[dy][dx];
	}

	return ret;
}

int main()
{
	int max = -1;
	int fx = -1;
	int fy = -1;
	for (int i = 0; i < 5; ++i)
	{
		for (int j = 0; j < 5; ++j)
		{
			int t = sum(i, j);
			if (max < t)
			{
				max = t;
				fx = j;
				fy = i;
			}
		}
	}

	cout << fy << " " << fx;
	return 0;
}

 


char map[4][5] = { 0 };

struct CD
{
	CD() = default;
	CD(int ax, int ay)
	{
		x = ax; 
		y = ay;
	}

	int x = 0;
	int y = 0;

	CD operator+(const CD& cd) const
	{
		CD ret;
		ret.x = this->x + cd.x;
		ret.y = this->y + cd.y;
		return ret;
	}
};

CD dir[8] =
{
	// x, y
	CD(-1,  0), // 좌
	CD(-1,- 1), // 좌측 상단
	CD( 0, -1), // 상
	CD( 1, -1), // 우측 상단
	CD( 1,  0), // 우
	CD( 1,  1), // 우측 하단
	CD( 0,  1), // 하
	CD(-1,  1) // 좌측 하단
};

void Boom(const CD& cd)
{
	for (const auto& d: dir)
	{

		CD t = cd + d;

		// 예외 처리
		if (t.x < 0 || 5 <= t.x || t.y < 0 || 4 <= t.y)
		{
			continue;
		}

		map[t.y][t.x] = '#';
	}

	return;
}

int main()
{
	memset(map, '-', sizeof(map));

	CD input[2];
	for (auto& d : input)
	{
		cin >> d.x >> d.y;
		Boom(d);
	}

	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 5; ++j)
		{
			cout << map[i][j] << " ";
		}
		cout << endl;
	}

	return 0;
}

 


int image[4][4] = { 0 };

int rectSum(int y, int x)
{
	int sum = 0;
	for (int i = 0; i < 2; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			sum += image[y + i][x + j];
		}
	}

	return sum;
}

int main()
{
	for (int i = 0; i < 4; ++i)
	{
		for (int j = 0; j < 4; ++j)
		{
			cin >> image[i][j];
		}
	}

	int max = -1;
	int my = -1;
	int mx = -1;
	for (int i = 0; i < 3; ++i)
	{
		for (int j = 0; j < 2; ++j)
		{
			int t = rectSum(i, j);
			if (max < t)
			{
				max = t;
				my = i;
				mx = j;
			}
		}
	}

	cout << "(" << my << "," << mx << ")";

	return 0;
}

 


// del : 토큰 이전까지의 문자를 저장
// clean : 토큰 이후의 문자를 저장
void Split(const char* data, const char token, char** del, char** clean)
{
	// 1. 토큰의 인덱스, 문자열 사이즈 구하기
	int tidx = 0;
	bool flag = false;
	int i;
	for (i = 0; data[i] != '\0'; ++i)
	{
		if (flag == false && data[i] == token)
		{
			tidx = i;
			flag = true;
		}
	}
	int size = i; // 문자의 개수(널문자 제외)

	// 2. del에 토큰 이전까지 문자 저장
	*del = new char(tidx + 1);
	for (int j = 0 ;j < tidx; ++j)
	{
		(*del)[j] = data[j];
	}
	(*del)[tidx] = '\0';


	// 3. clean에 토근 이후의 문자열 저장
	*clean = new char(size - tidx);
	for (int j = 0; j <= tidx; ++j)
	{
		(*clean)[j] = data[j + tidx + 1];
	}
	(*clean)[size - tidx] = '\0';

	return;
}

// 문자열을 정수로 변환하는 함수
int StoI(const char* str)
{
	int ret = 0;
	for (int i = 0; str[i] != '\0'; ++i)
	{
		ret *= 10;
		ret += str[i] - '0';
	}
	return ret;
}

class Date
{
public:

	Date() = default;
	Date(int y, int m, int d)
		:my(y), mm(m), md(d)
	{};
	Date(const char* str)
	{
		char* temp;
		char* py;
		char* pm;
		char* pd;
		Split(str, '/', &py, &temp);
		Split(temp, '/', &pm, &pd);

		my = StoI(py);
		mm = StoI(pm);
		md = StoI(pd);

		delete temp;
		delete py;
		delete pm;
		delete pd;
	}

	void show()
	{
		cout << my << "년" << mm << "월" << md << "일" << endl;
	}

	int getYear() { return my; };
	int getMonth() { return mm; };
	int getDay() { return md; };

private:
	int my = 0;
	int mm = 0;
	int md = 0;
};

int main()
{
	Date birth(2014, 3, 20);
	Date independenceDay("1945/8/15");
	independenceDay.show();
	cout << birth.getYear() << ',' << birth.getMonth() << ',' << birth.getDay() << endl;

	return 0;
}

'코딩 테스트 > 알고리즘 풀이' 카테고리의 다른 글

[LV5] 연습 문제  (0) 2025.04.21
[LV4] 복습 문제  (1) 2025.04.21
[LV3] 복습 문제  (0) 2025.04.15
[LV3] 연습 문제  (0) 2025.04.14
[LV1] 복습 문제  (0) 2025.04.13

+ Recent posts