E D R S I H C RSS
ID
Password
Join
Your aims are high, and you are capable of much.

FrontPage 사다리타기

//============================================================================
// Name        : Ladder.cpp
// Author      : chobocho
// Version     :
// Copyright   : chobocho at com
// Description : Ladder
// Date        : 2010. 12. 26
//============================================================================

#include <iostream>
#include <queue>
using namespace std;

/* Example

 1   2   3
 |   |   |
 +---+   |   10
 |   |   |
 |   +---+   20
 |   |   |
 +---+   |   30
 |   |   |
 |   |   |
 A   B   C


 (1, 2, 10) => (1, 10)
 (2, 3, 20) => (2, 20)
 (1, 2, 30) => (1, 30)

*/

int main() {

    priority_queue<int, deque<int> > ladder;

    int node[3] = {
        10 << 8 | 1,  /* (1, 2, 10) => (1, 10) => (10 << 8 | 1) */
        20 << 8 | 2,  /* (2, 3, 20) => (2, 20) */
        30 << 8 | 1   /* (1, 2, 30) => (1, 30) */
    };
    int temp_node;

    char result[3] = { 'A', 'B', 'C' };
    char temp_char;

    for (int i = 0; i < 3; i++)
    {
    	ladder.push(node[i]);
    }

    for (int i = 0; i < 3; i++)
    {
    	temp_node = (ladder.top() & 0xF) - 1;
        ladder.pop();

        temp_char = result[ temp_node ];
        result [ temp_node ] = result [ temp_node + 1];
        result [ temp_node + 1 ] = temp_char;
    }

    cout << "================================" << endl;
    cout << result[0] << " " << result[1] << " " << result[2] << endl;
    cout << "================================" << endl;

    return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2010-12-26 19:12:40
Processing time 0.0231 sec