#include <stdio.h>
#include <stdlib.h>
#define M 300 //定义每月固定的零用钱
int main()
{
int i, a, d, c, saving = 0, balance = 0, N = 12, b[20];
i = 1;
while( N-- ) //输入12个月的预算
{
scanf("%d", &a);
b[i] = a;
i++;
}
for(i=1, N=12; i<=N; i++) //对12个月的每个月分别分析
{
balance+= M - b[i]; //结余
d = 4;
while ( d-- ) //判断有多少钱可以用来存储
{
if(balance >= 100)
{
saving+= 100; //用来存储
balance-=100; //预算用来消费
}
}
if( balance < 0 ) //如果预算不足
{
printf("-%d\n", i);
break;
}
if ( i==N && balance>=0 ) //到年底每月预算充足,所得储蓄资产
{
c = saving * 1.2 + balance;
printf("%d\n", c);
}
}
return 0;
}
原文:https://www.cnblogs.com/Tristan-Adams/p/9606544.html