Advertisement
allia

жаккар

Mar 3rd, 2021
1,574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5.  
  6. class MainClass
  7. {
  8.   static int Minimum(int a, int b, int c)
  9.  {
  10.    int min = 0;
  11.  
  12.    if (a <= b && a <= c)
  13.     min = a;
  14.    else if (b <= a && b <= c)
  15.     min = b;
  16.    else if (c <= a && c <= b)
  17.     min = c;
  18.    return min;
  19.  }
  20.  
  21.   public static string Replace_s(string str)
  22.   {
  23.     Regex regF = new Regex(@"[^a-z0-9\s]");
  24.             str = regF.Replace(str.ToLower(), string.Empty);
  25.  
  26.             MatchCollection regS = Regex.Matches(str, @"[a-z0-9]{4,}\s?");
  27.  
  28.             str = "";
  29.             foreach (Match match in regS)
  30.             {
  31.               str += match.Value;
  32.             }
  33.  
  34.             return str;
  35.   }
  36.  
  37.   public static void Jaccard(string firstString, string secondString)
  38.   {
  39.    double c = 0.0;
  40.    double length = 0.0;
  41.    double n = firstString.Length;
  42.    double m = secondString.Length;
  43.  
  44.    if (n <= m)
  45.     length = n;
  46.      else length = m;
  47.  
  48.    for (int i = 0; i < length; i++)
  49.      if (firstString[i] == secondString[i])
  50.       c++;
  51.  
  52.    //Console.WriteLine("{0} {1} {2}", n, m, c);
  53.    double result = c/(n+m-c);
  54.    Console.Write(Math.Round(result, 8));
  55.   }
  56.  
  57.   public static void Main(string[] args)
  58.   {
  59.     string firstString;
  60.     string secondString;
  61.  
  62.     firstString = Console.ReadLine();
  63.     secondString = Console.ReadLine();
  64.      firstString = Replace_s(firstString);
  65.      secondString = Replace_s(secondString);
  66.    
  67.     Jaccard(firstString, secondString);
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement