-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday4.cpp
More file actions
71 lines (66 loc) · 1.26 KB
/
day4.cpp
File metadata and controls
71 lines (66 loc) · 1.26 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
#include<bits/stdc++.h>
using namespace std;
int checkUniqueElement(vector<int> &nums){
int count = 0;
for(int i =0; i<nums.size(); i++){
if(nums[i]==nums[i+1]){
count++;
}
}
int elm = nums.size() - count;
return elm;
}
int sum(int l){
int ans =0;
if(l<10) return l;
while(l>0){
int val = l%10;
ans += val;
l = l/10;
}
return ans;
}
int prod(int l){
int ans =1;
if(l<10) return l;
while(l>0){
int val = l%10;
ans *= val;
l = l/10;
}
return ans;
}
int beautifulNumbers(int l, int r) {
int ans = 0;
for(int i = l; i<=r;i++){
int s = sum(i);
int p = prod(i);
if(p%s==0){
ans++;
}
}
return ans;
}
bool divideArray(vector<int>& nums) {
int n = nums.size();
unordered_map<int,int>mp;
for(int i =0;i<n;i++){
mp[nums[i]]++;
}
for(auto i : mp){
if(i.second%2!=0){
return false;
}
}
return true;
}
int main(){
vector<int>v = {3,2,3,2,2,2,1};
//// set<int>s(v.begin(),v.end());
//// v.assign(s.begin(), s.end());
//// cout<< v.size();
// cout<< checkUniqueElement(v);
//cout<<prod(11124);
cout<<divideArray(v);
return 0;
}