Header Ads Widget

Anagram

program:-

Given two strings, a and b , that may or may not be of the same length, determine the minimum number of character deletions required to make a and b anagrams. Any characters can be deleted from either of the strings.
Input :
  • test cases,t
  • two strings a and b, for each test case
Output:
Desired O/p
Constraints :
string lengths<=10000
Note :
Anagram of a word is formed by rearranging the letters of the word.
For e.g. -> For the word RAM - MAR,ARM,AMR,RMA etc. are few anagrams.
SAMPLE INPUT
 
1
cde
abc
SAMPLE OUTPUT
 
4
Time Limit:1.0 sec(s) for each input file.
Memory Limit:256 MB
Source Limit:1024 KB

BEST SUBMISSION

SIMILAR PROBLEMS

CONTRIBUTORS

solotion:-                                                                                                       

#include<stdio.h>
#include<string.h>
void main()
{
     char a[10000],b[10000];
     int l1,l2,s=0,t,i,j,k,l,sum,s1=0,s2=0;
     scanf("%d",&t);
     for(i=1;i<=t;i++)
     {
         scanf("%s",a);
         scanf("%s",b);
         l1=strlen(a);
         l2=strlen(b);
         for(j=0;j<=l1-1;j++)
         {
            for(k=0;k<=l1-1;k++)
            {
                if(a[j]==a[k])
                {
                 s1=s1+1;
                 if(k!=j)
                 a[k]=1;
                }
            }
            for(k=0;k<=l2-1;k++)
            {
                if(a[j]==b[k])
                 s2=s2+1;
            }
            if(s1>s2)
             s=s+s2;
            else
             s=s+s1;
            s1=0;
            s2=0;
         }
l=l1+l2;
         sum=2*s;
         printf("%d\n",(l-sum));
         s=0;
     }
}

Post a Comment

0 Comments