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可以用。