Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct _SLine
- {
- double start;
- double end;
- }Line;
- void swap(double *x,double *y)
- {
- double p=0;
- p=*x;*x=*y;*y=p;
- }
- int read(const char *sf,Line **mas,int *leng)
- {
- int i;
- FILE *f;
- double p;
- f=fopen(sf,"r");
- if(fscanf(f,"%d",leng)!=1) return -1;
- else
- {
- (*leng)=(*leng)/2;
- (*mas)=(Line*)malloc((*leng)*sizeof(Line));
- for(i=0;i<(*leng);i++)
- {
- fscanf(f,"%lf",&p);
- (*mas+i)->start=p;
- fscanf(f,"%lf",&p);
- (*mas+i)->end=p;
- if((*mas+i)->start>(*mas+i)->end) swap(&((*mas+i)->end),&((*mas+i)->start));
- }
- }
- fclose(f);
- return 0;
- }
- Line joined_lines(Line *mas,int leng)
- {
- int i=0;
- double min_start=mas[1].start,max_end=mas[1].end;
- Line l;
- for(i=2;i<leng;i++)
- {
- if(mas[i].start<=min_start) min_start=mas[i].start;
- if(mas[i].end>=max_end) max_end=mas[i].end;
- }
- l.start=min_start;
- l.end=max_end;
- return l;
- }
- int if_belong(Line l1,Line l2)
- {
- if(((l1.start>=l2.start)&&(l1.end<=l2.end))) return 1;else return 0;
- }
- int main(int __argc,char *__argv[])
- {
- if(__argc>1)
- {
- int leng;
- Line *mas;
- FILE *f;
- if(read(__argv[1],&mas,&leng)==0)
- {
- f=fopen(__argv[2],"w");
- fprintf(f,"%d",if_belong(mas[0],joined_lines(mas,leng)));
- fclose(f);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment