Skip to content

Commit

Permalink
added day18 (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
divyakhetan authored and MadhavBahl committed Jan 15, 2019
1 parent 07e3991 commit 322fa46
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 0 deletions.
41 changes: 41 additions & 0 deletions day18/C++/CheckSquareDay18.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @author divyakhetan
* @date 14/1/2019
*/

#include<bits/stdc++.h>
using namespace std;

int main(){
int n;
cin >> n;
int a[n];
int b[n];
for(int i = 0; i < n; i++){
cin >> a[i];

}

for(int i = 0; i < n; i++){
cin >> b[i];

}
int num;
cin >> num;
sort(a, a + n);
sort(b, b + n);


bool flag = true;
for(int i = 0; i< n; i++){

if((int) pow(a[i], num) != b[i]){
flag = false;
break;
}
}
if(flag)
cout << "true" << endl;
else cout << "false" << endl;
return 0;
}
27 changes: 27 additions & 0 deletions day18/C++/FreqCounterDay18.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* @author divyakhetan
* @date 14/1/2019
*/

#include<bits/stdc++.h>
using namespace std;

int main(){
int n;
cin >> n;
int a[n];
map<int, int> m;
for(int i = 0; i < n; i++){
cin >> a[i];
m[a[i]]++;
}

map<int, int>::iterator it;
for (it = m.begin(); it != m.end(); it++)
{
std::cout << it->first << " comes " << it->second << " times " << '\n';
}


return 0;
}
33 changes: 33 additions & 0 deletions day18/C++/UniqueElementsDay18.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @author divyakhetan
* @date 14/1/2019
*/

#include<bits/stdc++.h>
using namespace std;

int main(){
int n;
cin >> n;
int a[n];

for(int i = 0; i < n; i++){
cin >> a[i];

}

//since sorted

int count = 1;
int pos = a[0];
for(int i = 1; i < n; i++){
if(a[i] != pos){
count++;
pos = a[i];

}
}

cout << count << endl;
return 0;
}
125 changes: 125 additions & 0 deletions day18/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,40 @@ function printFrequency (freqObj) {
freqCounter ([ 1, 2, 3, 1, 3, 4, 4, 4, 4, 2, 5]);
```

### C++ Implementation

#### [Solution by @divyakhetan](./C++/FreqCounterDay18.cpp)

```cpp
/**
* @author divyakhetan
* @date 14/1/2019
*/

#include<bits/stdc++.h>
using namespace std;

int main(){
int n;
cin >> n;
int a[n];
map<int, int> m;
for(int i = 0; i < n; i++){
cin >> a[i];
m[a[i]]++;
}

map<int, int>::iterator it;
for (it = m.begin(); it != m.end(); it++)
{
std::cout << it->first << " comes " << it->second << " times " << '\n';
}


return 0;
}
```

## Java Implementation

### [Solution](./Java/Freq.java)
Expand Down Expand Up @@ -246,6 +280,48 @@ function countUniques (arr) {
console.log (`Number of unique elements = ${countUniques([1, 1, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 5, 5, 6, 7])}`);
```

### C++ Implementation

#### [Solution by @divyakhetan](./C++/UniqueElementsDay18.cpp)



```cpp
/**
* @author divyakhetan
* @date 14/1/2019
*/

#include<bits/stdc++.h>
using namespace std;

int main(){
int n;
cin >> n;
int a[n];

for(int i = 0; i < n; i++){
cin >> a[i];
}

//since sorted

int count = 1;
int pos = a[0];
for(int i = 1; i < n; i++){
if(a[i] != pos){
count++;
pos = a[i];
}
}

cout << count << endl;
return 0;
}
```

## Java Implementation

### [Solution](./Java/Unique.java)
Expand Down Expand Up @@ -379,6 +455,55 @@ console.log (checkPowerN ([1, 2, 3, 4], [4, 9, 1, 16], 2));
console.log (checkPowerN ([3, 4, 5, 2], [1, 2, 3], 4));
```

### C++ Implementation

#### [Solution](./C++/CheckSquareDay18.cpp)


```cpp
/**
* @author divyakhetan
* @date 14/1/2019
*/

#include<bits/stdc++.h>
using namespace std;

int main(){
int n;
cin >> n;
int a[n];
int b[n];
for(int i = 0; i < n; i++){
cin >> a[i];

}

for(int i = 0; i < n; i++){
cin >> b[i];

}
int num;
cin >> num;
sort(a, a + n);
sort(b, b + n);


bool flag = true;
for(int i = 0; i< n; i++){
if((int) pow(a[i], num) != b[i]){
flag = false;
break;
}
}
if(flag)
cout << "true" << endl;
else cout << "false" << endl;
return 0;
}
```

## Java Implementation

### [Solution](./Java/Power.java)
Expand Down

0 comments on commit 322fa46

Please sign in to comment.