落叶堆数落叶,这个是自己写了一个,然而不完善过不了,参考网上的,和自己写的很像,改了一些细节
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int s[90],d,sum,stopl,stopr;
void ds(int n)
{
cin>>d;
if(d==-1)
return;
if(n<stopl)
stopl=n;
if(n>stopr)
stopr=n;
s[n]=s[n]+d;
//printf("s[%d]=%d\n",n,s[n]);
ds(n-1);
ds(n+1);
return;
}
int main()
{
int t=0;
while(1)
{
t++;
memset(s,0,sizeof(s));
stopl=40;
stopr=40;
ds(40);
if(s[40]==0)
break;
printf("Case %d:\n",t);
for(int i=stopl;i<stopr;i++)
{
printf("%d ",s[i]);
}
cout<<s[stopr]<<endl;
cout<<endl;
}
return 0;
}