洛谷入门3-循环结构:津津的储蓄计划

题目:

 

 

 

 解题:

# include<iostream>

using namespace std;

int main()
{
    int money=0,cost,mother=0,flag=1;//手头的钱、这个月要花的钱、存在妈妈那的钱的张数、标记会不会省吃俭用
    for(int i=1;i<=12;i++)
    {
        money+=300;
        cin>>cost;
        money-=cost;
        if(money<0)
        {
            flag=0;
            cout<<-i;
            break;
        }
        if(money>=100)
        {
            mother+=money/100;
            money-=(money/100)*100;
        }
    }
    if(flag==1)
    {
        cout<<mother*120+money;
    }
    return 0;
}
View Code

 

posted @ 2020-09-14 15:57  inss!w!  阅读(188)  评论(0编辑  收藏  举报