Creditors have much better memories than debtors.
FrontPage › 사다리타기
Difference between r1.1 and the current
@@ -12,6 +12,7 @@
using namespace std;/* Example
| | |
+---+ | 10
@@ -32,16 +33,16 @@
int main() {
priority_queue<int, deque<int> > ladder;
};
int temp_node;
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++)
@@ -59,9 +60,9 @@
result [ temp_node + 1 ] = temp_char;}
cout << "================================" << endl;
cout << result[0] << " " << result[1] << " " << result[2] << endl;
cout << "================================" << endl;
return 0;
}}}}//============================================================================ // 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; }