Skip to content

Commit

Permalink
Day4 (#59)
Browse files Browse the repository at this point in the history
* Add @imkaka as a contributor

* day4
  • Loading branch information
imkaka authored and MadhavBahl committed Dec 26, 2018
1 parent bc6fa3a commit 8f271d2
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 7 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
@@ -1,4 +1,5 @@
[![All Contributors](https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square)](#contributors)

## Contributors

Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
Expand Down
1 change: 1 addition & 0 deletions Day2/README.md
Expand Up @@ -216,6 +216,7 @@ public class Reverse {
System.out.println("Reversed String: " + reversed);
}
}
```

## C++ Implementation

Expand Down
34 changes: 34 additions & 0 deletions day4/C++/countVovels.cpp
@@ -0,0 +1,34 @@
/*
* @author: imkaka
* @date: 25/12/2018
*/

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int count = 0;
string str;
cout << "/* ===== Number of Vowels ===== */" << endl;
cout << "\nEnter the string: ";
cin >> str;

// transform(str.begin(), str.end(), str.begin(), ::tolower);

for (int i = 0; i < str.size(); i++)
{
if (
tolower(str[i]) == 'a' ||
tolower(str[i]) == 'e' ||
tolower(str[i]) == 'i' ||
tolower(str[i]) == 'o' ||
tolower(str[i]) == 'u')
{
count++;
}
}
// Print the result
cout<<"Number of vowels in \""<<str<<"\" = "<<count<<endl;
return 0;
}
Binary file added day4/C++/mostFrequent
Binary file not shown.
31 changes: 31 additions & 0 deletions day4/C++/mostFrequent.cpp
@@ -0,0 +1,31 @@
/*
* @author : imkaka
* @date : 25/12.2018
*/


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int main()
{
string str;
cout << "Enter the string: ";
cin >> str;

int max_count = -1;
char label;
for (int i = 0; i < str.size(); ++i)
{
int current_count = count(str.begin(), str.end(), str[i]);
if (current_count > max_count)
{
max_count = current_count;
label = str[i];
}
}
cout << "'" << (char)label << "' has MAX " << max_count << " occurences in " << str << endl;
return 0;
}
99 changes: 92 additions & 7 deletions day4/README.md
Expand Up @@ -76,7 +76,7 @@ function numVowels (str) {
// Define an array of vowels
let vowels = ['a', 'e', 'i', 'o', 'u'];

// Check each character of string
// Check each character of string
for (let char of str) {
for (let vowel of vowels) {
if (char.toLowerCase() === vowel) count++;
Expand Down Expand Up @@ -122,12 +122,12 @@ function numVowels (str) {
}
}
}

// Print the result
console.log('Vowel Count: ');
for (let vowel in vowels) {
console.log(`Vowel: ${vowel} appears ${vowels[vowel]} number of times in the string "${str}"`);
}
}

console.log("Total number of vowels: " + count);
return count;
Expand Down Expand Up @@ -262,6 +262,47 @@ int main()
}
```

### [countVovels.cpp](./C++/countVovels.cpp)

```cpp

/*
* @author: imkaka
* @date: 25/12/2018
*/

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int count = 0;
string str;
cout << "/* ===== Number of Vowels ===== */" << endl;
cout << "\nEnter the string: ";
cin >> str;

// transform(str.begin(), str.end(), str.begin(), ::tolower);

for (int i = 0; i < str.size(); i++)
{
if (
tolower(str[i]) == 'a' ||
tolower(str[i]) == 'e' ||
tolower(str[i]) == 'i' ||
tolower(str[i]) == 'o' ||
tolower(str[i]) == 'u')
{
count++;
}
}

cout<<"Number of vowels in \""<<str<<"\" = "<<count<<endl;
return 0;
}

```

## Python Implementation

### [Solution](./Python/partA_sol.py)
Expand All @@ -288,7 +329,9 @@ print("Number of vowels in the string are : ",count)

```

### [Solution 2](./Python/Shashankvowels.py)

### [Solution by shashank](./Python/Shashankvowels.py)

```python
"""
* @author: Shashank Jain
Expand All @@ -304,6 +347,7 @@ for i in b:
count=count+1
print(count)
```

## C Implementation

### [Solution](./C/vowels.c)
Expand Down Expand Up @@ -453,9 +497,9 @@ maxChars('helllllo worlld');
* @author: Rajdeep Roy Chowdhury<rrajdeeproychowdhury@gmail.com>
* @github: https://github.com/razdeep
* @date: 25/12/2018
*
*
* Max Char Problem Solution
*
*
**/

#include <iostream>
Expand Down Expand Up @@ -493,6 +537,47 @@ int main()
}
```

### [mostFrequent.cpp](./C++/mostFrequent.cpp)

```cpp

/*
* @author : imkaka
* @date : 25/12.2018
*/


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int main()
{
string str;
cout << "Enter the string: ";
cin >> str;

int max_count = -1;
char label;
for (int i = 0; i < str.size(); ++i)
{
int current_count = count(str.begin(), str.end(), str[i]);
if (current_count > max_count)
{
max_count = current_count;
label = str[i];
}
}
cout << "'" << (char)label << "' has MAX " << max_count << " occurences in " << str << endl;
return 0;
}

// Time Compllexity = O(size(str) ^2)
// We can Improve that by using hashing to which will increse space complexity to O(n)
// Its called time-space trade off, which we generally do most times.
```

## Python Implementation

### [Solution](./Python/partB_sol.py)
Expand All @@ -513,7 +598,7 @@ for char in string:
# Else initialize its frequency by 1
else:
characters[char.lower()]=1

# Print the character which has the maximum frequency
print("The most occouring character in the string is : ", max(characters,key=characters.get))

Expand Down

0 comments on commit 8f271d2

Please sign in to comment.