Compare chars in two strings of different length in C# - c#

In C#, Im trying to compare two strings and find out how many chars are different.
I Tried this:
static void Main(String[] args)
{
var strOne = "abcd";
var strTwo = "bcd";
var arrayOne = strOne.ToCharArray();
var arrayTwo = strTwo.ToCharArray();
var differentChars = arrayOne.Except(arrayTwo);
foreach (var character in differentChars)
Console.WriteLine(character); //Will print a
}
but there are problems with this:
if the strings contain same chars but on different positions within the string
it removes the duplicate occurences
If the strings would be the same length I would compare the chars one by one but if one is bigger than the other the positions are different

You may want to have a look at the Leventshtein Distance Algorithm.
As the article says
the Levenshtein distance between two words is the minimum number of
single-character edits (insertions, deletions or substitutions)
required to change one word into the other
You can find many reference implementations in the internet, like here or here.
public static int LevenshteinDistance(string s, string t)
{
int n = s.Length;
int m = t.Length;
int[,] d = new int[n + 1, m + 1];
if (n == 0)
{
return m;
}
if (m == 0)
{
return n;
}
for (int i = 0; i <= n; d[i, 0] = i++)
{
}
for (int j = 0; j <= m; d[0, j] = j++)
{
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
int cost = (t[j - 1] == s[i - 1]) ? 0 : 1;
d[i, j] = Math.Min(
Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1),
d[i - 1, j - 1] + cost);
}
}
return d[n, m];
}
}

How about this? Append two strings into one and group them, you will have the count of the chars, > 1 will give the repeatings and = 0 will give the unique ones.
var strOne = "abcd";
var strTwo = "bcd";
var arrayOne = strOne.Concat(strTwo).GroupBy(x => x).Select(x => new { Key = x.Key, Count = x.Count() });
foreach (var character in arrayOne) {
if (character.Count > 1)
{
Console.WriteLine(character.Key); // the repeating chars
}
}
If the same character appears twice in the same string,
var strOne = "abbcdd";
var strTwo = "cd";
var arrayTwo = strOne.Select(x => new { Key = x, IsExists = strTwo.Any(y => y == x) });
foreach (var character in arrayTwo) {
if (character.IsExists)
{
Console.WriteLine(character.Key);
}
}

Related

All combinations of boolean values for array

I have an array of strings, can be any length. How can I produce a boolean matrix (array of array of boolean values with the same width as the array of strings) that contains all combinations of booleans?
Result should look something like this
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
.
.
1 1 1 1
Edit:
To elaborate a little, this is part of a solution to a larger problem to generate dynamic SQL to handle where clause conditions across multiple tables each with 2 versions. In my attempt to narrow down the issue I agree I might have been too terse, I apologize.
This is what I ended up doing with the help of JamJar00.
var sWhere = TranslateCriteriaToSQL(oUoW, oCriteria, false, false, DataBaseID, User);
var sResult = "";
var tables = asTables.ToArray();
int n = tables.Length;
List<bool[]> matrix = new List<bool[]>();
double count = Math.Pow(2, n);
for (int i = 0; i < count; i++)
{
string str = Convert.ToString(i, 2).PadLeft(n, '0');
bool[] boolArr = str.Select((x) => x == '1').ToArray();
var sCondition = sWhere;
for (var j = 0; j < boolArr.Length; j++)
{
if (boolArr[j])
{
sCondition = " OR (" + sCondition.Replace("[" + tables[j] + "]", "[" + tables[j] + "Pending" + "]") +
")\n";
}
}
sResult += sCondition;
}
}
Your question isn't the most clear but I think this something like what you're after:
int n = 4;
List<bool[]> matrix = new List<bool[]>();
double count = Math.Pow(2, n);
for (int i = 0; i < count; i++)
{
string str = Convert.ToString(i, 2).PadLeft(n, '0');
bool[] boolArr = str.Select((x) => x == '1').ToArray();
matrix.Add(boolArr);
Console.WriteLine(String.Join(" ", boolArr.Select((x) => x ? "1" : "0")));
}
bool[][] arr = matrix.ToArray();
Where n is the width of the strings to create.
(Definitely not the most optimized code I've ever written...)
Try this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication87
{
class Program
{
static void Main(string[] args)
{
string input = "abcdef";
long max = (long)(Math.Pow(2, input.Length) - 1);
for (long count = 0; count <= max; count++)
{
List<string> array = new List<string>();
for (int j = input.Length - 1; j >= 0; j--)
{
array.Add((count >> j & 1) == 0 ? "0" : "1");
}
Console.WriteLine(string.Join(" ", array.ToArray()));
}
Console.ReadLine();
}
}
}
With an input string s and bool array b:
string s = "foo";
bool[,] b = new bool[(int)Math.Pow(2, s.Length), s.Length];
for (int i = 0; i < (int)Math.Pow(2, s.Length); i++)
{
for (int j = 0; j < s.Length; j++)
{
b[i, s.Length - 1 - j] = ((i & (int)Math.Pow(2, j)) > 0);
}
}
Appreciate this is an old question, however I found myself having to generate all permutations for an array of booleans and came up with the following:
bool[][] GeneratePermutations(int size)
{
return Enumerable.Range(0, (int)Math.Pow(2, size))
.Select(i =>
Enumerable.Range(0, size)
.Select(b => ((i & (1 << b)) > 0))
.ToArray()
).ToArray();
}

Count Number of Changes Comparing two string in c# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to find out Number of changes comparing two string.
Example:
String 1:
I hope to do something good from this chance.I think my Test form will
help me in ODI. Scoring runs in international cricket, regardless of
the format, gives a player confidence.
string 2:
"I hope to do something good this chance. I think my Testing form will
help me in ODI Format. Scoring runs in latest international cricket,
regardless of the format, gives a playing confidence."
Expected Output: 5.(ignoring space & newline)
Changes are:
from(delete from string 2),
Testing(modified in string 2),
Format(extra addition in string 2),
latest(extra addition in string 2),
playing(modified in string 2).
Have any algorithm for count the number of changes?
You problem is quite similar to comparing two files.. Difference is In file comparison files are compared by comparing text in a single line. In your case it white space would be a separator instead of Newline.
Typically this is accomplished by finding the Longest Common Subsequence. Here is a related document which explains it: https://nanohub.org/infrastructure/rappture/export/2719/trunk/gui/src/diff.pdf
For finding LCS:
public static int GetLCS(string str1, string str2)
{
int[,] table;
return GetLCSInternal(str1, str2, out table);
}
private static int GetLCSInternal(string str1, string str2, out int[,] matrix)
{
matrix = null;
if (string.IsNullOrEmpty(str1) || string.IsNullOrEmpty(str2))
{
return 0;
}
int[,] table = new int[str1.Length + 1, str2.Length + 1];
for (int i = 0; i < table.GetLength(0); i++)
{
table[i, 0] = 0;
}
for(int j= 0;j<table.GetLength(1); j++)
{
table[0,j] = 0;
}
for (int i = 1; i < table.GetLength(0); i++)
{
for (int j = 1; j < table.GetLength(1); j++)
{
if (str1[i-1] == str2[j-1])
table[i, j] = table[i - 1, j - 1] + 1;
else
{
if (table[i, j - 1] > table[i - 1, j])
table[i, j] = table[i, j - 1];
else
table[i, j] = table[i - 1, j];
}
}
}
matrix = table;
return table[str1.Length, str2.Length];
}
//Reading Out All LCS sorted in lexicographic order
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
namespace LambdaPractice
{
class Program
{
static int[,] c;
static int max(int a, int b)
{
return (a > b) ? a : b;
}
static int LCS(string s1, string s2)
{
for (int i = 1; i <= s1.Length; i++)
c[i,0] = 0;
for (int i = 1; i <= s2.Length; i++)
c[0, i] = 0;
for (int i=1;i<=s1.Length;i++)
for (int j = 1; j <= s2.Length; j++)
{
if (s1[i-1] == s2[j-1])
c[i, j] = c[i - 1, j - 1] + 1;
else
{
c[i, j] = max(c[i - 1, j], c[i, j - 1]);
}
}
return c[s1.Length, s2.Length];
}
/* Prints one LCS
static string BackTrack(string s1, string s2, int i, int j)
{
if (i == 0 || j == 0)
return "";
if (s1[i - 1] == s2[j - 1])
return BackTrack(s1, s2, i - 1, j - 1) + s1[i - 1];
else if (c[i - 1, j] > c[i, j - 1])
return BackTrack(s1, s2, i - 1, j);
else
return BackTrack(s1, s2, i, j - 1);
}*/
static SortedSet<string> backtrack(string s1, string s2, int i, int j)
{
if (i == 0 || j == 0)
return new SortedSet<string>(){""} ;
else if (s1[i - 1] == s2[j - 1])
{
SortedSet<string> temp = new SortedSet<string>();
SortedSet<string> holder = backtrack(s1, s2, i - 1, j - 1);
if (holder.Count == 0)
{
temp.Add(s1[i - 1]);
}
foreach (string str in holder)
temp.Add(str + s1[i - 1]);
return temp;
}
else
{
SortedSet<string> Result = new SortedSet<string>() ;
if (c[i - 1, j] >= c[i, j - 1])
{
SortedSet<string> holder = backtrack(s1, s2, i - 1, j);
foreach (string s in holder)
Result.Add(s);
}
if (c[i, j - 1] >= c[i - 1, j])
{
SortedSet<string> holder = backtrack(s1, s2, i, j - 1);
foreach (string s in holder)
Result.Add(s);
}
return Result;
}
}
static void Main(string[] args)
{
string s1, s2;
s1 = Console.ReadLine();
s2 = Console.ReadLine();
c = new int[s1.Length+1, s2.Length+1];
LCS(s1, s2);
// Console.WriteLine(BackTrack(s1, s2, s1.Length, s2.Length));
// Console.WriteLine(s1.Length);
SortedSet<string> st = backtrack(s1, s2, s1.Length, s2.Length);
foreach (string str in st)
Console.WriteLine(str);
GC.Collect();
Console.ReadLine();
}
}
}
could you check this might be useful somehow, I would say you'll use a lot of control statements (if/else or switch) for result sets.
You can do it relatively easy, if you you consider a string as modified if it is starting with another string:
void Main()
{
var a = "I hope to do something good from this chance.I think my Test form will help me in ODI.Scoring runs in international cricket, regardless of the format, gives a player confidence.";
var b = "I hope to do something good this chance. I think my Testing form will help me in ODI Format. Scoring runs in latest international cricket, regardless of the format, gives a playing confidence.";
var d = new Difference(a,b);
Console.WriteLine("Number of differences: {0}", d.Count);
foreach (var diff in d.Differences)
{
Console.WriteLine("Different: {0}", diff);
}
}
class Difference
{
string a;
string b;
List<string> notInA;
List<string> notInB;
public int Count
{
get { return notInA.Count + notInB.Count; }
}
public IEnumerable<string> Differences
{
get { return notInA.Concat(notInB); }
}
public Difference(string a, string b)
{
this.a = a;
this.b = b;
var itemsA = Split(a);
var itemsB = Split(b);
var changedPairs =
from x in itemsA
from y in itemsB
where (x.StartsWith(y) || y.StartsWith(x)) && y != x
select new { x, y };
var softChanged = changedPairs.SelectMany(p => new[] {p.x, p.y}).Distinct().ToList();
notInA = itemsA.Except(itemsB).Except(softChanged).ToList();
notInB = itemsB.Except(itemsA).Except(softChanged).ToList();
}
IEnumerable<string> Split(string x)
{
return x.Split(new[] { " ", ".", ","}, StringSplitOptions.RemoveEmptyEntries);
}
}
Output:
Number of differences: 5
Different: from
Different: player
Different: Format
Different: latest
Different: playing

Latest Codility Time Problems

Just got done with the latest Codility, passed it, but didnt get 100% on it
Here is the spec
A prefix of a string S is any leading contiguous part of S. For example, "c" and "cod" are prefixes of the string "codility". For simplicity, we require prefixes to be non-empty.
The product of prefix P of string S is the number of occurrences of P multiplied by the length of P. More precisely, if prefix P consists of K characters and P occurs exactly T times in S, then the product equals K * T.
For example, S = "abababa" has the following prefixes:
"a", whose product equals 1 * 4 = 4,
"ab", whose product equals 2 * 3 = 6,
"aba", whose product equals 3 * 3 = 9,
"abab", whose product equals 4 * 2 = 8,
"ababa", whose product equals 5 * 2 = 10,
"ababab", whose product equals 6 * 1 = 6,
"abababa", whose product equals 7 * 1 = 7.
The longest prefix is identical to the original string. The goal is to choose such a prefix as maximizes the value of the product. In above example the maximal product is 10.
In this problem we consider only strings that consist of lower-case English letters (a−z).
So basically, it is a string traverse problem. I was able to pass all the validation parts, but I lost on the time. Here is what I wrote
int Solution(string S)
{
int finalCount = 0;
for (int i = 0; i <= S.Length - 1; i++)
{
string prefix = S.Substring(0, i + 1);
int count = 0;
for (int j = 0; j <= S.Length - 1; j++)
{
if (prefix.Length + j <= S.Length)
{
string newStr = S.Substring(j, prefix.Length);
if (newStr == prefix)
{
count++;
}
}
if (j == S.Length - 1)
{
int product = count * prefix.Length;
if (product > finalCount)
{
finalCount = product;
}
}
}
}
return finalCount;
}
I know that the nested loop is killing me, but I cannot think of a way to traverse the "sections" of the string without adding the other loop.
Any help would be appreciated.
Naive brute-force solution takes O(N ** 3) time. Choose length from 1 to N, get a prefix of its length and count occurences by brute-force searching. Сhoosing length takes O(N) time and brute force takes O(N ** 2) time, totally O(N ** 3).
If you use KMP or Z-algo, you can find occurences in O(N) time, so the whole solution will be O(N ** 2) time.
And you can precalc occurences, so it will take O(N) + O(N) = O(N) time solution.
vector<int> z_function(string &S); //z-function, z[0] = S.length()
vector<int> z = z_function(S);
//cnt[i] - count of i-length prefix occurrences of S
for (int i = 0; i < n; ++i)
++cnt[z[i]];
//if cnt[i] is in S, cnt[i - 1] will be in S
int previous = 0;
for (int i = n; i > 0; --i) {
cnt[i] += previous;
previous = cnt[i];
}
Here's the blog post, explaining all O(N ** 3), O(N ** 2), O(N) solutions.
my effort was as follows trying to eliminate unnecessary string compares, i read isaacs blog but it is in c how would this translate to c#, i even went as far as using arrays everywhere to avoid the string immutability factor but there was no improvement
int Rtn = 0;
int len = S.Length;
if (len > 1000000000)
return 1000000000;
for (int i = 1; i <= len; i++)
{
string tofind = S.Substring(0, i);
int tofindlen = tofind.Length;
int occurencies = 0;
for (int ii = 0; ii < len; ii++)
{
int found = FastIndexOf(S, tofind.ToCharArray(), ii);
if (found != -1)
{
if ((found == 0 && tofindlen != 1) || (found >= 0))
{
ii = found;
}
++occurencies ;
}
}
if (occurencies > 0)
{
int total = occurencies * tofindlen;
if (total > Rtn)
{
Rtn = total;
}
}
}
return Rtn;
}
static int FastIndexOf(string source, char[] pattern, int start)
{
if (pattern.Length == 0) return 0;
if (pattern.Length == 1) return source.IndexOf(pattern[0], start);
bool found;
int limit = source.Length - pattern.Length + 1 - start;
if (limit < 1) return -1;
char c0 = pattern[0];
char c1 = pattern[1];
// Find the first occurrence of the first character
int first = source.IndexOf(c0, start, limit);
while ((first != -1) && (first + pattern.Length <= source.Length))
{
if (source[first + 1] != c1)
{
first = source.IndexOf(c0, ++first);
continue;
}
found = true;
for (int j = 2; j < pattern.Length; j++)
if (source[first + j] != pattern[j])
{
found = false;
break;
}
if (found) return first;
first = source.IndexOf(c0, ++first);
}
return -1;
}
I only got a 43... I like my code though! Same script in javascript got 56 for what it's worth.
using System;
class Solution
{
public int solution(string S)
{
int highestCount = 0;
for (var i = S.Length; i > 0; i--)
{
int occurs = 0;
string prefix = S.Substring(0, i);
int tempIndex = S.IndexOf(prefix) + 1;
string tempString = S;
while (tempIndex > 0)
{
tempString = tempString.Substring(tempIndex);
tempIndex = tempString.IndexOf(prefix);
tempIndex++;
occurs++;
}
int product = occurs * prefix.Length;
if ((product) > highestCount)
{
if (highestCount > 1000000000)
return 1000000000;
highestCount = product;
}
}
return highestCount;
}
}
This works better
private int MaxiumValueOfProduct(string input)
{
var positions = new List<int>();
int max = 0;
for (int i = 1; i <= input.Length; i++)
{
var subString = input.Substring(0, i);
int position = 0;
while ((position < input.Length) &&
(position = input.IndexOf(subString, position, StringComparison.OrdinalIgnoreCase)) != -1)
{
positions.Add(position);
++position;
}
var currentMax = subString.Length * positions.Count;
if (currentMax > max) max = currentMax;
positions.Clear();
}
return max;
}

Longest Common Subsequence

Hi this is my code for longest common subsequence for 2 strings in c# . I need help in backtracking . I need to find out the subsequence : GTCGT
String str1 = "GTCGTTCG";
String str2 = "ACCGGTCGAGTG";
int[,] l = new int[str1.Length, str2.Length]; // String 1 length and string 2 length storing it in a 2-dimensional array
int lcs = -1;
string substr = string.Empty;
int end = -1;
for (int i = 0; i <str1.Length ; i++) // Looping based on string1 length
{
for (int j = 0; j < str2.Length; j++) // Looping based on string2 Length
{
if (str1[i] == str2[j]) // if match found
{
if (i == 0 || j == 0) // i is first element or j is first elemnt then array [i,j] = 1
{
l[i, j] = 1;
}
else
{
l[i, j] = l[i - 1, j - 1] + 1; // fetch the upper value and increment by 1
}
if (l[i, j] > lcs)
{
lcs = l[i, j]; // store lcs value - how many time lcs is found
end = i; // index on longest continuous string
}
}
else // if match not found store zero initialze the array value by zero
{
l[i, j] = 0;
}
}
Your function needs to return a collection of strings. There might be several longest common sub-sequence with same length.
public List<string> LCS(string firstString, string secondString)
{
// to create the lcs table easier which has first row and column empty.
string firstStringTemp = " " + firstString;
string secondStringTemp = " " + secondString;
// create the table
List<string>[,] temp = new List<string>[firstStringTemp.Length, secondStringTemp.Length];
// loop over all items in the table.
for (int i = 0; i < firstStringTemp.Length; i++)
{
for (int j = 0; j < secondStringTemp.Length; j++)
{
temp[i, j] = new List<string>();
if (i == 0 || j == 0) continue;
if (firstStringTemp[i] == secondStringTemp[j])
{
var a = firstStringTemp[i].ToString();
if (temp[i - 1, j - 1].Count == 0)
{
temp[i, j].Add(a);
}
else
{
foreach (string s in temp[i - 1, j - 1])
{
temp[i, j].Add(s + a);
}
}
}
else
{
List<string> b = temp[i - 1, j].Concat(temp[i, j - 1]).Distinct().ToList();
if (b.Count == 0) continue;
int max = b.Max(p => p.Length);
b = b.Where(p => p.Length == max).ToList();
temp[i, j] = b;
}
}
}
return temp[firstStringTemp.Length - 1, secondStringTemp.Length - 1];
}
You need to have a collection set in each entry of table. So you can still keep different strings with the same length in each cell of table.
As far as I've understood your question, I think you want to know the subsequence value i.e. that string. So, to get the subsequence, I've learnt a little bit differently. First, I calculate the table the one we do in standard Longest Common Subsequence (LCS) problem. Then I traverse the table to get the subsequence value. Sorry, I'm not familiar with C#, so, I will give you CPP code. Please have a look and let me know if you face any problem.
#include<iostream>
#include<vector>
#include<string>
using namespace std;
string printLongestCommonSubsequence(vector<vector<int> >& dp, int m, int n, string text1, string text2){
int i = m, j = n;
string lcs = "";
while(i > 0 && j > 0){
if(text1[i-1] == text2[j-1]){
lcs.push_back(text1[i-1]);
i--; j--;
}
else{
if(dp[i][j-1] > dp[i-1][j]) j--;
else i--;
}
}
reverse(lcs.begin(), lcs.end());
return lcs;
}
string longestCommonSubsequence(string text1, string text2){
int m = text1.size();
int n = text2.size();
vector<vector<int> > dp(m+1, vector<int>(n+1));
//initialization
for(int i=0; i<m+1; i++){
for(int j=0; j<n+1; j++){
if(i == 0 || j == 0) dp[i][j] = 0;
}
}
//solving the subproblems to solve the bigger problems
for(int i=1; i<m+1; i++){
for(int j=1; j<n+1; j++){
if(text1[i-1] == text2[j-1])
dp[i][j] = 1 + dp[i-1][j-1];
else
dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
}
}
return printLongestCommonSubsequence(dp, m, n, text1, text2);
}
int main(){
string text1, text2;
cout<<"Enter the first string: ";
cin>>text1;
cout<<"\nEnter the second string: ";
cin>>text2;
string lcs = longestCommonSubsequence(text1, text2);
cout<<"Longest Common Subsequence is: "<<lcs<<endl;
return(0);
}
Please have a look at the diagram.
With respect to printing the LCS,
The basic idea is:
When the characters are equal of both the strings then move towards diagonal.
When the characters are not equal of both the strings then move towards the maximum of both the directions.
I hope this helps 🙂
Happy Learning
Thanks

How can I calculate similarity between two strings in C#?

I'm looking to assess similarity (including case) between two strings and give a value between 0 and 1.
I tried the Levenshtein distance implementation but it only gives integers and does not compare inner alphabets.
For e.g. comparing "ABCD" and "Abcd" gives distance of 3 and "AOOO" also gives a distance of 3 but clearly "Abcd" is better match than "AOOO".
So compared to "ABCD" I want "ABcd" to be most similar then "Abcd" then "AOOO" then "AOOOO"
I've also looked here but I am not looking for a variable length algorithm.
Thanks
Try something like this
double d = (LevenshteinDist(s, t) + LevenshteinDist(s.ToLower(), t.ToLower())) /
2.0 * Math.Max(s.Length, t.Length);
If you want to give less importance to case differences than letter differences, you can give different weights to the terms
double d = (0.15*LevenshteinDist(s, t) +
0.35*LevenshteinDist(s.ToLower(), t.ToLower())) /
Math.Max(s.Length, t.Length);
Note that the weights sum up to 0.5, thus makting the division by 2.0 obsolete.
Adapt Levenshtein Distance with a custom table T. Let the cost of insertion = 1. The cost of deletion also 1. Let T(c,d) denote the penalty of replacing c with d. T(c,c) should be = 0. T(c,d) should be <= 2.
Define Max(n,m) be the maximum theoretical distance of strings of length n and m. Obviously, Max(n,m) = n+m.
Define Distance(s,t) be the cost of changing s to t divided by Max(s,t). There you go.
Be careful in defining T so that the definition obeys distance axioms:
Distance(s,s) = 0
Distance(s,t) = Distance(t,s)
Distance(s,t) <= Distance(s,u) + Distance(u,t)
Then it will be more useful in more situations.
bool check(string[] a, string s)
{
for (int i = 0; i < a.Length; i++)
if (s == a[i])
return true;
return false;
}
public double simi(string string1, string string2)
{
int sub1 = 0;
int sub2 = 0;
string[] sp1 = new string[string1.Length - 1];
string[] sp2 = new string[string2.Length - 1];
string[] sp3 = new string[string1.Length - 1];
string[] sp4 = new string[string2.Length - 1];
for (int i = 0; i < string1.Length - 1; i++)
{
string x = "";
x = string1.Substring(i, 2);
sp1[sub1] = x;
++sub1;
}
for (int i = 0; i < string2.Length - 1; i++)
{
string x = "";
x = string2.Substring(i, 2);
sp2[sub2] = x;
++sub2;
}
int j = 0, k = 0;
for (int i = 0; i < sp1.Length; i++)
if (check(sp3, sp1[i]) == true)
{
continue;
}
else
{
sp3[j] = sp1[i];
j++;
}
for (int i = 0; i < sp2.Length; i++)
if (check(sp4, sp2[i]) == true)
{
continue;
}
else
{
sp4[k] = sp2[i];
k++;
}
Array.Resize(ref sp3, j);
Array.Resize(ref sp4, k);
Array.Sort<string>(sp3);
Array.Sort<string>(sp4);
int n = 0;
for (int i = 0; i < sp3.Length; i++)
{
if (check(sp4, sp3[i]))
{
n++;
}
}
double resulte;
int l1 = sp3.Length;
int l2 = sp4.Length;
resulte = ((2.0 * Convert.ToDouble(n)) / Convert.ToDouble(l1 + l2)) * 100;
return resulte;
}

Categories

Resources