-
Notifications
You must be signed in to change notification settings - Fork 5
/
2018_2.c
128 lines (125 loc) · 2.9 KB
/
2018_2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* 检查FASTQ文件格式是否合规
* a. 以四行为一组.
* b. 第一行需以@开头
* c. 第二行字符仅包含A G T C a g t c 这八种字符
* d. 第三行需以+开头
* e. 第四行所用字符其ascii码值需在33到126之间且总个数与第二行相同
* 任意一条不符合, 则不合规
*/
#include <stdio.h>
#include <string.h>
#define MAXSIZE 2000
int judgefline(char* buff);
int judgesline(char* buff, int* secondnum);
int judgetline(char* buff);
int judgefoline(char* buff, int* secondnum);
int main(int argc, char* argv[]){
char filename[100]="./exe/2018.txt";
char buff[MAXSIZE];
FILE* fp;
fp=fopen(argv[1],"r"); //命令行执行语句: 2018_2 2018.txt
//fp=fopen(filename,"r");
int row=0;
int flag=0;
int secondnum=0;
while (fgets(buff,MAXSIZE,fp)!=NULL)
{
if (buff[strlen(buff)-1]=='\n')
{
buff[strlen(buff)-1]='\0';
}
//printf("%s\n",buff);
row++;
if (row%4==1)
{
if ((flag=judgefline(buff))==0)
{
printf("%s\n",buff);
printf("1 failed.\n");
break;
}
}
if (row%4==2)
{
if ((flag=judgesline(buff, &secondnum))==0)
{
printf("%s\n",buff);
printf("2 failed.\n");
break;
}
}
if (row%4==3)
{
if ((flag=judgetline(buff))==0)
{
printf("%s\n",buff);
printf("3 failed.\n");
break;
}
}
if (row%4==0)
{
if ((flag=judgefoline(buff, &secondnum))==0)
{
printf("%s\n",buff);
printf("4 failed.\n");
break;
}
}
}
if (flag && row%4==0)
{
printf("pass!\n");
}
else
{
printf("last failed.\n");
}
fclose(fp);
getchar();
return 0;
}
int judgefline(char* buff){
return buff[0]=='@';
}
int judgesline(char* buff, int* secondnum){
int flag;
*secondnum=strlen(buff);
for (int i = 0; i < strlen(buff); i++)
{
if (buff[i]!='A' && buff[i]!='C' && buff[i]!='T' && buff[i]!='G' && buff[i]!='a' && buff[i]!='c' && buff[i]!='t' && buff[i]!='g')
{
flag=0;
return flag;
}
flag=1;
}
return flag;
}
int judgetline(char* buff){
return buff[0]=='+';
}
int judgefoline(char* buff, int* secondnum){
if (strlen(buff)!=*secondnum)
{
return 0;
}
else
{
int flag;
for (int i = 0; i < strlen(buff); i++)
{
if (buff[i]>126 || buff[i]<33)
{
flag=0;
return flag;
}
else
{
flag=1;
}
}
return flag;
}
}