[ FUN CODE ] Couple Or Friend Finder
This is a fun code which is based on love quotient. The love quotient of the names is calculated. If the difference of the love qoutients of the two names is 0, 4, 16, or 32, the pair is declared a COUPLE or else, they are declared as FRIEND. The bellow code is implemented in C++
To calculate the love qoutient of a name individually, take the product of the letters, considering A as 1, Z as 26 and so on. Then perform modulus 36 with that number. For example, DAVE can be calculated as:
D * A * V * E = (4 * 1 * 22 * 5) % 36 = 440 % 36 = 8
Screenshot
The Code
Got words to share, do comment here !
To calculate the love qoutient of a name individually, take the product of the letters, considering A as 1, Z as 26 and so on. Then perform modulus 36 with that number. For example, DAVE can be calculated as:
D * A * V * E = (4 * 1 * 22 * 5) % 36 = 440 % 36 = 8
Screenshot
The Code
#include<iostream> #include<string.h> #include<cmath> using namespace std; string upper(string x) { for(int i=0;i<x.size();i++) { x[i]=toupper(x[i]); } return x; } void call(string x, string y) { int yc=1,xc=1; for(int i=0;i<x.size();i++) { xc*=((int)x[i]-64); } for(int i=0;i<y.size();i++) { yc*=((int)y[i]-64); } xc=xc%36; yc=yc%36; int dif=std::abs(xc-yc); if(dif==0 || dif==4 || dif==16 || dif==32) cout<<"COUPLE"<<endl; else cout<<"FRIEND"<<endl; } int main() { int t; cin>>t; while(t-->0) { string x,y; cin>>x>>y; x=upper(x); y=upper(y); call(x,y); } return 0; }
Got words to share, do comment here !
Comments
Post a Comment