跳转至

202012-1 期末预测之安全指数

100% 数据——模拟

根据题目要求,我们求出 \(s=\sum\limits_{i=1}^{n}{score_i\cdot w_i}\) 后,输出 \(\max\{{s, 0}\}\) 即可。

代码实现
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n;
int w, s;
int ans;
int main() {
    scanf("%d", &n);
    ans = 0;
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d", &w, &s);
        ans += w * s;
    }
    printf("%d", max(ans, 0));
    return 0;
}
import java.util.Scanner;
public class csp2020121 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n, w, score, ans = 0;
        n = input.nextInt();
        for (int i = 1; i <= n; ++i) {
            w = input.nextInt();
            score = input.nextInt();
            ans += w * score;
        }
        if (ans < 0)
            ans = 0;
        System.out.print(ans);
        input.close();
    }
}
1
2
3
4
5
6
7
8
n = int(input())
ans = 0
for i in range(n):
    w, score = map(int, input().strip().split())
    ans += w * score
if ans < 0:
    ans = 0
print(ans)

评论