Last active
January 3, 2016 00:09
-
-
Save dedunumax/8381313 to your computer and use it in GitHub Desktop.
This class can compare two comma separated word lists and return the matching percentage.
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace WordCompare | |
{ | |
class FindWorkPercentage | |
{ | |
static void Main(string[] args) | |
{ | |
FindWorkPercentage pr = new FindWorkPercentage(); | |
Console.WriteLine(pr.GetPercentage("cat, cat, dog, puppy", "cat, bite, bark")); | |
Console.ReadKey(); | |
} | |
public float GetPercentage(string firstInputs, string secondInputs) | |
{ | |
float total = 0f; | |
float count = 0f; | |
float result = 0f; | |
//Removing Spaces | |
firstInputs = firstInputs.Replace(" ", ""); | |
secondInputs = secondInputs.Replace(" ", ""); | |
string[] firstArray = firstInputs.Split(','); | |
string[] secondArray = secondInputs.Split(','); | |
total = firstArray.Length + secondArray.Length; | |
for (int i = 0; i < firstArray.Length; i++) | |
{ | |
for (int j = 0; j < secondArray.Length; j++) | |
{ | |
if (firstArray[i] == secondArray[j]) | |
{ | |
count++; | |
break; | |
} | |
} | |
} | |
for (int i1 = 0; i1 < secondArray.Length; i1++) | |
{ | |
for (int j1 = 0; j1 < firstArray.Length; j1++) | |
{ | |
if (secondArray[i1] == firstArray[j1]) | |
{ | |
count++; | |
break; | |
} | |
} | |
} | |
//Caculating result as percentage | |
result = count / total * 100; | |
/* | |
* To have result as a ratio uncomment below line and comment above line. | |
* | |
* Note : Nothing ;) | |
*/ | |
//result = count / total; | |
return result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment