Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- int MINI(char *p,int hash1[],int hash2[],int count)
- {int count1=0,count2=0;//count2 will keep a count of the unique characters encountered in scan matching with the count
- while(*p!='\0')
- {if(hash2[*p-' ']==1)
- {if(hash1[*p-' ']==0)
- {hash1[*p-' ']=1;
- count2++;//count of unique characters increases
- }}
- count1++;//the total characters read which were present in str2
- if(count2==count)//all characters
- return count1;
- p++;
- }
- }
- int main()
- {int hash1[95],hash2[95];
- char str1[100],str2[100];
- //gets(str1);
- scanf("%[^\n]s",str1);
- getchar();
- scanf("%[^\n]s",str2);
- //gets(str2);
- int I;
- for(I=0;I<95;I++)
- {hash1[I]=0;
- hash2[I]=0;}
- char *p=str2;
- int count=0;//count contains number of unique characters in str2
- while(*p!='\0')
- {if(hash2[*p-' ']==0)
- {hash2[*p-' ']=1;
- count++;}
- p++;}//loop for hashing the characters of str2
- int min=strlen(str1);
- p=str1;
- int k;
- while(*p!='\0')
- {k=MINI(p,hash1,hash2,count);
- if(min>k)
- min=k;
- for(I=0;I<95;I++)
- hash1[I]=0;//hash table reset
- p++;
- }
- printf("%d",min);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement