本文主要是介绍uva 699,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题意:求同一垂直线的和,数组模拟,递归模拟这个过程
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 110;int a[MAXN];void dfs(int mid,int n,int *a)
{if ( n != -1){a[mid] += n ;scanf("%d",&n);dfs(mid-1,n,a);scanf("%d",&n);dfs(mid+1,n,a);}
}int main()
{int i,j,mid,cnt=1;int left,right,n;while (scanf("%d",&n) != EOF && n >= 0){memset(a,0,sizeof(a));mid = 50 ;dfs(mid,n,a);printf("Case %d:\n",cnt++);left = 0 ,right = MAXN;while (!a[left])left++;while (!a[right])right--;for ( i = left ; i <= right ; i++){printf("%d",a[i]);if (i != right)printf(" ");}printf("\n\n");}return 0;
}
这篇关于uva 699的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!