zoukankan      html  css  js  c++  java
  • UVA 699 The Falling Leaves 数据结构

      题目链接: UVA

      题目描述: 递归方式输入叶子节点权值, 输出每一列的叶子节点的权值之和

      解题思路: 还是递归输入和上题差不多。

      代码: 

    #include <iostream>
    #include <queue>
    #include <string>
    #include <vector>
    #include <map>
    #include <algorithm>
    #include <list>
    #include <iterator>
    #include <cmath>
    #include <cstring>
    #include <forward_list>
    #include <sstream>
    using namespace std;
    
    const int maxn = 1e3+10;
    int sum[maxn];
    
    void build(int p) {
        int v;
        cin >> v;
        if(v == -1) return;
        sum[p] += v;
        build(p-1);
        build(p+1);
    }
    bool init() {
        int v;
        if((cin >> v)==EOF) return false;
        int pos = maxn >> 1;
        sum[pos] = v;
        build(pos-1);
        build(pos+1);    
        return true;
    }
    int main() {
        freopen("in.txt", "r", stdin);
        while(init()) {
            int p = 0;
            while(sum[p]==0) p++;
            while(sum[p]!=0) {
                cout << sum[p++] << " ";
            }
            cout << endl;
        }    
        return 0;
    }
    View Code

      思考: 很烦, 这道题写很烦, 这样吧, 一会儿再写写面试题

  • 相关阅读:
    状态同步和帧同步
    SVN和Git的使用
    客户端知识点
    客户端性能优化
    H5游戏开发面试经验
    2.0 pomelo-treasure官方demo的使用
    1.0 pomelo环境的搭建和部署
    python 网络编程
    冒泡排序
    面向对象-反射和元类
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/8027633.html
Copyright © 2011-2022 走看看