题解:P15638 [ICPC 2022 Tehran R] Final Price
Night_Echo · · 题解
思路
题目描述中只有最后一段有用。
我们仔细读题、观察样例,就可以发现本题要求我们求累加和。我们定义 ans 作为答案,每次输入 ans 加上 ans,就是答案了。
Code
#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;
}