#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void)
{
FILE *fp;
int i=0,j=0,l=0,m=0,second=0,snd=0,sec21=0,sec22=0,sec23=0;
char buf[10],first[10],str[10],t,orien[10];
char sb31[10],sb32[10],sb33[10],third[10],pthird[10];
if ((fp=fopen("xuan.txt","r"))==NULL)
{
printf("read err!\n");
exit(0);
}
memset(buf,0x00,10);
while (!feof(fp))
{
fscanf(fp,"%c",&t);
if (t!='\t' && t!='\n')
{
buf[i]=t;
i++;
}
else
{
i=0;
j++;
if (j==1)
{
strcpy(first,buf);
}
if (j==2)
{
second=atoi(buf);
}
if (j==3)
{
strcpy(third,buf);
}
memset(buf,0x00,10);
if (j==3)
{
l++;
j=0;
m++;
if (abs(second-snd)<2000 && strcmp(orien,first)==0)
{
if (m==1 && (strcmp(third,pthird)!=0))
{
strcpy(sb31,pthird);strcpy(sb32,third);sec21=snd;sec22=second;
}
else if (m==2 && strcmp(third,sb31)!=0 && strcmp(third,sb32)!=0)
{
strcpy(sb33,third);sec23=second;
}
else if (m==3 && strcmp(third,sb31)!=0 && strcmp(third,sb32)!=0 && strcmp(third,sb33)!=0)
{
printf(orien);printf("\t");itoa((l-3),str,10);printf(str);printf("---");itoa(l,str,10);printf(str);printf("\n");
strcpy(sb31,sb32);strcpy(sb32,sb33);strcpy(sb33,third);snd=sec21;sec21=sec22;sec22=sec23;sec23=second;
}
else if (m>3 && strcmp(third,sb31)!=0 && strcmp(third,sb32)!=0 && strcmp(third,sb33)!=0)
{
printf(orien);printf("\t");itoa((l-3),str,10);printf(str);printf("---");itoa(l,str,10);printf(str);printf("\n");
strcpy(sb31,sb32);strcpy(sb32,sb33);strcpy(sb33,third);snd=sec21;sec21=sec22;sec22=sec23;sec23=second;
}
else
{
m=0;
snd=second;
strcpy(orien,first);
}
}
else
{
m=0;
snd=second;
strcpy(orien,first);
}
strcpy(pthird,third);
}
}
}
fclose(fp);
return 0;
}
温馨提示:答案为网友推荐,仅供参考