-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path12_Question.cpp
More file actions
115 lines (73 loc) · 2.67 KB
/
12_Question.cpp
File metadata and controls
115 lines (73 loc) · 2.67 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Problem Statement
// Particulate matters are the biggest contributors to Delhi pollution. The main reason behind the increase in the
// concentration of PMs include vehicle emission by applying Odd Even concept for all types of vehicles.
// The vehicles with the odd last digit in the registration number will be allowed on roads on odd dates and those
// with even last digit will on even dates.
// Given an integer array a[], contains the last digit of the registration number of N vehicles traveling on
// date D(a positive integer). The task is to calculate the total fine collected by the traffic police department
// from the vehicles violating the rules.
// Note : For violating the rule, vehicles would be fined as X Rs.
// Example 1:
// Input :
// 4 -> Value of N
// {5,2,3,7} -> a[], Elements a[0] to a[N-1], during input each element is separated by a new line
// 12 -> Value of D, i.e. date
// 200 -> Value of x i.e. fine
// Output :
// 600 -> total fine collected
// Explanation:
// Date D=12 means , only an even number of vehicles are allowed.
// Find will be collected from 5,3 and 7 with an amount of 200 each.
// Hence, the output = 600.
// Example 2:
// Input :
// 5 -> Value of N
// {2,5,1,6,8} -> a[], elements a[0] to a[N-1], during input each element is separated by new line
// 3 -> Value of D i.e. date
// 300 -> Value of X i.e. fine
// Output :
// 900 -> total fine collected
// Explanation:
// Date D=3 means only odd number vehicles with are allowed.
// Find will be collected from 2,6 and 8 with an amount of 300 each.
// Hence, the output = 900
// Constraints:
// 0<N<=100
// 1<=a[i]<=9
// 1<=D <=30
// 100<=x<=5000
// The input format for testing
// The candidate has to write the code to accept 4 input(s).
// First input – Accept for N(Positive integer) values (a[]), where each value is separated by a new line.
// Third input – Accept value for D(Positive integer)
// Fourth input – Accept value for X(Positive integer )
// The output format for testing
// The output should be a positive integer number (Check the output in Example 1, Example e) if no fine is collected then print ”0”.
#include<iostream>
#include<vector>
using namespace std;
int CalculateFine(vector<int>& arr, int D, int X){
int fine = 0;
for(auto x : arr){
if(D % 2 == 0 && x % 2 != 0){
fine += X;
}else if(D % 2 != 0 && x % 2 == 0){
fine += X;
}
}
return fine;
}
int main(){
int N;
cin>>N;
vector<int> arr(N);
for(int i=0; i<N; i++){
cin>>arr[i];
}
int date;
cin>>date;
int fine;
cin>>fine;
cout<<CalculateFine(arr,date,fine);
return 0;
}