数据结构12——以三元组表为存储结构实现矩阵相加(耿5.7)

以三元组表为存储结构实现矩阵相加(耿5.7)

Time Limit: 3000ms, Memory Limit: 10000KB , Accepted: 247, Total Submissions: 1092

Description

假设稀疏矩阵A和B均以三元组表作为存储结构。试编写矩阵相加的程序,另设三元组表C存放结果矩阵。矩阵大小为m行n列(0<m,n<100)

Input

第一行输入t1,t2(0<t1,t2<100) ,t1和t2分别是矩阵A和B中非零元素的个数,后面t1+t2行分别输入A和B中的元素,用三元组表示。

Output

输出三元组表C。

  • Sample Input 
    3 3
    1 2 3
    3 2 1
    3 4 2
    1 1 4
    3 2 5
    3 4 1
  • Sample Output
    1 1 4
    1 2 3
    3 2 6
    3 4 3

#include<stdio.h>  
#include<stdlib.h>  
  
typedef struct node{  
    int row;  
    int col;  
    int num;  
}node;  
  
typedef struct{  
    int cnt1,cnt2;  
    node matrix1[101];  
    node matrix2[101];  
}juzhen;  
  
void init(juzhen *p){  
    int t1,t2,i=0;  
    int x,y,z,tmp;  
    scanf("%d%d",&t1,&t2);  
    p->cnt1=t1;  
    p->cnt2=t2;  
    while(1){  
        scanf("%d%d%d",&x,&y,&z);  
        p->matrix1[i].row = x;  
        p->matrix1[i].col = y;  
        p->matrix1[i]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值