本文主要是介绍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可以用。
这篇关于CCF202012-1的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!