Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void search(unsigned char *text,unsigned char *sample,int symbol, int *stopsymboltable,int i,int m,int *k,FILE *fout,int str)
- {
- int j,k1;
- do
- {
- j=str;
- k1=i;
- while ( (sample[j] == text[k1-1]) && (j >= 0) )
- {
- fprintf(fout,"%d ",k1+m);
- k1--;
- j--;
- }
- if ( (sample[j] != text[k1-1]) && (k1+1 < symbol) && (j >= 0) && (text[k1-1]>=0) )
- fprintf(fout,"%d ",k1+m);
- i=i+stopsymboltable[text[i-1]];
- } while ( i < symbol);
- *k=k1;
- }
- int clear(unsigned char *text,int k)
- {
- int i=0;
- while(k<=2046)
- {
- text[i]=text[k];
- k++;
- i++;
- }
- return i;
- }
- void open(unsigned char *sample, unsigned char *text,int *stopsymboltable,int i,FILE *fout,FILE *fin,int str)
- {
- int t=0,m=0,k;
- while(!feof(fin))
- {
- text[t]=fgetc(fin);
- if (t==2046)
- {
- search(text,sample,t,stopsymboltable,i,m,&k,fout, str);
- m=m+k;
- t=clear(text,k)-1;
- }
- t++;
- }
- search(text,sample,t ,stopsymboltable,i,m,&k,fout,str);
- }
- void stopsymbol(unsigned char *sample,int *stopsymboltable,int *i)
- {
- int i1,s;
- s=strlen((char*)sample);
- for(i1=0;i1<256;i1++)
- stopsymboltable[i1]=s;
- for(i1=0;i1<s-1;i1++)
- stopsymboltable[sample[i1]]=s-i1-1;
- *i=s;
- }
- int main()
- {
- FILE *fin,*fout;
- fin=fopen("in.txt", "r");
- fout=fopen("out.txt", "w");
- if (fin==NULL) return -1;
- if (fout==NULL) return -1;
- unsigned char text[2064],sample[18]={0};
- int stopsymboltable[256];
- int i,str;
- fgets((char*)sample,18,fin);
- str=strlen((char*)sample)-1;
- sample[str]='\0';
- str=strlen((char*)sample)-1;
- stopsymbol(sample,stopsymboltable,&i);
- open(sample,text,stopsymboltable,i,fout,fin,str);
- fclose(fin);
- fclose(fout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement