Skip to content

Commit f7fadeb

Browse files
dhruv-gupta14MadhavBahl
authored andcommitted
day19 implementation in c++ (#179)
1 parent 50606ca commit f7fadeb

File tree

3 files changed

+142
-1
lines changed

3 files changed

+142
-1
lines changed

day19/C++/day19a.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* @author : dhruv-gupta14
3+
* @date : 15/01/2019
4+
*/
5+
6+
#include <bits/stdc++.h>
7+
using namespace std;
8+
9+
int main() {
10+
int n,m;
11+
cin >> n >> m;
12+
int arr1[n];
13+
int arr2[m];
14+
15+
for(int i=0;i<n;i++)
16+
cin >> arr1[i];
17+
18+
for(int j=0;j<m;j++)
19+
cin >> arr2[j];
20+
21+
for(int l=0;l<n;l++)
22+
{
23+
for(int k=0;k<m;k++)
24+
{
25+
cout << arr1[l] << "," << arr2[k] << endl;
26+
}
27+
}
28+
return 0;
29+
}

day19/C++/day19b.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* @author : dhruv-gupta14
3+
* @date : 15/01/2019
4+
*/
5+
6+
#include <bits/stdc++.h>
7+
using namespace std;
8+
9+
int main() {
10+
int n;
11+
cin >> n;
12+
int arr1[n];
13+
14+
for(int i=0;i<n;i++)
15+
cin >> arr1[i];
16+
17+
int temp=0;
18+
int random_index = 0;
19+
20+
for(int j=0;j<n;j++)
21+
{
22+
random_index = rand() % n;
23+
temp = arr1[j];
24+
arr1[j] = arr1[random_index];
25+
arr1[random_index] = temp;
26+
}
27+
28+
for(int k=0;k<n;k++)
29+
cout << arr1[k] << " ";
30+
31+
32+
return 0;
33+
}

day19/README.md

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,42 @@ console.log (cartesian ([1, 2, 3, 4], ['a', 'b', 'c']));
9595
```
9696
## Java Implementation
9797

98+
### C++ Implementation
99+
100+
#### [Solution 1](./C++/day19a.cpp)
101+
102+
```cpp
103+
/*
104+
* @author : dhruv-gupta14
105+
* @date : 15/01/2019
106+
*/
107+
108+
#include <bits/stdc++.h>
109+
using namespace std;
110+
111+
int main() {
112+
int n,m;
113+
cin >> n >> m;
114+
int arr1[n];
115+
int arr2[m];
116+
117+
for(int i=0;i<n;i++)
118+
cin >> arr1[i];
119+
120+
for(int j=0;j<m;j++)
121+
cin >> arr2[j];
122+
123+
for(int l=0;l<n;l++)
124+
{
125+
for(int k=0;k<m;k++)
126+
{
127+
cout << arr1[l] << "," << arr2[k] << endl;
128+
}
129+
}
130+
return 0;
131+
}
132+
```
133+
98134
### [Solution](./Java/cartesianProd.java)
99135

100136
```java
@@ -169,6 +205,7 @@ int main(){
169205
### Python Implementation
170206

171207
### [Solution](./Python/cartesian_product.py)
208+
172209
```python
173210
'''
174211
@author: aaditkamat
@@ -201,6 +238,7 @@ def main():
201238
### Python Implementation
202239

203240
### [Solution](./Python/cartesian_product.py)
241+
204242
```python
205243
'''
206244
@author: aaditkamat
@@ -229,6 +267,7 @@ def main():
229267
set_B = get_input('B')
230268
calculate_cartesian_product(set_A, set_B)
231269
```
270+
232271
***
233272

234273
### Python Implementation
@@ -314,6 +353,46 @@ function fisherYates (arr) {
314353
fisherYates ([1, 2, 3, 4, 5, 6]);
315354
```
316355

356+
### C++ Implementation
357+
358+
#### [Solution 1](./C++/day19b.cpp)
359+
360+
```cpp
361+
/*
362+
* @author : dhruv-gupta14
363+
* @date : 15/01/2019
364+
*/
365+
366+
#include <bits/stdc++.h>
367+
using namespace std;
368+
369+
int main() {
370+
int n;
371+
cin >> n;
372+
int arr1[n];
373+
374+
for(int i=0;i<n;i++)
375+
cin >> arr1[i];
376+
377+
int temp=0;
378+
int random_index = 0;
379+
380+
for(int j=0;j<n;j++)
381+
{
382+
random_index = rand() % n;
383+
temp = arr1[j];
384+
arr1[j] = arr1[random_index];
385+
arr1[random_index] = temp;
386+
}
387+
388+
for(int k=0;k<n;k++)
389+
cout << arr1[k] << " ";
390+
391+
392+
return 0;
393+
}
394+
```
395+
317396
## Java Implementation
318397

319398
### [Solution](./Java/FisheYates.java)
@@ -413,4 +492,4 @@ def main():
413492
fisher_yates(lst)
414493

415494
main()
416-
```
495+
```

0 commit comments

Comments
 (0)