Learn C++ from a young age! Record the questions in the learning process of Xueersi Monkey programming and record every moment. Any infringement will be deleted immediately, thank you for your support!
Attached is a summary post: Little Monkey Programming C++ | Summary-CSDN Blog
[Title description]
In a blink of an eye, the little monkey has gone to college. He now faces grade point anxiety. In a class that Xiaohou chose this semester, the students were all scrambling to get homework points. Xiaohou and his classmate Xiaomei always say that each other is a paper monster. Now please figure out who has a higher homework score.
There are n homeworks in this class . The full score of the i- th homework is ai . The monkey got bi % of the full score of the homework in the i- th homework . Xiaomei got ci of the full score of the homework in the i- th homework. %.
Please judge who is the one with the higher homework score.
【enter】
The first line contains an integer n , indicating the number of jobs.
The second line contains n positive integers a 1, a 2,⋯, an , indicating the total score of each assignment.
The third line contains n integers b 1, b 2,⋯, bn , indicating the monkey’s score rate for each assignment.
The fourth line contains n integers c 1, c 2,⋯, cn , indicating Xiaomei’s score rate for each assignment.
【Output】
In one line, if the monkey's score is higher, H is output ; if Xiaomei's score is higher, M is output ; if the two have the same score, Same is output .
【Input sample】
5
10 10 10 10 20
80 80 80 80 80
100 100 100 100 50
【Output sample】
M
[Detailed code explanation]
#include <bits/stdc++.h>
using namespace std;
int a[10005]={0}, b[10005]={0}, c[10005]={0};
int n, ans1=0, ans2=0;
int main()
{
cin >> n;
for (int i=1; i<=n; i++) {
cin >> a[i];
}
for (int i=1; i<=n; i++) {
cin >> b[i];
ans1 += b[i]*a[i];
}
for (int i=1; i<=n; i++) {
cin >> c[i];
ans2 += c[i]*a[i];
}
if (ans1>ans2) cout << "H";
else if (ans1<ans2) cout << "M";
else cout << "Same";
return 0;
}
【operation result】
5
10 10 10 10 20
80 80 80 80 80
100 100 100 100 50
M