回复 10楼 zhou31146001
你总得告诉我输入文件内容吧?!我用你以前发的那个“结果22.txt”输出是65534行,之所以少两行,是因为我没有输出数量为0的八联体。如果你想全输出,只要将
if( octamer_count[i] == 0 )
continue;
删除掉就行了
#include <stdio.h> #define N_A 8 #define N_B (1u<<(2*N_A)) int main() { unsigned long octamer_count[N_B] = { 0 }; ////// 1 ////// { FILE* file = fopen( "result22.txt", "rb" ); if( !file ) { puts( "cannot open the input file."); return 1; } { unsigned long octamer; unsigned long octamer_n = 0; char c; for( ; fread(&c,1,1,file)==1; ) { switch( c ) { case 'A': octamer = (octamer*4+0)%N_B; ++octamer_n; break; case 'T': octamer = (octamer*4+1)%N_B; ++octamer_n; break; case 'C': octamer = (octamer*4+2)%N_B; ++octamer_n; break; case 'G': octamer = (octamer*4+3)%N_B; ++octamer_n; break; case '\r': case '\n': continue; default: puts( "Fuck" ); case 'N': octamer_n = 0; continue; } if( octamer_n < N_A ) continue; octamer_n = N_A; ++octamer_count[octamer]; } } fclose( file ); } ////// 2 ////// { FILE* fileout = fopen( "result22_ouput.txt", "wt" ); if( !fileout ) { puts( "cannot open the output file."); return 2; } { unsigned int i, j; for( i=0; i<sizeof(octamer_count)/sizeof(octamer_count[0]); ++i ) { if( octamer_count[i] == 0 ) continue; for( j=N_B/4; j!=0; j/=4 ) fprintf( fileout, "%c", "ATCG"[i/j%4] ); fprintf( fileout, " %u\n", octamer_count[i] ); } } fclose( fileout ); } return 0; }