跳到正文

题解

题解:P15638 [ICPC 2022 Tehran R] Final Price

Night_Echo约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年3月6日
收录
2026年3月7日
更新
2026年11月13日
篇幅
约 1 分钟
题目
P15638

版本

  1. v1当前

思路

题目描述中只有最后一段有用。

我们仔细读题、观察样例,就可以发现本题要求我们求累加和。我们定义 ans 作为答案,每次输入 xx(观察时间段内的每日价格变化),把 ans 加上 xx,最后输出的 ans,就是答案了。

Code

C++
#include<bits/stdc++.h>
using namespace std;
int n;
int ans;
int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        ans+=x;
    }
    cout<<ans;
    return 0;
}
原文
存档评论1 条抓取于