Skip to content

Commit f7ca66e

Browse files
committed
Merge branch 'master' of github.com:CodeToExpress/dailycodebase
2 parents 6e0dd34 + 7860809 commit f7ca66e

23 files changed

+1078
-43
lines changed

Day2/C++/palindromeday2.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @author:divyakhetan
3+
* @date: 30/12/2018
4+
*/
5+
6+
7+
#include<bits/stdc++.h>
8+
using namespace std;
9+
10+
11+
int main(){
12+
string s;
13+
cin >> s;
14+
string t = s;
15+
reverse(s.begin(), s.end());
16+
if(s.compare(t) == 0) cout << "Palindrome!";
17+
else cout << "Not a palindrome";
18+
return 0;
19+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
*@author: profgrammer
3+
*@date: 30-12-2018
4+
*/
5+
6+
#include <bits/stdc++.h>
7+
using namespace std;
8+
9+
10+
int main() {
11+
string s;
12+
cin>>s;
13+
14+
// method 1: print the string in reverse order
15+
cout<<"The reversed string is: ";
16+
for(int i = s.size()-1;i >= 0;i--) cout<<s[i];
17+
cout<<endl;
18+
19+
// method 2: swap characters at either end
20+
string s1 = s;
21+
for(int i = 0, j = s1.size()-1;i <= j;i++, j--){
22+
char temp = s1[i];
23+
s1[i] = s1[j];
24+
s1[j] = temp;
25+
}
26+
cout<<"The reversed string is: "<<s1<<endl;
27+
28+
// method 3: library functions
29+
s1 = s;
30+
reverse(s1.begin(), s1.end());
31+
cout<<"The reversed string is: "<<s1<<endl;
32+
33+
// to check if the string is a palindrome, we need to check if it is equal to its reverse.
34+
35+
if(s.compare(s1) == 0) cout<<"The string is a palindrome"<<endl;
36+
else cout<<"The string is not a palindrome\n";
37+
38+
}

Day2/C++/reverseday2.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @author:divyakhetan
3+
* @date: 30/12/2018
4+
*/
5+
6+
7+
#include<bits/stdc++.h>
8+
using namespace std;
9+
10+
11+
int main(){
12+
string s;
13+
cin >> s;
14+
reverse(s.begin(), s.end());
15+
cout <<s;
16+
return 0;
17+
}

Day2/README.md

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![cover](./cover.png)
1+
![cover](./cover.png)
22

33
# Day 2 -- String Reversal and Palindrome
44

@@ -224,7 +224,7 @@ public class Reverse {
224224

225225
## C++ Implementation
226226

227-
### [C++ Solution](./C++/reverseString.cpp)
227+
### [Solution by @imkaka](./C++/reverseString.cpp)
228228

229229
```cpp
230230
/*
@@ -255,6 +255,69 @@ return 0;
255255
}
256256
```
257257

258+
###[Solution by @profgrammer](./C++/profgrammer_reversepalindrome.cpp)
259+
```c
260+
/*
261+
*@author: profgrammer
262+
*@date: 30-12-2018
263+
*/
264+
265+
#include <bits/stdc++.h>
266+
using namespace std;
267+
268+
269+
int main() {
270+
string s;
271+
cin>>s;
272+
273+
// method 1: print the string in reverse order
274+
cout<<"The reversed string is: ";
275+
for(int i = s.size()-1;i >= 0;i--) cout<<s[i];
276+
cout<<endl;
277+
278+
// method 2: swap characters at either end
279+
string s1 = s;
280+
for(int i = 0, j = s1.size()-1;i <= j;i++, j--){
281+
char temp = s1[i];
282+
s1[i] = s1[j];
283+
s1[j] = temp;
284+
}
285+
cout<<"The reversed string is: "<<s1<<endl;
286+
287+
// method 3: library functions
288+
s1 = s;
289+
reverse(s1.begin(), s1.end());
290+
cout<<"The reversed string is: "<<s1<<endl;
291+
292+
// to check if the string is a palindrome, we need to check if it is equal to its reverse.
293+
294+
if(s.compare(s1) == 0) cout<<"The string is a palindrome"<<endl;
295+
else cout<<"The string is not a palindrome\n";
296+
}
297+
```
298+
299+
### [Solution by @divyakhetan](./C++/reverseday2.cpp)
300+
301+
```cpp
302+
/**
303+
* @author:divyakhetan
304+
* @date: 30/12/2018
305+
*/
306+
307+
308+
#include<bits/stdc++.h>
309+
using namespace std;
310+
311+
312+
int main(){
313+
string s;
314+
cin >> s;
315+
reverse(s.begin(), s.end());
316+
cout <<s;
317+
return 0;
318+
}
319+
```
320+
258321
## Python Implementation
259322

260323
### [Solution 1](./Python/Reverse.py)
@@ -549,7 +612,9 @@ public class Palindrome2 {
549612
}
550613
```
551614

552-
### [C++ Implementation](./C++/checkPalindrome.cpp)
615+
## C++ Implementation
616+
617+
### [Solution by @imkaka](./C++/checkPalindrome.cpp)
553618

554619
```cpp
555620
/*
@@ -587,6 +652,30 @@ int main(){
587652
}
588653
```
589654

655+
### [Solution by @divyakhetan](./C++/palindromeday2.cpp)
656+
657+
```cpp
658+
/**
659+
* @author:divyakhetan
660+
* @date: 30/12/2018
661+
*/
662+
663+
664+
#include<bits/stdc++.h>
665+
using namespace std;
666+
667+
668+
int main(){
669+
string s;
670+
cin >> s;
671+
string t = s;
672+
reverse(s.begin(), s.end());
673+
if(s.compare(t) == 0) cout << "Palindrome!";
674+
else cout << "Not a palindrome";
675+
return 0;
676+
}
677+
```
678+
590679
## Python Implementation
591680

592681
### [Solution 1](./Python/Palindrome.py)

Day3/C++/hammingDistanceday3.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @author:divyakhetan
3+
* @date: 30/12/2018
4+
*/
5+
6+
7+
#include<bits/stdc++.h>
8+
using namespace std;
9+
10+
11+
int main(){
12+
string s1, s2;
13+
cin >> s1 >> s2;
14+
if(s1.length() != s2.length()) cout << "Enter strings of equal length";
15+
else{
16+
int count = 0;
17+
for(int i = 0; i < s1.length(); i++){
18+
if(s1[i] != s2[i]) count++;
19+
}
20+
cout << "The Hamming Distance is: " << count;
21+
}
22+
return 0;
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
*@author: profgrammer
3+
*@date: 30-12-2018
4+
*/
5+
6+
7+
#include <bits/stdc++.h>
8+
using namespace std;
9+
10+
int main() {
11+
string s1, s2;
12+
cin>>s1>>s2;
13+
cout<<"The hamming distance is : ";
14+
// the hamming distance is calculated for strings of EQUAL length. hence if the lengths differ we return -1 as an invalid case.
15+
if(s1.size() != s2.size()) cout<<-1<<endl;
16+
else{
17+
// iterate through both strings and find the number of indices where the strings differ. the total of these indices is the hamming distance
18+
int hammingDistance = 0;
19+
for(int i = 0;i < s1.size();i++){
20+
if(s1[i] != s2[i]) hammingDistance++;
21+
}
22+
cout<<hammingDistance<<endl;
23+
}
24+
25+
}

Day3/README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Hamming](./cover.png)
1+
![Hamming](./cover.png)
22

33
# Day 3 -- The Hamming Distance Problem
44

@@ -173,6 +173,61 @@ int main(){
173173
}
174174
```
175175

176+
###[Solution by @profgrammer](./C++/profgrammer_hammingdistance.cpp)
177+
```c
178+
/*
179+
*@author: profgrammer
180+
*@date: 30-12-2018
181+
*/
182+
183+
184+
#include <bits/stdc++.h>
185+
using namespace std;
186+
187+
int main() {
188+
string s1, s2;
189+
cin>>s1>>s2;
190+
cout<<"The hamming distance is : ";
191+
// the hamming distance is calculated for strings of EQUAL length. hence if the lengths differ we return -1 as an invalid case.
192+
if(s1.size() != s2.size()) cout<<-1<<endl;
193+
else{
194+
// iterate through both strings and find the number of indices where the strings differ. the total of these indices is the hamming distance
195+
int hammingDistance = 0;
196+
for(int i = 0;i < s1.size();i++){
197+
if(s1[i] != s2[i]) hammingDistance++;
198+
}
199+
cout<<hammingDistance<<endl;
200+
}
201+
}
202+
```
203+
204+
### [hamingDistance](./C++/hammingDistanceday3.cpp)
205+
206+
```cpp
207+
/**
208+
* @author:divyakhetan
209+
* @date: 30/12/2018
210+
*/
211+
212+
213+
#include<bits/stdc++.h>
214+
using namespace std;
215+
216+
217+
int main(){
218+
string s1, s2;
219+
cin >> s1 >> s2;
220+
if(s1.length() != s2.length()) cout << "Enter strings of equal length";
221+
else{
222+
int count = 0;
223+
for(int i = 0; i < s1.length(); i++){
224+
if(s1[i] != s2[i]) count++;
225+
}
226+
cout << "The Hamming Distance is: " << count;
227+
}
228+
return 0;
229+
}
230+
176231
## C Implementation
177232

178233
### [hamming.c](./C/hamming.c)

day4/C++/MaxFreq.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* @author:divyakhetan
3+
* @date: 30/12/2018
4+
*/
5+
6+
7+
#include<bits/stdc++.h>
8+
using namespace std;
9+
10+
11+
int main(){
12+
string s1;
13+
cin >> s1;
14+
int freqlo[26];
15+
memset(freqlo, 0, sizeof(freqlo));
16+
int freqhi[26];
17+
memset(freqhi, 0, sizeof(freqhi));
18+
int max = 0;
19+
char maxc;
20+
//count for lowercase
21+
for(int i = 0; i < s1.length(); i++){
22+
if(s1[i] >= 'a' && s1[i] <= 'z'){
23+
freqlo[s1[i] - 'a']++;
24+
if(freqlo[s1[i] - 'a']> max){
25+
max = freqlo[s1[i] - 'a'];
26+
maxc = s1[i];
27+
}
28+
}
29+
30+
else if(s1[i] >= 'A' && s1[i] <= 'Z'){
31+
freqhi[s1[i] - 'A']++;
32+
if(freqhi[s1[i] - 'A']> max){
33+
max = freqhi[s1[i] - 'A'];
34+
maxc = s1[i];
35+
}
36+
}
37+
}
38+
39+
40+
41+
42+
cout << "Max freq is:" << max << " for " << maxc;
43+
return 0;
44+
}

day4/C++/vowelday4.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @author:divyakhetan
3+
* @date: 30/12/2018
4+
*/
5+
6+
7+
#include<bits/stdc++.h>
8+
using namespace std;
9+
10+
11+
int main(){
12+
string s1;
13+
cin >> s1;
14+
int count = 0;
15+
for(int i = 0; i < s1.length(); i++){
16+
if(s1[i] == 'a' || s1[i] == 'e' ||s1[i] == 'i' || s1[i] == 'o' ||s1[i] == 'u') count++;
17+
}
18+
cout << "Vowels are:" << count;
19+
return 0;
20+
}

0 commit comments

Comments
 (0)