[NOIP2004 Improvement Team] Jinjin’s Savings Plan

Topic link

Title description
Jinjin's pocket money has always been managed by himself. At the beginning of each month, my mother gives 300,300 yuan to the allowance. The allowance will be budgeted for this month, and the actual expenses will always be the same as the budget.

In order for Jinjin to learn how to save, her mother proposed that Jinjin can deposit a whole hundred of money with her at any time, and she will add 20% to the allowance at the end of the year. Therefore, Jinjin formulated a savings plan: at the beginning of each month, after receiving pocket money from her mother, if she predicts that there will be more than 100 yuan or exactly 100 yuan in her hand by the end of the month, she will spend the whole hundred His money is kept with his mother, and the remaining money is in his own hands.

For example, at the beginning of November, Jinjin still had 83 yuan, and her mother gave Jinjin 300 yuan. Jinjin expects to spend 180 yuan in November, so she will deposit 200 yuan with her mother and keep 183 yuan for herself. By the end of November, Jinjin will have 3 yuan left.

Jinjin discovered that the main risk of this savings plan was that the money in his mother could not be withdrawn before the end of the year. It is possible that at the beginning of a certain month, Jinjin’s money plus the money given by her mother this month is not enough for this month’s original budget. If this happens, Tianjin Jin will have to save money and reduce budget this month.

Now, please judge whether this will happen according to the monthly budget from January to December 2004. If not, calculate how much money there will be in Jinjin's hands after the mother returns 20% of Jinjin's usual deposit by the end of 2004.

The input format is
12 lines of data, each line contains a non-negative integer less than 350, respectively representing the budget of Tianjin from November to December.

Output format
An integer. If there is not enough money in a certain month during the implementation of the savings plan, output −X, where X represents the first month when this happens; otherwise, how much money will be exported to Tianjin and Tianjin at the end of 2004.

Code:

//P1089 津津的储蓄计划
#include<iostream>
using namespace std;
int main()
{
    
    
	int sum = 0, count = 0, flag = 0, n;
	for(int i = 1; i <= 12; i++)
	{
    
    
		cin >> n;
		sum += 300 - n;
		while(sum >= 100)
		{
    
    
			sum -= 100;
			count++;
		}
		if(sum < 0)
		{
    
    
			cout << -i << endl;
			flag = 1;
			break;
		}
	}
	if(flag == 0) cout << count * 120 + sum << endl;
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_44826711/article/details/113746211