-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRowWeights.cpp
More file actions
65 lines (50 loc) · 1.52 KB
/
RowWeights.cpp
File metadata and controls
65 lines (50 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<iostream>
#include<algorithm>
#include<vector>
#include <array>
#include<cmath>
#include <string>
#include <iostream>
#include <string>
using namespace std;
pair<int, int> rowWeights(const vector <int>& weights) {
int numberone = 0;
int numbertwo = 0;
for (int i = 0; i < weights.size(); i++)
{
if (i % 2 == 0) {
numberone += weights[i];
}
else {
numbertwo += weights[i];
}
}
pair<int, int>result;
result.first = numberone;
result.second = numbertwo;
return result;
}
int main()
{
rowWeights({});
return 0;
}
/*Description:
Scenario
Several people are standing in a row divided into two teams.
The first person goes into team 1, the second goes into team 2, the third goes into team 1, and so on.
Task
Given an array of positive integers (the weights of the people), return a new array/tuple of two integers, where the first one is the total weight of team 1, and the second one is the total weight of team 2.
Notes
Array size is at least 1.
All numbers will be positive.
Input >> Output Examples
rowWeights([13, 27, 49]) ==> return (62, 27)
Explanation:
The first element 62 is the total weight of team 1, and the second element 27 is the total weight of team 2.
rowWeights([50, 60, 70, 80]) ==> return (120, 140)
Explanation:
The first element 120 is the total weight of team 1, and the second element 140 is the total weight of team 2.
rowWeights([80]) ==> return (80, 0)
Explanation:
The first element 80 is the total weight of team 1, and the second element 0 is the total weight of team 2.*/