-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day28.cpp
68 lines (55 loc) · 1.48 KB
/
Day28.cpp
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
66
67
68
// Pair and Tuple
// https://www.interviewbit.com/problems/pair-and-tuple/
/*
#include <iostream>
#include <vector>
#include<tuple>
using namespace std;
*/
pair<int, int> findMaxMin(vector<int> &A) {
// First value of pair will be Maximum of array A and second will be Minimum of array A
int Max = A[0];
int Min = A[0];
for(int i = 0; i < A.size(); i++) {
if(Max < A[i]) {
Max = A[i];
}
if(Min > A[i]) {
Min = A[i];
}
}
pair<int,int> ans(Max, Min);
return ans;
}
tuple<int, int, int> compute(vector<int> &A){
// First value of tuple will be sum of array A
// Second value of tuple will be sum of even values in array A
// Third value of tuple will be sum of odd values in array A
int sum1 = 0, sum2 = 0, sum3 = 0;
for(int i = 0; i < A.size(); i++) {
sum1 += A[i];
}
for(int i = 0; i < A.size(); i++) {
if(A[i] % 2 == 0) {
sum2 += A[i];
}
}
sum3 = sum1 - sum2;
tuple<int,int,int> ans(sum1, sum2, sum3);
return ans;
}
/*
int main() {
int n;
cin>>n;
vector<int> A(n);
for(int i = 0; i < n; i++){
cin>>A[i];
}
pair<int, int> max_min = findMaxMin(A);
cout<<max_min.first<<" "<<max_min.second<<endl;
tuple<int, int, int> tuple_values = compute(A);
cout<< get<0>(tuple_values) << " " << get<1>(tuple_values) << " " << get<2>(tuple_values) << endl;
return 0;
}
*/