-
-
Save migueldferreira/e634a8c80bb4af5c258b to your computer and use it in GitHub Desktop.
Simple C++ program that calculates the compatibility percentage between two people based on their first name! Note that the percentages may vary depending on the order of the names: one person may love the other more or less than that one loves the first one!
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
#include<iostream> | |
#include<vector> | |
int main() { | |
std::string nameConcat, name; | |
std::vector<int> counter; | |
std::cout << "First name of the 1st person (lowercase): "; | |
std::cin >> nameConcat; | |
nameConcat += " ama "; | |
std::cout << "First name of the 2nd person (lowercase): "; | |
std::cin >> name; | |
nameConcat += name; | |
std::cout << nameConcat << std::endl; | |
for(size_t i = 0; i < nameConcat.size(); i++) { | |
char current = nameConcat[i]; | |
if(current == ' ') continue; | |
int currentCount = 0; | |
for(int pos = i; pos < nameConcat.size(); pos++) { | |
if(nameConcat[pos] != current) continue; | |
nameConcat[pos] = ' '; | |
currentCount++; | |
} | |
if(currentCount >= 10) counter.push_back(currentCount/10); | |
counter.push_back(currentCount % 10); | |
} | |
int size; | |
while((size = counter.size()) > 2) { | |
for(std::vector<int>::iterator it = counter.begin(); it < counter.end(); it++) | |
std::cout << *it << ' '; | |
std::cout <<std::endl; | |
std::vector<int> aux; | |
int i; | |
for(i = 0; i < size/2; i++) { | |
int sum = counter[i] + counter[size-1-i]; | |
if(sum >= 10) aux.push_back(sum/10); | |
aux.push_back(sum % 10); | |
} | |
if(size % 2 == 1) aux.push_back(counter[i]); | |
counter = aux; | |
} | |
int result; | |
if(counter.size() == 1) result = counter[0]; | |
else result = counter[0] * 10 + counter[1]; | |
std::cout << result << "%" << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment