how do i count the dupes
for example
Input name1: james
Input name2: james
so total is 10 dupes because it counts not detect
detect means 5 i need the how to count the dupes
how does one get or count the duplicated letters?
slow down and try english.
what the heck do you want to do, exactly?
what is the output for aaaa bbbb for the 2 strings? For aaaa abbbb ? Does 'a' == 'A' ?
most likely you want some to count with tables, but we need the problem description in full.
if you don't care about performance you can sort both strings up front and then muddle through them that way.
really need this for my code
so basically if i input "james" name1
and still "james" on name 2
it counts all the duplicated letters
input1 | input2
J A M E S | J A M E S
1 2 3 4 5 | 6 7 8 9 10
im just gonna give you the whole code its a flames proj
#include<iostream>
#include<string>
#include<cctype>
#include<cstring>
using namespace std;
int main()
{
int points, ans;
string nme1;
string nme2;
system("cls");
cout<<"Input Your Fullname: ";
getline(cin,nme1);
cout<<"Input Your Partners Fullname: ";
getline(cin,nme2);
points=0;
if(nme1.length()<=2)
{
cout<<"\nPlease Enter a name and try again.";
}
else
{
for (size_t x = 0; x < nme1.length(); x++)
{
nme1[x] = tolower(nme1[x]);
for (size_t y = 0; y < nme2.length(); y++)
{
nme2[y] = tolower(nme2[y]);
if(nme1[x]==nme2[y])
{
points++;
break;
}
else if(points!=0)
{
points++;
break;
}
for(size_t n = 0; n < nme1.length();n++)
{
if(nme1[x]==nme2[n])
{
points++;
break; }}}}
points=points*2;
cout<<"\nRESULTS:";
switch(points%6)
{
case 0:
cout<<"\n\nWALANG FOREVER, WALANG KAMI.....\n";
break;
case 1:
cout<<"\n\n"<<nme1<<" AND "<<nme2<<" are Friends only. Friendzone.....";
break;
case 2:
cout<<"\n\n"<<nme1<<" and "<<nme2<<" are LOVERS, Uwian na besh, may NANALO na besh.\n";
break;
case 3:
cout<<"\n\nACQUAINTANCE ( MURAG NON-EXISTENT RAKA PARA NIYA! )\n";
break;
case 4:
cout<<"\n\n"<<nme1<<" and "<<nme2<<" are goint to MARRY one another.\n";
break;
case 5:
cout<<"\n\n"<<nme1<<" and "<<nme2<<" are ENEMIES....\n";
break;
}
}
return 0;
}
also to answer the 10 duplicates
here another example
INPUT1 : "butt"man
INPUT2 : "buttb"oyl
so basically the duplicated letters are butt + b ignore the " so overall count the "butt" on input 1 and "buttb" on input 2 total is : 9
input1............input2
b u t t............b u t t b
1 2 3 4..........5 6 7 8 9
ignore the dots in the middle
most likely you want some to count with tables ... you can sort both strings
On jonnin’s advice, here’s an example about how to collect your data into tables you can later take advantage of (assumes character order is NOT important):
#include <cctype>
#include <iostream>
#include <map>
#include <string>
int main()
{
std::string nme1;
while( nme1.length() < 3 ) {
std::cout << "Input your fullname: ";
std::getline(std::cin, nme1);
if( nme1.length() < 3 ) {
std::cout << "\nPlease enter a name and try again.";
}
}
std::map<char, int> table1;
for(auto c : nme1) {
if( std::isalpha( c ) ) {
++table1[static_cast<char>( ::tolower( c ) )];
}
}
std::string nme2;
while( nme2.length() < 3 ) {
std::cout << "Input your partner's fullname: ";
std::getline(std::cin, nme2);
if( nme2.length() < 3 ) {
std::cout << "\nPlease enter a name and try again.";
}
}
std::map<char, int> table2;
for(auto c : nme2) {
if( std::isalpha( c ) ) {
++table2[static_cast<char>( ::tolower( c ) )];
}
}
// Now you have two ordered tables with the main data - just use them.
// For example:
// Do you want to sum all the occurences of a character c in "nme1" to all
// the occurencies of the same character in "nme2" ?
int how_many {};
for(constauto& [c, i] : table1 ) {
// TODO: delete this after debug:
std::cerr << "instances of " << c << " --> in nme1: " << i
<< " in nme2: ";
try {
how_many += i + table2.at(c);
// TODO: delete this after debug:
std::cerr << table2.at(c) << '\n';
} catch (std::out_of_range&) {
// TODO: delete this after debug:
std::cerr << "0\n";
/**/
}
}
// TODO: delete this after debug:
std::cerr << "Total common characters: " << how_many << '\n';
std::cout << "\nRESULTS:\n\n";
switch(how_many % 6) {
case 0:
std::cout << "WALANG FOREVER, WALANG KAMI...\n";
break;
case 1:
std::cout << nme1 << " and " << nme2 << " are Friends only. Friendzone...";
break;
case 2:
std::cout << nme1 << " and " << nme2 << " are LOVERS, Uwian na besh, ""may NANALO na besh.\n";
break;
case 3:
std::cout << "ACQUAINTANCE ( MURAG NON-EXISTENT RAKA PARA NIYA! )\n";
break;
case 4:
std::cout << nme1 << " and " << nme2 << " are goint to MARRY one another.\n";
break;
case 5:
std::cout << nme1 << " and " << nme2 << " are ENEMIES....\n";
break;
}
return 0;
}
Input your fullname: "butt"man
Input your partner's fullname: "buttb"oyl
instances of a --> in nme1: 1 in nme2: 0
instances of b --> in nme1: 1 in nme2: 2
instances of m --> in nme1: 1 in nme2: 0
instances of n --> in nme1: 1 in nme2: 0
instances of t --> in nme1: 2 in nme2: 2
instances of u --> in nme1: 1 in nme2: 1
Total common characters: 9
RESULTS:
ACQUAINTANCE ( MURAG NON-EXISTENT RAKA PARA NIYA! )