@[Twistedmind](/user/1045579)
首先
```cpp
int cost[12]
```
是
```cpp
cost[0]~cost[11]
```
其次
```cpp
int rest;
int Savemny;
```
最好是
```cpp
int rest=0;
int Savemny=0;
```
by ge_zhe @ 2023-07-26 21:56:42
@[ge_zhe](/user/724440) 谢谢指正,就结果来说不影响吧qaq
by Twistedmind @ 2023-07-26 23:40:21
@[Twistedmind](/user/1045579) 改完能过
by ge_zhe @ 2023-07-27 12:03:04
@[Twistedmind](/user/1045579)
[通过记录](https://www.luogu.com.cn/record/117598093)
```cpp
#include <stdio.h>
#include <math.h>
int main()
{
int cost[13];
for(int i=1;i<=12;i++)
{
scanf("%d",&cost[i]);
}
int month; //钱不够的月
int rest=0;//每个月扣掉生活费剩下的
int Flag=0;//标志
int Savemny=0;//存的钱
int flag;
for(int i=1;i<=12;i++)
{
rest = rest + 300 - cost[i];
flag = rest / 100;
//printf("%d %d %d\n",rest,Savemny,flag);
if(rest<0)
{
month = i;
Flag = 1;
//printf("%d\n",rest);
break;
}
if(flag>0)
{
Savemny +=( flag * 100 );
rest = rest - (flag * 100);
}
}
if(Flag == 1)
{
printf("%d\n",-month);
}
else printf("%d\n",Savemny*6/5+rest);
return 0;
}
```
在程序函数内定义的局部变量初值不一定是0,
是一个随机数,定义时赋值是好习惯
by ge_zhe @ 2023-07-27 12:06:32
@[ge_zhe](/user/724440) 谢谢佬!!!明白了!!
by Twistedmind @ 2023-07-27 12:32:52