CCF202012-1

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

问题描述
试题编号: 202012-1
试题名称: 期末预测之安全指数
时间限制: 1.0s
内存限制: 512.0MB
问题描述:
在这里插入图片描述

样例1输入
6
2 60
10 100
0 70
0 0
-10 50
10 60
Data
样例1输出
1220

样例2输入
2
-10 100
-1 15
Data
样例2输出
0
下面是通常解法:

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

int main(){
	   
	   
	 
	    int  n;//行数
        cin>>n;
        int score[n],w[n];
		for (int i = 0;i<n;i++){
			cin>>score[i]>>w[i];
		} 
		int res = 0;
        for(int j = 0;j<n;j++){
        	res += score[j] * w[j];//累乘
		}
        res = max(0,res); 
        cout<<res;
 


	return 0;
}

当然也可以使用结构体:

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

int main(){
      int n;
	   cin>>n;
       struct student{
       	int score;
       	int w;
	   }a[n];
	   for (int i = 0;i<n;i++){
			cin>>a[i].score>>a[i].w;
		} 
	    int res = 0;
        for(int j = 0;j<n;j++){
        	res += a[j].score * a[j].w;
		}
        res = max(0,res); 
        cout<<res; 
	return 0;
}

这两种方法计算方法一样,就是思考的方向不一样。】
注:#include<bits/stdc++.h>是c++通用库,有的编译测试会出错,但是ccf和Devc可以用。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值