Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added C++ implementation of Day4 (#49)
* Added C++ implementation of Day4 * Day4 directory renamed to day4
- Loading branch information
Showing
3 changed files
with
179 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* @author: Rajdeep Roy Chowdhury<rrajdeeproychowdhury@gmail.com> | ||
* @github: https://github.com/razdeep | ||
* @date: 25/12/2018 | ||
**/ | ||
|
||
#include <iostream> | ||
#include <algorithm> | ||
using namespace std; | ||
int main() | ||
{ | ||
// set count = 0 | ||
int count = 0; | ||
string str; | ||
cout << "/* ===== Number of Vowels ===== */" << endl; | ||
cout << "\nEnter the string: "; | ||
cin >> str; | ||
|
||
// Convert input string to lower case | ||
// using transform() function and ::tolower in STL | ||
transform(str.begin(), str.end(), str.begin(), ::tolower); | ||
|
||
// Run a loop from 0 to string length | ||
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++; | ||
} | ||
} | ||
|
||
// Print the result | ||
cout<<"Number of vowels in \""<<str<<"\" = "<<count<<endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @author: Rajdeep Roy Chowdhury<rrajdeeproychowdhury@gmail.com> | ||
* @github: https://github.com/razdeep | ||
* @date: 25/12/2018 | ||
* | ||
* Max Char Problem Solution | ||
* | ||
**/ | ||
|
||
#include <iostream> | ||
#include <algorithm> | ||
#include <vector> | ||
#include <climits> | ||
using namespace std; | ||
int main() | ||
{ | ||
int count = 0; | ||
|
||
// Input the string | ||
string str; | ||
cout << "/* ===== Number of Vowels ===== */" << endl; | ||
cout << "\nEnter the string: "; | ||
cin >> str; | ||
|
||
// Convert input string to lower case | ||
// using transform() function and ::tolower in STL | ||
transform(str.begin(), str.end(), str.begin(), ::tolower); | ||
|
||
int max_count = INT_MIN; | ||
char max_label; | ||
for (int i = 0; i < str.size(); i++) | ||
{ | ||
int this_count = std::count(str.begin(), str.end(), str[i]); | ||
if (this_count > max_count) | ||
{ | ||
max_count = this_count; | ||
max_label = str[i]; | ||
} | ||
} | ||
cout << "'" << (char)max_label << "' has " << max_count << " occurences." << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters