Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

张世杰 矩阵相乘(已修改) #16

Open
ZSJ6 opened this issue Nov 27, 2018 · 1 comment
Open

张世杰 矩阵相乘(已修改) #16

ZSJ6 opened this issue Nov 27, 2018 · 1 comment
Labels
修改 代码出现问题,请修改后重新提交代码

Comments

@ZSJ6
Copy link

ZSJ6 commented Nov 27, 2018

`
#include"stdio.h"

#include"stdlib.h"

#define LEN sizeof(Mat)
#define num 1000
typedef struct Matrix {
int m, n, a;
struct Matrix *right, *down;
}Mat;
Mat *creat()
{
int i, j;
Mat *h, *p, *r1, *r2;
h = NULL;
r1 = (Mat *)malloc(LEN);
r1->right = NULL;
r1->down = NULL;
scanf("%d", &r1->a);
r2 = p = h = r1;
for (i = 1;i <= num - 1;i++)
{
r1 = (Mat *)malloc(LEN);
scanf("%d", &r1->a);
r1->right = NULL;
r1->down = NULL;
r2->right = r1;
r2 = r1;
}
for (i = 1;i <= num - 1;i++)
{
for (j = 1;j <= num;j++)
{
r1 = (Mat *)malloc(LEN);
scanf("%d", &r1->a);
r1->right = NULL;
r1->down = NULL;
if (j == 1)
p = p->down = r1;
else
r2->right = r1;
r2 = r1;
}
}
p = h;
for (i = 1;i <= num - 1;i++)
{
r1 = p;
r2 = p->down;
for (j = 1;j <= num - 1;j++)
{
r1 = r1->right;
r2 = r2->right;
r1->down = r2;
}
p = p->down;
}
return h;
}
Mat *creatm()
{
int i, j;
Mat *h, *p, *r1, *r2;
h = NULL;
r1 = (Mat *)malloc(LEN);
r1->a = 0;
r1->right = NULL;
r1->down = NULL;
r2 = p = h = r1;
for (i = 1;i <= num - 1;i++)
{
r1 = (Mat *)malloc(LEN);
r1->a = 0;
r1->right = NULL;
r1->down = NULL;
r2->right = r1;
r2 = r1;
}
for (i = 1;i <= num - 1;i++)
{
for (j = 1;j <= num;j++)
{
r1 = (Mat *)malloc(LEN);
r1->a = 0;
r1->right = NULL;
r1->down = NULL;
if (j == 1)
p = p->down = r1;
else
r2->right = r1;
r2 = r1;
}
}
p = h;
for (i = 1;i <= num - 1;i++)
{
r1 = p;
r2 = p->down;
for (j = 1;j <= num - 1;j++)
{
r1 = r1->right;
r2 = r2->right;
r1->down = r2;
}
p = p->down;
}
return h;
}
void print(Mat *h)
{
Mat *p1, *p2;
p1 = p2 = h;
do {
printf("\n");
do {
printf("%d\t", p1->a);
p1 = p1->right;
} while (p1);
p2 = p2->down;
p1 = p2;
} while (p2);
}
Mat *mul(Mat *h1, Mat *h2, Mat *h3)
{
Mat *head;
Mat *a1, *a2, *b1, *b2, *c1, c2;
int i, j, k, sum;
head = h3;
a1 = a2 = h1;
b1 = b2 = h2;
c1 = c2 = h3;
for (i = 1;i <= num;i++)
{
for (j = 1;j <= num;j++)
{
sum = 0;
for (k = 1;k <= num;k++)
{
sum = sum + a1->a
b1->a;
a1 = a1->right;
b1 = b1->down;
}
c1->a = sum;
c1 = c1->right;
b1 = b2 = b2->right;
a1 = a2;
}
c1 = c2 = c2->down;
a1 = a2 = a2->down;
b1 = b2 = h2;
}
return head;
}
int main()
{
Mat *h1, *h2, *h3;
printf("\n矩阵一:");
h1 = creat();
print(h1);
printf("\n矩阵二:");
h2 = creat();
print(h2);
h3 = creatm();
printf("\n相乘得:");
print(mul(h1, h2, h3));
return 0;
}
`

@wanghao15536870732
Copy link
Member

  • 编译未通过
error C2676: 二进制*”:“Mr不定义该运算符或到预定义运算符可接收的类型的转换
error C2065: “M”: 未声明的标识符
error: 结构体类型的数据无法直接相乘和赋值
  • 不符合题目要求(要求使用链表实现)
  • 实现了矩阵方式的矩阵乘法,但是时间复杂度过高

@wanghao15536870732 wanghao15536870732 added the 修改 代码出现问题,请修改后重新提交代码 label Dec 8, 2018
@ZSJ6 ZSJ6 changed the title 张世杰 矩阵相乘 张世杰 矩阵相乘(已修改) Feb 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
修改 代码出现问题,请修改后重新提交代码
Projects
None yet
Development

No branches or pull requests

2 participants