티스토리 뷰
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV141176AIwCFAYD
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
처음엔 트리를 만들어서 중위순회하는 방법을 생각했는지만 한번 그리면서 살펴보니 리프노드는 숫자를 이외 노드드은 연산자를 가지고 있어야만 성립하더라구요 이를 이용해 풀었습니다!
num == n일때 두가지로 나눈 이유는 왼쪽 자식만 있을때는 left만 둘 다 있을때는 left, right 둘 다 받아주기 위해서 입니다.(완전 이진 트리)
#include <iostream>
#define MAX 201
using namespace std;
int main(int argc, char** argv)
{
int test_case;
int T = 10;
for(test_case = 1; test_case <= T; ++test_case)
{
int n;
int num, left, right;
int ans = 1;
char content;
cin>> n;
for(int i=1; i<=n; i++) {
cin>>num;
if(num < n /2) {
cin>> content >> left>>right;
if(content != '+' && content != '-' && content != '*' && content != '/') {
ans = 0;
}
} else if(num == n/2 && n%2 == 1) {
cin>> content >> left>>right;
if(content != '+' && content != '-' && content != '*' && content != '/') {
ans = 0;
}
} else if(num == n/2 && n%2 == 0){
cin>> content >> left;
if(content != '+' && content != '-' && content != '*' && content != '/') {
ans = 0;
}
} else {
cin>> content;
if(content <'0' || content > '9') {
ans = 0;
}
}
}
cout << "#"<< test_case<<" "<< ans <<"\n";
}
return 0;//정상종료시 반드시 0을 리턴해야합니다.
}
'Algorithm' 카테고리의 다른 글
Algorithm) SWEA 10726 이진수표현 (0) | 2023.01.25 |
---|---|
Algorithm) SWEA 1288 새로운 불면증 치료법 c++ (0) | 2023.01.25 |
Algorithm) Programmers-경주로 건설 swift (0) | 2022.12.27 |
Algorithm) Programmers- 합승 택시 요금 swift (0) | 2022.12.23 |
Algorithm) 플로이드 와샬(Floyd Warshall) 알고리즘 (2) | 2022.12.23 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- programmres
- 3차원 농부
- UIKit
- ios
- 문자열 교집합
- 백준 20058
- 코딩테스트
- 알고리즘
- Algorithm
- C++
- 마법사 상어와 파이어스톰
- Xcode
- 8898
- 도둑질
- programmers
- 3000
- 입국심사
- 단속카메라
- swift
- swea
- 코테
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
글 보관함