B. Maximums

冬令营第一天

B. Maximums

题目链接
题意
输入一组数据,根据题干要求转化成输出
Alicia has an array, a1,a2,…,an, of non-negative integers. For each 1≤i≤n, she has found a non-negative integer xi=max(0,a1,…,ai−1). Note that for i=1, xi=0.

For example, if Alicia had the array a={0,1,2,0,3}, then x={0,0,1,2,2}.

Then, she calculated an array, b1,b2,…,bn: bi=ai−xi.

For example, if Alicia had the array a={0,1,2,0,3}, b={0−0,1−0,2−1,0−2,3−2}={0,1,1,−2,1}.

Alicia gives you the values b1,b2,…,bn and asks you to restore the values a1,a2,…,an. Can you help her solve the problem?

分析
所求方法由b反推a,根据题干要求可以把它分成三个部分,a—输入单个数字、x–前b i-1 数中最大数、b–输出数字。b=a+x,每输入一个数字,关键求出x,求b。
代码

#include"bits/stdc++.h"
using namespace std;

int main(){
	int n,a,x=0,b;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
		b=a+x;
		cout<<b<<" ";
		if(a>0){
			x+=a;
		}
	}
	return 0;
}

今日小结

今天是冬令营开始的第一天,紧跟课程进度。20级讲的是内存,19级先讲的是STL和前一天要求做的题,个人感觉对于我来说题目有点难,不过也是收获满满。明天再接再厉。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值