Skip to content

Commit

Permalink
Fix conlicts
Browse files Browse the repository at this point in the history
  • Loading branch information
MadhavBahl committed Dec 26, 2018
2 parents 98b7853 + 3c26214 commit 82dab62
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 9 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;
}
27 changes: 27 additions & 0 deletions day4/C++/day4_part_a.cpp
@@ -0,0 +1,27 @@
/*
* @author : dhruv-gupta14
* @date : 25/12/2018
*/

#include <bits/stdc++.h>
using namespace std;
int main()
{

int count = 0;
string str;
cin >> str;

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

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

cout<<count;
return 0;
}
30 changes: 30 additions & 0 deletions day4/C++/day4_part_b.cpp
@@ -0,0 +1,30 @@
/*
* @author : dhruv-gupta14
* @date : 25/12/2018
*/

#include <bits/stdc++.h>
using namespace std;
int main()
{
int count = 0;
string str;
cin >> str;

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

int cnt1 = 0;
char max;
for (int i = 0; i < str.size(); i++)
{
int cnt2 = std::count(str.begin(), str.end(), str[i]);
if (cnt2 > cnt1)
{
cnt1 = cnt2;
max = str[i];
}
}
cout <<char(max) << "=>" << cnt1;

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;
}
159 changes: 150 additions & 9 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,11 +262,52 @@ 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)

```py
```python
# Input the String.
string=input("Enter the String : ")

Expand All @@ -288,7 +329,8 @@ print("Number of vowels in the string are : ",count)

```

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

```py
"""
* @author: Shashank Jain
Expand Down Expand Up @@ -341,6 +383,33 @@ void main(){

}
```
## Ruby Implementation

### [Solution](./Ruby.partA_sol.rb)

```ruby
=begin
@author: aaditkamat
@date: 25/12/2018
=end
def count_vowels(str)
if str === nil or not str.class === String
-1
end
ctr = 0
str.downcase!
vowels = ['a', 'e', 'i', 'o', 'u']
vowels.each do |vowel|
ctr += str.count(vowel)
end
ctr
end

print "Enter a string: "
str = gets
str.chomp!
puts "The number of vowels in #{str} is : #{count_vowels(str)}"
```

</hr>

Expand Down Expand Up @@ -427,9 +496,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 @@ -467,6 +536,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 @@ -487,13 +597,13 @@ 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))

```

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

```python
"""
Expand Down Expand Up @@ -543,4 +653,35 @@ void main(){

printf("Most frequent character = \'%c\'\n", (Max+32));
}
```

## Ruby Implementation

### [Solution](./Ruby/partB_sol.rb)

```ruby
=begin
@author: aaditkamat
@date: 25/12/2018
=end
def most_frequent_character(str)
if str === nil or not str.class === String
nil
end
counts = {}
str.downcase!
str.each_char do |ch|
if not counts.key?(ch)
counts[ch] = 1
else
counts[ch] = counts[ch] + 1
end
end
counts.key(counts.values.max)
end

print "Enter a string: "
str = gets
str.chomp!
puts "The most frequent character in #{str} is : #{most_frequent_character(str)}"
```
21 changes: 21 additions & 0 deletions day4/Ruby/partA_sol.rb
@@ -0,0 +1,21 @@
=begin
@author: aaditkamat
@date: 25/12/2018
=end
def count_vowels(str)
if str === nil or not str.class === String
-1
end
ctr = 0
str.downcase!
vowels = ['a', 'e', 'i', 'o', 'u']
vowels.each do |vowel|
ctr += str.count(vowel)
end
ctr
end

print "Enter a string: "
str = gets
str.chomp!
puts "The number of vowels in #{str} is : #{count_vowels(str)}"

0 comments on commit 82dab62

Please sign in to comment.