#include <iostream> #include <vector> #include <queue> using namespace std; int getRoot(string& str) {     int re = 0;     int i = 0;     while(str[i] != ':')     {         re = re * 10 + (str[i]-'0');         i++;     }     return re; } int getLeft(string& str) {     int re = 0;     int i = 0;     while(str[i] != ':')     {         i++;     }     i++;     bool sign = true;     if(str[i] == '-')     {         sign = false;         i++;     }     while(str[i] != '|')     {         re = re * 10 + (str[i]-'0');         i++;     }     if(sign == false) re = (-1)*re;     return re; } int getRight(string& str) {     int re = 0;     int i = 0;     while(str[i] != '|')     {         i++;     }     i++;     bool sign = true;     if(str[i] == '-')     {         sign = false;         i++;     }     while(str[i] != '\0')     {         re = re * 10 + (str[i]-'0');         i++;     }     if(sign == false) re = (-1)*re;     return re; } void middle(int root, vector< vector<int> >& child, vector<int>& re) {      if(root == -1) return;      middle(child[root][0], child, re);      re.push_back(root);      middle(child[root][1], child, re); } int main() {     vector<int> parent(1023,-1);     vector< vector<int> > child(1023, vector<int>(2,-1));     vector<int> tree;     int ROOT;     cin>>ROOT;     tree.push_back(ROOT);     queue<int> que;     que.push(ROOT);     string str;     int left, right;     int root;     while(que.size()!=0)     {         cin>>str;         root = getRoot(str);         left = getLeft(str);         right = getRight(str);         if(left != -1)         {             parent[left] = root;             que.push(left);             tree.push_back(left);         }         if(right != -1)         {             parent[right] = root;             que.push(right);             tree.push_back(right);         }         child[root][0] =  left;         child[root][1] =  right;         que.pop();     }     vector<int> rere;     middle(ROOT, child, rere);     for(unsigned long i = 1; i < rere.size(); i++)     {         if(rere[i] < rere[i-1])         {             cout<<0<<endl;             return 0;         }     }     cout<<1<<endl;     return 0; }
点赞 评论

相关推荐

大厂的边缘业务去了也没啥用,也得不到任何成长,尤其是审核、中台这种价值产出不清楚的,别被大厂光环蒙蔽了双眼,如果你找实习工作,优先找"离钱近的业务",钱多的业务福利年终奖啥的都不会差的
陈100:呵呵。 你在大厂工作2年,后面准备好,可以随便跳很多公司。 去小厂,现在拿到所谓多的钱,有啥用啊,未来没有了。 而且应届生,工作没几年的,也不是赚钱的时间。
点赞 评论 收藏
分享
水墨不写bug:疑似没有上过大学
点赞 评论 收藏
分享
04-27 08:59
常州大学 Java
牛客139242382号:《两门以上汇编语言》
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务