调用第一个函数divide成功,但是第二个compares就不行了,就算是在这个函数的第一行输出一个常数都输出不了,请问这是什么原因?
#include<iostream>
#include<string>
#include<cstring> //strlen()函数
#include<algorithm>//转化为小写函数
#include<iomanip>//输出间隔
#include<bits/stdc++.h>
using namespace std;
int k=0,k1=0; //k为txt中句子数量,k1为lib中句子数量
float g[10000][10000];
void compares(void);
int divide(char t[],char l[]);
void divide1(int i,int j);
double compute(int i,int j,double a[][10000]);
void result(double f[]);
double max(double a1,double a2,double a3);
struct txts
{
string sentence;
int num; //num为第i个句子的单词数
};
struct txts txt[10000];
struct txts lib[10000];
double compute(int i,int j,double a[][10000])
{
divide1(i,j);
int m=txt[i].num;
int n=lib[j].num;
a[0][0]=0; //先把整个句子拆成单个单词
for(int c=1;c<=n;c++)
a[0][c]=a[0][c-1]-0.5;
for(int c=1;c<=m;c++)
a[c][0]=a[c-1][0]-0.5;
for(int c=1;c<=m;c++)
{
for(int d=1;d<=n;d++)
{
a[c][d]=max(a[c-1][d-1]+g[c][d],a[c-1][d]-0.5,a[c][d-1]-0.5);
}
}
return a[m][n]/m;
}
double max(double a1,double a2,double a3)
{
double temp=a1;
if(a2>a1) temp=a2;
if(temp<a3) temp=a3;
return temp;
}
void divide1(int i,int j) //拆成单个单词,计算单词间的相似度矩阵
{
string x,y,x1,y1;
string t[10000],l[10000];
x=txt[i].sentence;
y=lib[j].sentence;
int h=x.length()+1;
int h1=y.length()+1;
int e=0,u=0;
while(e<h) //拆分txt的第i句的单词
{
if(((x[e]>='a')&&(x[e]<='z')) ||((x[e]>='A')&&(x[e]<='Z')))
{
x1+=x[e];
}
else
{
if(x1!="")
{
t[u]=x;
u+=1;
}
x1="";
}
e+=1;
}
txt[i].num=u;
e=0;
u=0;
while(e<h1) //拆分lib的第j句的单词
{
if(((y[e]>='a')&&(y[e]<='z')) ||((y[e]>='A')&&(y[e]<='Z')))
{
y1+=y[e];
}
else
{
if(y1!="")
{
l[u]=x;
k+=1;
}
y1="";
}
e+=1;
}
lib[j].num=u;
for(int e=0;e<txt[i].num;e++) //构造矩阵
{
for(int e1=0;e1<lib[j].num;e1++)
{
if(t[e]==l[e1])
g[e][e1]=1;
else
g[e][e1]=-1;
}
}
for(int e=0;e<txt[i].num;e++) //构造矩阵
{
for(int e1=0;e1<lib[j].num;e1++)
{
cout<<g[e][e1];
}
}
}
int divide(char t[],char l[]) //拆成单个句子
{
string x;
string y;
int h=strlen(t);
int h1=strlen(l);
for(int i=0;i<h;i++)
{
if(t[i]!='!'&&t[i]!='?'&&t[i]!='.'&&t[i]!=',')
{
x+=t[i];
}
else
{
if(x!="")
{
x+=' ';
if(t[i+1]==' ')
i+=1;
transform(x.begin(),x.end(),x.begin(), ::tolower);
txt[k].sentence=x;
k+=1;
x="";
}
}
}
for(int i=0;i<h1;i++)
{
if(l[i]!='!'&&l[i]!='?'&&l[i]!='.'&&l[i]!=',')
{
y+=l[i];
}
else
{
if(y!="")
{
y+=' ';
if(l[i+1]==' ')
i+=1;
transform(y.begin(),y.end(),y.begin(), ::tolower);
lib[k1].sentence=y;
cout<<lib[k1].sentence<<endl;
k1+=1;
y="";
}
}
}
}
void result(double f[])
{
double r,r1;
for(int i=0;i<k;i++)
{
if(f[i]>0.4)
{
r+=(f[i]*txt[i].num);
r1+=txt[i].num;
}
}
cout<<(r/r1)*100<<'%';
}
void compares(void)
{
cout<<k1<<endl;
cout<<lib[1].sentence;
double a[10000][10000],f[10000];
for(int i=0;i<k;i++) //txt的第i句和lib的第j句的相似度
{
for(int j=0;j<k1;j++)
{
double mx=compute(i,j,a); //计算相似度
f[i]=max(mx,f[i]);
cout<<f[i];
}
}
result(f);
}
int main()
{
char text[10000],lib[10000];
cin.getline(lib,10000);
cin.getline(text,10000);
divide(text,lib);
compares();
}