【例题 6-10 UVA

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

递归模拟就好。

【代码】

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e5;

int n,cnt;
map <int,int> dic;

void dfs(int x,int val){
    if (val==-1) return;
	dic[x]+=val;
	int temp;
	scanf("%d",&temp);
	dfs(x-1,temp);

	scanf("%d",&temp);
	dfs(x+1,temp);
}

int main(){
	//freopen("rush.txt","r",stdin);
	int kase = 0;
	while (~scanf("%d",&n) && n!=-1){
	    printf("Case %d:
",++kase);
		cnt = 1;
		dfs(1,n);	
		map<int,int>::iterator it;
		for (it = dic.begin();it != dic.end();it++){
			if ( (it)!=dic.begin()) putchar(' ');
			printf("%d",(*it).second);
		}	
		puts("");
		puts("");
		dic.clear();
	}
	return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/7703629.html