Trees on the level
Even more(,)()
This kind of thing !!!
# Include <cstdio> # include <cstring> # include <cctype> const int maxn = 256 + 1; char s [maxn]; struct node {int val; bool have; node * left, * right; node (int v = 0, node * l = NULL, node * r = NULL): Val (V), left (L ), right (r) {have = false ;}} * root, * Q [maxn]; int front = 0, rear = 0; void printans (node * root, int OK) {If (OK = 0) {printf ("not complete \ n"); return;} front = rear = 0; Q [rear ++] = root; while (front <rear) {node * u = Q [Front + +]; If (u-> have = false) {OK = 0; break;} If (u-> left! = NULL) Q [rear ++] = u-> left; If (u-> right! = NULL) Q [rear ++] = u-> right;} If (OK = 0) {printf ("not complete \ n"); return ;} front = 0; printf ("% d", Q [Front ++]-> Val); While (front <rear) printf ("% d ", Q [Front ++]-> Val); printf ("\ n");} node * newnode () {return new node (0, null, null );} void insert (INT Val, char s [], Int & OK) {node * u = root; int M = strlen (s); For (INT I = 0; I <m; I ++) {If (s [I] = 'l') {If (u-> left = NULL) u-> left = newnode (); U = u-> left;} If (s [I] = 'R '){ If (u-> right = NULL) U-> right = newnode (); U = u-> right;} If (u-> have = true) OK = 0; else {u-> val = val; U-> have = true;} return;} void del (node * u) {If (u-> left! = NULL) del (u-> left); If (u-> right! = NULL) del (u-> right); Delete U;} int main () {int OK = 1, val = 0; root = newnode (); while (scanf ("% s", S) = 1) {If (! Strcmp (S, "()") {printans (root, OK); OK = 1; del (Root); root = newnode (); memset (S, 0, sizeof (s); memset (Q, 0, sizeof (q);} else {If (! Isdigit (s [1]) OK = 0; else sscanf (S + 1, "% d", & Val); int Pos = strchr (S ,',') -S + 1; insert (Val, S + POs, OK) ;}} return 0 ;}
October 30, 2018 was a very unfortunate day.
On this day, I finally dropped this question a and submitted it more than 10 times. Today, I understand why it is wrong:
The output format of the vulnerability !!! There must be an empty line at the end of the output file !!!
Trees on the level