首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

[d]C语言程序以perl语言兑现

2012-10-10 
[d]C语言程序以perl语言实现* Note:Your choice is C IDE */#include stdio.h#includestdio.h#include

[d]C语言程序以perl语言实现
* Note:Your choice is C IDE */
#include "stdio.h"
#include<stdio.h>
#include <stdlib.h>
#include <iostream.h>

int point[4][14] =
 {{36,0,112,200,0,112,18,18,22,0,0,0,200,112},
  {0,0,0,0,200,0,9,0,0,0,0,0,0,0},
  {0,0,0,0,0,22,0,9,0,200,0,0,0,22},
  {72,200,22,0,0,0,27,27,112,0,200,200,0,0}};
void main()
{
  FILE *fp,*fp1,*buk;
  int i=0;
  int j=0;
  int score=0;
  int count=0;
  int len=0;
  char *pBuf;
  char c;
  system("cmd /c md d:\\lixinyue");
   
  if((fp=fopen("d:\\listeria.fasta","rt"))==NULL)
  {
  printf("\nCannot open file strike any key exit!");
  getch();
  exit(1);
  }
  if((fp1=fopen("d:\\lixinyue\\result.txt","wt+"))==NULL)
  {
  printf("\nCannot open file strike any key exit!");
  getch();
  exit(1);
  }
  if((buk=fopen("d:\\lixinyue\\buk.txt","wt+"))==NULL)
  {
  printf("\nCannot open file strike any key exit!");
  getch();
  exit(1);
  }
 
  while((c=fgetc(fp))!=EOF)
  {
  if(c=='A'||c=='T'||c=='G'||c=='C')
  fputc(c,buk);
  }
  fclose(fp);
  fclose(buk);
  if((buk=fopen("d:\\lixinyue\\buk.txt","rt"))==NULL)
  {
  printf("\nCannot open file strike any key exit!");
  getch();
  exit(1);
  }
  fseek(buk,0,SEEK_END);  
  len = ftell(buk);
  pBuf = (char *)malloc(sizeof(char)*(len+1));
  pBuf[len] = 0;
  rewind(buk);
  fread(pBuf,1,len,buk);
  fclose(buk);
  while(pBuf[i++]!='T');
  while(pBuf[i+++15]!=0)  
  { 
  score=0;
for(j=0;j<14;j++)
{
if(pBuf[i+j]=='A')
score+=point[0][j];
else if(pBuf[i+j]=='C')
score+=point[1][j];
else if(pBuf[i+j]=='G')
score+=point[2][j];
else 
score+=point[3][j];

if(score>1820)
{
fwrite(pBuf+i,sizeof(char),14,fp1);
count++;
fputc('\n',fp1);
break;
}
}
  }

fwrite("Totel count:",sizeof(char),sizeof("Totel count:"),fp1);
fputc(count/1000+'0',fp1);
fputc(count/100+'0',fp1);
fputc(count/10+'0',fp1);
fputc(count%10+'0',fp1);
system("explorer D:\\lixinyue\\result.txt");
  printf("Totel count:%d \n",count);
  printf("Mission Success");
  fclose(fp1);
  free(pBuf)
  return;

}

这是C语言的程序,怎么用perl实现呢?
-----------------------------
Double行动:
原帖分数:40

[解决办法]
没看明白程序要干嘛,大致可以按 perl 思路:

Perl code
#!/usr/bin/perluse strict;use warnings;my @point = (    [36,0,112,200,0,112,18,18,22,0,0,0,200,112],    [0, 0,0,0,200,0,9,0,0,0,0,0,0,0],    [0, 0,0,0,0,22,0,9,0,200,0,0,0,22],    [72,200,22,0,0,0,27,27,112,0,200,200,0,0],);my $in_file_name  = 'd:\listeria.fasta';my $out_file_name = 'd:\lixinyue\result.txt';my $buk_file_name = 'd:\lixinyue\buk.txt';open my $in,  '<', $in_file_name  or die "$!: $in_file_name";open my $out, '>', $out_file_name or die "$!: $out_file_name";open my $buk, '>', $buk_file_name or die "$!: $buk_file_name";while my $line (<$in>) {    my @chars = split //, $line;    for my $char (@chars) {        if () {        }    }}close $buk;close $out;close $in; 

热点排行