알고리즘 연습
[SWEA 중위순회] 입력 버리기 , getline(cin,str) , getc(stdin)
_h.j
2024. 7. 25. 10:49
728x90
#include<iostream>
#include <string>
#include <cstring>
using namespace std;
int N;
char tree[102];
void inorder(int id) {
if (!tree[id] || id > N)
return;
inorder(id * 2);
cout << tree[id];
inorder(id * 2 + 1);
}
int main(int argc, char** argv)
{
int T = 10;
//cin >> T;
for (int test_case = 1; test_case <= T; ++test_case)
{
memset(tree, 0, sizeof(tree));
cin >> N;
for (int i = 1; i <= N;i++) {
int id; char c;
cin >> id >> c;
tree[id] = c;
//방법1
string str;
getline(cin, str);
// 방법2
// int tmp;
//while (getc(stdin) == ' ')
// cin >> tmp;
}
cout << "#" << test_case << " ";
inorder(1);
cout << "\n";
}
return 0;
}
728x90