求助:程序编译时无错误,但运行时却提示未编译
#pragma warning(disable:4786)#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cinio.h>
#include <string>
using namespace std;
const long maxn = 1048580;
const int INF = 0x3fffff;
const double EPS = 1e-6;
const double PI = 3.1415926;
typedef long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
int k;
typedef struct node //′¢Öμ
{
int add;
struct node *next;
} node,*Rlink;
Rlink head[maxn];
void List_insert(int add,int data) //á′±íÖD2åèëμØÖ·
{
if(head[add]==NULL)
{
head[add] = (node *)malloc(sizeof(node));
head[add]->add = data;
head[add]->next = NULL;
}
else
{
node *p = head[add];
while(p->next)
p=p->next;
node *q = (node *)malloc(sizeof(node));
q->add = data;
q->next = NULL;
p->next = q;
}
}
char str[1048580][101];
char lstr[110000000];
int hash(char *strr);
struct Trie
{
int next[1048580][101],fail[1048580],end[1048580];
int root,L;
int newnode()
{
for(int i = 0; i < 101; i++)
next[L][i] = -1;
end[L++] = -1;
return L-1;
}
void init()
{
L = 0;
root = newnode();
}
void insert(char s[],int id)
{
int len = strlen(s);
int now = root;
for(int i = 0; i < len; i++)
{
if(next[now][s[i]] == -1)
next[now][s[i]] = newnode();
now = next[now][s[i]];
}
end[now] = id;
}
void build()
{
queue<int>Q;
fail[root] = root;
for(int i = 0; i < 101; i++)
if(next[root][i] == -1)
next[root][i] = root;
else
{
fail[next[root][i]] = root;
Q.push(next[root][i]);
}
while(!Q.empty())
{
int now = Q.front();
Q.pop();
for(int i = 0; i < 101; i++)
if(next[now][i] == -1)
next[now][i]=next[fail[now]][i];
else
{
fail[next[now][i]]=next[fail[now]][i];
Q.push(next[now][i]);
}
}
}
int num[1048580];//¼Ç¼¸öêy
vector<int>post[1048580];//¼Ç¼λÖÃ
void query(char buf[],int n)
{
for(int i = 0; i < n; i++)
num[i] = 0,post[i].clear();
int len=strlen(buf);
int now=root;
for( i=0; i<len; i++)
{
now=next[now][buf[i]];
int temp = now;
while( temp != root )
{
if(end[temp] != -1)
{
num[end[temp]]++;
post[end[temp]].push_back(i);
}
temp = fail[temp];
}
}
for(i = 0; i < n; i++)
{
if(num[i] > 0)
{
int add = hash(str[i]); //′æ′¢Ôúêy×éÖD
for(int j=0; j<post[i].size(); j++)
{
List_insert(add,post[i][j]+1-k); //
}
}
}
}
};
Trie ac;
int hash(char *strr)
{
int len = strlen(strr);
int add = 0; //μØÖ·
int base = 1; //½øÖÆ
for(int i=len-1; i>=0; i--)
{
switch(strr[i])
{
case 'A':
add += 0*base;
break;
case 'T':
add += 1*base;
break;
case 'G':
add += 2*base;
break;
case 'C':
add += 3*base;
break;
}
base*=4;
}
return add;
}
void substr(char *st,char *ss,int i,int j) //i¿aê¼½Øè¡j¸ö×Ö·û,èó½østÖD
{
for(int k=0; k<j; k++)
st[k] = ss[k+i];
st[j] = '\0';
}
void Index(char *s)
{
int add = hash(s);
node *p = head[add];
while(p)
{
printf("Ä£ê½′®ËùÔúDNADòáDoÅÎa: %d,ËùÔúμÄϱêÎa: %d\n",p->add/101+1,p->add%101+1);
p=p->next;
}
}
int main()
{
printf("Çëêäèëò»¸öKÖμ:\n");
scanf("%d",&k);
map <string,int> map; //è¥ÖØ
string ss;
char tmp[102];
ac.init();
int i=0;
int cnt=0; //¼Ç¼Ä£ê½′®¸öêy
ifstream in("C:\\Users\\Administrator\\Desktop\\KMP\\solexa_100_170_1.fa"); //Îļt¶áè¡
if(in)
{
while(getline(in,ss))
{
ss.copy(tmp,100,0);
tmp[100] = '*'; //½«2»í¬DDμÄ×Ö·û′®·Ö¸ô¿a,±üÃa¿çDDÆ¥Åä3é1|
tmp[101] = '\0';
strcat(lstr,tmp);
for(int j=0; j<=100-k; j++)
{
string moshi = ss.substr(j,k);
if(map[moshi]==1) continue; //òѾ-2åèë1yμÄÄ£ê½′®2»»áÔù2åèë
substr(str[cnt],tmp,j,k);
ac.insert(str[cnt],cnt);
cnt++;
map[moshi] = 1; //2åèë±ê¼Ç
}
i++;
}
}
ac.build(); //ac×Ô¶ˉ»ú½¨á¢
ac.query(lstr,cnt);
char l[101];
printf("ÇëêäèëÄúòa2éÑˉμÄk-mer:\n");
while(~scanf("%s",l))
Index(l);
return 0;
}