char input[] = { "#MIn#C#O##dE" };
int nullIdx = 12;

void Func(int idx)
{
    if (input[idx] == '#' || nullIdx <= idx)
        return;

    if ('A' <= input[idx] && input[idx] <= 'Z')
        cout << input[idx];

    Func(idx * 2);
    Func(idx * 2 + 1);
    return;
}

int main()
{
    Func(1);
    return 0;
}
 

 

char input[] = "RKFCBICM";
int mat[8][8] = {
    0, 1, 1, 1, 0, 0, 0, 0,
    0, 0, 0, 0, 1, 1, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 1, 1,
    0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0
};


void DFS(int idx)
{
    // Base case
    if (8 <= idx)
    {
        return;
    }

    cout << input[idx];

    // Recursive
    for (int i = 0; i < 8; ++i)
    {
        if (mat[idx][i] == 0)
            continue;

        DFS(i);
    }
    return;
}

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

 


 

char input[] = "ABCDEF";
struct Node
{
	char data;
	Node* left = nullptr;
	Node* right = nullptr;
};

void DFS(Node* n)
{
	if (n == nullptr)
	{
		return;
	}

	cout << n->data;

	DFS(n->left);
	DFS(n->right);
}

Node* head;

int main()
{
	head = new Node();
	head->left = new Node();
	head->left->left = new Node();
	head->left->right = new Node();
	head->right = new Node();
	head->right->left = new Node();
	
	queue<Node*> q;
	q.push(head);

	while (q.empty() == false)
	{
		Node* now = q.front();

		// 지금 노드에 입력받음
		cin >> now->data;

		// 큐에 다음 거 삽입
		if (now->left != nullptr)
			q.push(now->left);
		if (now->right != nullptr)
			q.push(now->right);

		// 앞에 삭제
		q.pop();
	}

	DFS(head);

    return 0;
}

 


 

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

int DFS(int idx, int lev, int ret)
{
    if (2 < lev)
        return 0;

    if (lev == 2)
        ret += input[idx];

    int temp1 = DFS(idx * 2, lev + 1, ret);
    int temp2 = DFS(idx * 2 + 1, lev + 1, ret);
    return temp1 + temp2 + ret;
}

int main()
{
    cout <<DFS(1, 0, 0);
    return 0;
}

 


int inputData[] = { 0,1,3,4,2,5 };
int input[6][6] = {
    0, 1, 0, 1, 1, 0,
    0, 0, 1, 0, 0, 1,
    0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0
};

int main()
{
    queue<int> q;
    q.push(0);

    while (q.empty() == false)
    {
        int now = q.front();

        if (inputData[now] % 2 == 1)
            cout << inputData[now];

        //삽입
        for (int i = 0; i < 6; ++i)
        {
            if (input[now][i] == 1)
                q.push(i);
        }

        q.pop();
    }
    return 0;
}

 


 

char tree[] = "ABCDE";
int treeEnd = 5;

char matrix[5][5] = {
    0,1,1,0,0,
    0,0,0,1,1,
    0,0,0,0,0,
    0,0,0,0,0,
    0,0,0,0,0,
};

void DFS(int idx)
{
    // Base case
    if (treeEnd <= idx)
        return;

    // Work step
    cout << tree[idx];

    // Recursive step
    for (int i = 0; i < treeEnd; ++i)
    {
        if (matrix[idx][i] == 0)
            continue;

        DFS(i);
    }
    return;
}

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

 


 

int input[] = { 0,1,2,3,0,0,4,5 };
int endIdx = 8;

int main()
{
    queue<int> q;

    q.push(1);

    while (q.empty() == false)
    {
        int now = q.front();

        cout << input[now] << " ";

        int left  = now * 2;
        int right = now * 2 + 1;

        if (left < endIdx && input[left] != 0)
            q.push(left);
        if (right < endIdx && input[right] != 0)
            q.push(right);

        q.pop();
    }

    return 0;
}

 


 

char DATA[] = "ABCDEFGHIJ";
int endIdx = 10;

int matrix[10][10] = {
    0,1,0,0,0,0,0,0,0,0,
    0,0,1,1,1,1,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,1,0,0,0,
    0,0,0,0,0,0,0,1,0,0,
    0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,1,0,
    0,0,0,0,0,0,0,0,0,1,
    0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0
};

int main()
{
    char input;
    cin >> input;
    queue<int> q;
    q.push(input - 'A');

    while (q.empty() == false)
    {
        int now = q.front();

        cout << DATA[now] << " ";

        for (int i = 0; i < endIdx; ++i)
        {
            if (matrix[now][i] == 0)
                continue;

            q.push(i);
        }

        q.pop();
    }

    return 0;
}

 


 

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

    int parent = 0;
    int child = 1;
    for (int i = 0; i < input; ++i)
    {
        // 자식 낳고 어른의 총원에 추가
        parent += child;
        // 자식 수 업데이트
        child *= 3;
    }

    cout << parent + child;
    return 0;
}

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

[LV18] 연습 문제  (0) 2025.06.08
[LV17] 복습 문제  (0) 2025.06.07
[LV16] 복습 문제  (0) 2025.06.02
[LV16] 연습 문제  (0) 2025.05.27
[LV15] 연습 문제  (0) 2025.05.24

+ Recent posts