fork download
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Test
  5. {
  6.  
  7. static double IntersectionSize(string a, string b) {
  8. var wordsA = a.Split(null);
  9. var wordsB = b.Split(null);
  10. var common = wordsA.Intersect(wordsB);
  11. double res = common.Sum(w => w.Length); // Total length of common words
  12. return 2 * res / (wordsA.Distinct().Sum(w => w.Length) + wordsB.Distinct().Sum(w => w.Length));
  13. }
  14. public static void Main()
  15. {
  16. var res = IntersectionSize(
  17. "Economie - Un oeil sur les medias"
  18. , "Un oeil sur les medias - Economie du mond"
  19. );
  20. Console.WriteLine(res);
  21. }
  22. }
Success #stdin #stdout 0.05s 24096KB
stdin
Standard input is empty
stdout
0.9