0

Basically this program is made up of two other programs. First Part to find the permutations of a Sub-String and the Second Part to find the number of occurence of all the permutations in a given String. I'm not Getting the required output for most cases I'd be glad if anybody could help.Thanks.

Here is the Program..

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>


int appearanceCount(int input1,int input2,char* input3,char* input4)
{
     int count=0,temp,i,j,k;
     int no_of_permutations=1;
     for(i=1;i<input1+1;i++)
     {
         no_of_permutations *= i;
     }
     int a = no_of_permutations/((input1-1));

     for (i=0; i < a; i++)          
     {
         for(j=0; j<input1-1; j++)
         {
             char temp; 
             temp=input3[j];    
             input3[j]=input3[j+1];
             input3[j+1] = temp;                        
             //printf("\n%s",input3);
             char *temp_input4 = input4;     
 //Now I have got the permutation
 //Finding the occurance 
             while(temp_input4 = (strstr(temp_input4, input3)) ) 
             {
                 count++;
                 printf("\n%s  -- %s  -- %d",temp_input4,input3,count);
                 temp_input4++;
             }
         }
      }
      return count;
 }

 int main() 
 {
     int output = 0;
     int ip1;
     scanf("%d", &ip1);
     int ip2;
     scanf("%d", &ip2);
     char* ip3;
     ip3 = (char *)malloc(512000 * sizeof(char));
     scanf("\n%[^\n]",ip3);
     char* ip4;
     ip4 = (char *)malloc(512000 * sizeof(char));
     scanf("\n%[^\n]",ip4);
     output = appearanceCount(ip1,ip2,ip3,ip4);
     printf("\n%d", output);
     return 0;
 }

My Expected output for the values 4 11 cAda AbrAcadAbRa

would be 2

because the two possible sequence that can be found in the string are Acad and cadA

but I get the output as 0;

rsanath
  • 1,154
  • 2
  • 15
  • 24

1 Answers1

0

Try using anagram search and then it will work fine.