P1089 [NOIP2004 提高组] 津津的储蓄计划 题解

  • C++ 实现
// -*- coding: utf-8 -*-
//  @ Date   : 2020/5/20 13:14
//  @ Author : RichardLau_Cx
//  @ file   : Richard.cpp
//  @ IDE    : Dex-C++
//  @ Source : luogu

#include <cstdio>
#include <iostream>

using namespace std;

const int alimony = 300;  // 妈妈每个月打入的生活费 

int main() 
{
	int jj = 0;  // 津津手里的钱 
	int budget;  // 津津的预算 
	int mum = 0;  // 妈妈那里存的钱
//	int surplus;  // 剩余金额 
	 
	for (int i=1; i <= 12 ; i++)
	{
		jj += alimony;
		cin >> budget;
		
		jj -= budget;
		
//		cout << "jj: " << jj << endl;
		
		if (jj >= 100)
		{
			int remainder;  // 剩余几百 
			remainder = jj / 100; 
			
			// 整百存入妈妈那里 
			mum += remainder * 100;  
			jj -= remainder * 100;   
			
//			cout << "remainder: " << remainder << endl;
		} 
		 
		else if (jj < 0)
		{
			cout << "-" << i << endl;
			break; 
		}
		
		if (i == 12) 
		{
			jj = jj + mum / 10 * (10 + 2);
			cout << jj; 
		}
	}
	
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值