SabirSazzad

String Matching percentage

Mar 17th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     char s1[100],s2[100];
  8.     int match[100]= {0},i=0,j=0,k=0,count=0,large=0,s1Size=0,result=0;
  9.  
  10.     cout << "Input 1st string: ";
  11.     gets(s1);
  12.     cout << "Input 2nd String: ";
  13.     gets(s2);
  14.  
  15.     for (i=0,j=0; s1[i] != '\0' && s2[j] != '\0'; i++,j++)
  16.     {
  17.         s1Size++;
  18.         if(s1[i] == s2[j])
  19.         {
  20.             count++;
  21.             if(s1[i+1] != '\0' && s2[j+1] != '\0')
  22.             {
  23.                continue;
  24.             }
  25.         }
  26.         if(count!=0)
  27.         {
  28.             match[k] = count;
  29.             count = 0;
  30.             k++;
  31.         }
  32.  
  33.     }
  34.     for(i=0; match[i]!=0; i++)
  35.     {
  36.         if(match[i]>large)
  37.         {
  38.             large = match[i];
  39.         }
  40.     }
  41.     cout << "Highest Matching: " << large << " character" <<endl;
  42.     result = (large*100)/s1Size;
  43.     cout << "Result: " << result << "% Matching" <<endl;
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment