40分代码求助大佬,找不到问题,跑了几次答案也没问题
查看原帖
40分代码求助大佬,找不到问题,跑了几次答案也没问题
1165047
Koishi514ww楼主2023/11/2 21:27
#include<stdio.h>
int main()
{
	int left =0, save = 0, cost, month = 1;
	for (month = 1; month <13; month++)
	{   left+=300;
		scanf("%d", &cost);
		if (cost > left)
		{
			printf("%d", -month);
			break;
		}
		else
			left -= cost;
        if(left>=300)
        {
            save+=300;
            left-=300;
        }
		else if (left >= 200)
		{
			save += 200;
			left = left - 200;
		}
		else if (left >= 100)
		{
			save += 100;
			left = left - 100;
		}
		else
			save += 0;
		
		if(month==12)
		printf("%d", save * (1 + 0.2) + left);
	}
	
	return 0;
}
2023/11/2 21:27
加载中...