咸鱼综合症 2019-01-22 18:13 采纳率: 0%
浏览 639

求助这串C++代码怎么改成python啊

#include
using namespace std;
int n, a[10000], l = 5000, r = 5000;
void make_tree(int now)
{
int x;
cin >> x;
if(x == -1)
return;
a[now] += x;
l = min(l, now);
r = max(r, now);
make_tree(now - 1);
make_tree(now + 1);
}
int main ()
{
make_tree(5000);
for (int i = l; i <= r; ++i)
cout << a[i] << " ";
}

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-01-22 23:54
    关注
    n=0
    a=[0]*[10000]
    l = [0]*5000
    r = [0]*5000
    def make_tree(now):
        x = int(input())
        if(x == -1):
            return
        a[now] = a[now] + x
        l = min(l, now)
        r = max(r, now)
        make_tree(now - 1)
        make_tree(now + 1)
    
    def main():
        make_tree(5000)
        for (i in range(r)):
            print(a[i])
    
    
    
    评论

报告相同问题?

悬赏问题

  • ¥20 随身WiFi移动网络访问不了
  • ¥50 RAD_XE11.3获取android11手机的IMEI码
  • ¥15 linux的gcc命令报错
  • ¥20 如何再GIS用海岸线建立缓冲区
  • ¥15 codeblock遇到问题了,求帮助😭
  • ¥15 Qt6.8.0加载网页MSVC2022
  • ¥15 360浏览器m2的这个值
  • ¥15 国内有哪些厂商做automlops的?
  • ¥15 skynet pb mysql
  • ¥15 笔记本外接显示器分辨率太低各种方法都用过了调不高