这段代码我改了一下午了,还是不知道哪里出错了,各路大虾帮俺看看,小生在这里谢过了:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define N 20
double M[N][N];
int Men[N][11];
int Women[N][11];
void Input()
{
FILE *fp;
int i;
fp=fopen("men.txt","r");
for(i=0;i<N;i++)
{
fscanf(fp,"%d%d%d%d%d%d%d%d%d%d%d",&Men[i][0],&Men[i][1],&Men[i][2],&Men[i][3],&Men[i][4],&Men[i][5],&Men[i][6],&Men[i][7],&Men[i][8],&Men[i][9],&Men[i][10],&Men[i][11]);
}
fclose(fp);
fp=fopen("women.txt","r");
for(i=0;i<N;i++)
{
fscanf(fp,"%d%d%d%d%d%d%d%d%d%d%d",&Women[i][0],&Women[i][1],&Women[i][2],&Women[i][3],&Women[i][4],&Women[i][5],&Women[i][6],&Women[i][7],&Women[i][8],&Women[i][9],&Women[i][10],&Women[i][11]);
}
fclose(fp);
}
//判断两个人是否符合基本条件i表示men女生表示women
int Isone(int i,int j)
{
int k=0;
int m=0;
int n=0;
int q=0;
if(Men[i][0]-Women[j][0]<=5&&Women[j][0]-Men[i][0]<=2)//如果满足年龄条件
{
k=1;
}
for(q=1;q<=5;q++)
{
if(Men[i][q+5]>=Women[j][q])//假如women满足men的要求
m++;
}
for(q=1;q<=5;q++)
{
if(Women[j][q+5]>=Men[i][q])//假如men满足women的要求
n++;
}
if(m>=2&&n>=2&&k==1)
return 1;
else
return 0;
}
//构造0-1矩阵
void Ones()
{
int i;
int j;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
{
if(Isone(i,j))
M[i][j]=1;
else
M[i][j]=0;
}//初始化
}
void Display()
{
int i,j;
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
printf("%3d ",M[i][j]);
}
}
}
void Output(char*a)
{
FILE *fp;
int i;
int j;
fp=fopen(a,"w");
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
{
fprintf(fp,"%4.3f ",M[i][j]);
}
fprintf(fp,"/n");
}
fclose(fp);
}
double Weight(int i,int j)
{
double w=5;
int q=0;
if(Men[i][0]>Women[j][0])
w-=(Men[i][0]-Women[j][0])/5.0;
else
w-=(Women[j][0]-Men[i][0])/2.0;
for(q=1;q<=5;q++)
{
w+=(Men[i][q+5]-Women[j][q])/5.0;
}
for(q=1;q<=5;q++)
{
w+=(Women[j][q+5]-Men[i][q])/5.0;
}
return w;
}
double WeightMen(int i,int j)
{
double w=5;
int q=0;
if(Men[i][0]>Women[j][0])
w-=(Men[i][0]-Women[j][0])/5.0;
else
w-=(Women[j][0]-Men[i][0])/2.0;
for(q=1;q<=5;q++)
{
w+=(Men[i][q+5]-Women[j][q])/5.0;
}
return w;
}
double WeightWomen(int i,int j)
{
double w=5;
int q=0;
if(Men[i][0]>Women[j][0])
w-=(Men[i][0]-Women[j][0])/5.0;
else
w-=(Women[j][0]-Men[i][0])/2.0;
for(q=1;q<=5;q++)
{
w+=(Women[j][q+5]-Men[i][q])/5.0;
}
return w;
}
void WM()
{
int i,j;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
M[i][j]*=Weight(i,j);
Output("weight.txt");
}
void WMMen()
{
int i,j;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
M[i][j]*=WeightMen(i,j);
Output("weightmen.txt");
}
void WMWomen()
{
int i,j;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
M[i][j]*=WeightWomen(i,j);
Output("weightwomen.txt");
}
void main()
{
Input();
Display();
Ones();
Output("ones.txt");
WMMen();
}
c语言求助
最新推荐文章于 2022-10-19 16:36:08 发布