Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. //205
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #include <iostream>
  4. #include <math.h>
  5. #include <string>
  6. #include <algorithm>
  7. #include <climits>
  8. using namespace std;
  9.  
  10.  
  11. double gakkar(string s1, string s2)
  12. {
  13.     double c = 0;
  14.     if (s1.length() <= s2.length())
  15.     {
  16.         for (int i = 0; i < s1.length(); i++) {
  17.             if (s1[i] == s2[i])
  18.                 c++;
  19.         }
  20.     }
  21.     else
  22.     {
  23.         for (int i = 0; i < s2.length(); i++)
  24.             if (s1[i] == s2[i])
  25.                 c++;
  26.     }
  27.     c = c / (s1.length() + s2.length() - c);
  28.  
  29.  
  30.     return c;
  31.        
  32.  
  33.  
  34. };
  35.  
  36. string norm2(string s)
  37. {
  38.     string x, k;
  39.     int i = 0;
  40.  
  41.     while ((int)s[i] == 32)
  42.         i++;
  43.  
  44.     for (; i<s.length(); i++)
  45.     {
  46.         if ((int)s[i] == 32)
  47.             if (k.length() > 3)
  48.             {
  49.                 x = x + k + " ";
  50.                 k = "";
  51.             }
  52.             else
  53.                 k = "";
  54.         else
  55.             k = k + s[i];
  56.     }
  57.     if (k.length() > 3)
  58.         x = x + k;
  59.     return x;
  60. }
  61.  
  62. string norm1(string s)
  63. {
  64.     string x;
  65.     for (int i = 0; i < s.length(); i++)
  66.     {
  67.         int a = (int)s[i];
  68.         if ((a == 32) || ((a >= 48) && (a <= 57)) || ((a >= 97) && (a <= 122)))
  69.             x = x + s[i];
  70.         if ((a >= 65) && (a <= 90))
  71.         {
  72.             s[i] += 32;
  73.             x = x + s[i];
  74.         }
  75.     }
  76.     return x;
  77. };
  78.  
  79.  
  80. int main()
  81. {
  82.     freopen("input.txt", "r", stdin);
  83.     freopen("output.txt", "w", stdout);
  84.     string s1,s2, m;
  85.  
  86.     getline(cin, s1);
  87.     getline(cin, s2);
  88.  
  89.     s1 = norm1(s1);
  90.     s1 = norm2(s1);
  91.     s2 = norm1(s2);
  92.     s2 = norm2(s2);
  93.    
  94.     cout.precision(8);
  95.  
  96.     cout << fixed << gakkar(s1, s2);
  97.  
  98.  
  99.  
  100.     return 0;
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement