-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
TeodorKolev
committed
Jun 11, 2017
1 parent
1833789
commit ccae52e
Showing
17 changed files
with
1,371 additions
and
0 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,84 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
#include <set> | ||
#include <map> | ||
|
||
using namespace std; | ||
|
||
int validateStringsCount(string prompt) | ||
{ | ||
int val; | ||
|
||
while (true) | ||
{ | ||
cin.clear(); | ||
cin.sync(); | ||
cout << prompt; | ||
cin >> val; | ||
if (cin.good() && val >= 1 && val < 100) | ||
{ | ||
break; | ||
} | ||
else | ||
cin.clear(); | ||
cout << "Invalid input! Value must be between 1 and 99" << endl; | ||
} | ||
return val; | ||
} | ||
|
||
int validateLastCharsCount(string prompt) | ||
{ | ||
int val; | ||
|
||
while (true) | ||
{ | ||
cin.clear(); | ||
cin.sync(); | ||
cout << prompt; | ||
cin >> val; | ||
if (cin.good() && val >= 1 && val < 200) | ||
{ | ||
break; | ||
} | ||
else | ||
cin.clear(); | ||
cout << "Invalid input! Value must be between 1 and 199" << endl; | ||
} | ||
return val; | ||
} | ||
|
||
int main() | ||
{ | ||
int stringsCount = validateStringsCount("Enter number of strings: "); | ||
|
||
vector<string> arr; | ||
string input; | ||
int counter = 0; | ||
|
||
for (int i = 0; i < stringsCount; ++i) { | ||
cout << "Enter String: "; | ||
cin >> input; | ||
transform(input.begin(), input.end(), input.begin(), ::tolower); | ||
arr.push_back(input); | ||
} | ||
|
||
int lastCharsCount = validateLastCharsCount("Enter number of last characters: "); | ||
|
||
map<string, int> words; | ||
for(string x : arr) ++(words[x.erase(0, x.length() - lastCharsCount)]); | ||
|
||
cout << "========================== " << endl; | ||
for(const auto& p : words) | ||
{ | ||
if(p.second > 1) | ||
{ | ||
cout << p.first << " - " << p.second << " times " << endl; | ||
++counter; | ||
} | ||
} | ||
|
||
cout << "Repeating words count is: " << counter << endl; | ||
cout << "========================== " << 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,98 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
int validateArrLength(string prompt) | ||
{ | ||
int val; | ||
|
||
while (true) | ||
{ | ||
cin.clear(); | ||
cin.sync(); | ||
cout << prompt; | ||
cin >> val; | ||
if (cin.good() && val >= 1 && val < 200) | ||
{ | ||
break; | ||
} | ||
else | ||
cin.clear(); | ||
cout << "Invalid input! Value must be between 1 and 199" << endl; | ||
} | ||
return val; | ||
} | ||
|
||
int validateInput(string prompt) | ||
{ | ||
int val; | ||
|
||
while (true) | ||
{ | ||
cin.clear(); | ||
cin.sync(); | ||
cout << prompt; | ||
cin >> val; | ||
if (cin.good() && val >= 0) | ||
{ | ||
break; | ||
} | ||
else | ||
cin.clear(); | ||
cout << "Invalid input! Value must be bigger than zero" << endl; | ||
} | ||
return val; | ||
} | ||
|
||
int validatePivot(string prompt, int firstArrLength) | ||
{ | ||
int val; | ||
|
||
while (true) | ||
{ | ||
cin.clear(); | ||
cin.sync(); | ||
cout << prompt; | ||
cin >> val; | ||
if (cin.good() && val >= 0 && val <= firstArrLength) | ||
{ | ||
break; | ||
} | ||
else | ||
cin.clear(); | ||
cout << "Invalid input! Value must in range of first array" << endl; | ||
} | ||
return val; | ||
} | ||
|
||
int main() | ||
{ | ||
vector<int> firstArr; | ||
vector<int> secondArr; | ||
int input; | ||
int pivot; | ||
|
||
int firstArrLength = validateArrLength("Enter first array length: "); | ||
|
||
for (int i = 0; i < firstArrLength; ++i) { | ||
input = validateInput("Enter Number: "); | ||
firstArr.push_back(input); | ||
} | ||
|
||
int secondArrLength = validateArrLength("Enter second array length: "); | ||
|
||
for (int i = 0; i < secondArrLength; ++i) { | ||
input = validateInput("Enter Number: "); | ||
secondArr.push_back(input); | ||
} | ||
|
||
pivot = validatePivot("Enter pivot point: ", firstArrLength); | ||
|
||
firstArr.insert(firstArr.begin() + pivot, secondArr.begin(), secondArr.end()); | ||
|
||
for (std::vector<int>::const_iterator i = firstArr.begin(); i != firstArr.end(); ++i) | ||
std::cout << *i << ' '; | ||
|
||
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,76 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int validateDaysCount(string prompt) | ||
{ | ||
int val; | ||
|
||
while (true) | ||
{ | ||
cin.clear(); | ||
cin.sync(); | ||
cout << prompt; | ||
cin >> val; | ||
if (cin.good() && val >= 2 && val <= 31) | ||
{ | ||
break; | ||
} | ||
else | ||
cin.clear(); | ||
cout << "Invalid input! Value must be between 2 and 31" << endl; | ||
} | ||
return val; | ||
} | ||
|
||
int validateTemperature(string prompt) | ||
{ | ||
int val; | ||
|
||
while (true) | ||
{ | ||
cin.clear(); | ||
cin.sync(); | ||
cout << prompt; | ||
cin >> val; | ||
if (cin.good() && val >= -50 && val <= 50) | ||
{ | ||
break; | ||
} | ||
else | ||
cin.clear(); | ||
cout << "Invalid input! Temperature must be between -50 and 50 degrees" << endl; | ||
} | ||
return val; | ||
} | ||
|
||
int main() | ||
{ | ||
int numberOfDays = validateDaysCount("Enter a number between 2 and 31: "); | ||
int daysArray[numberOfDays]; | ||
int previousDayTemp = 0; | ||
int higherTempCounter = 0; | ||
|
||
for(int i = 0; i < numberOfDays; i++) | ||
{ | ||
daysArray[i] = validateTemperature("Enter temperature: "); | ||
|
||
if (i == 0) | ||
{ | ||
previousDayTemp = daysArray[0]; | ||
} | ||
else | ||
{ | ||
if (daysArray[i] > previousDayTemp) | ||
{ | ||
higherTempCounter++; | ||
} | ||
previousDayTemp = daysArray[i]; | ||
} | ||
} | ||
|
||
cout << "Number of days with higher temperature is: " << higherTempCounter << endl; | ||
cout << 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,54 @@ | ||
#include <iostream> | ||
#include <algorithm> | ||
|
||
using namespace std; | ||
|
||
bool checkString(string result) | ||
{ | ||
return none_of(result.begin(), result.end(), [](const char& c) | ||
{ | ||
return !(isalpha(c) || isdigit(c) || c == ' '); | ||
}); | ||
} | ||
|
||
string validateInput(string prompt) | ||
{ | ||
string result; | ||
|
||
while (true) | ||
{ | ||
cin.clear(); | ||
cin.sync(); | ||
cout << prompt; | ||
getline(cin, result); | ||
if (checkString(result)) | ||
{ | ||
break; | ||
} | ||
else | ||
cin.clear(); | ||
cout << "Invalid input! Input must contain only small or capital letters and numbers." << endl; | ||
|
||
} | ||
return result; | ||
} | ||
|
||
int main() | ||
{ | ||
int counter = 0; | ||
string::size_type start = 0; | ||
string firstRow = validateInput("Enter first string: "); | ||
string secondRow = validateInput("Enter second string: "); | ||
transform(firstRow.begin(), firstRow.end(), firstRow.begin(), ::tolower); | ||
transform(secondRow.begin(), secondRow.end(), secondRow.begin(), ::tolower); | ||
|
||
while ((start = firstRow.find(secondRow, start)) != string::npos) | ||
{ | ||
++counter; | ||
start += secondRow.length(); | ||
} | ||
|
||
cout << counter << endl; | ||
|
||
return 0; | ||
} |
Oops, something went wrong.