链串(linkstring)&& 压缩矩阵(compress maxtrix)

#include<stdio.h> #include<malloc.h> #include<iostream> using namespace std; const int SIZE=100; struct linkString{ char data; linkString *next; }; void assign(linkString ** s,char t[]){ int i=0; linkString *q,*ts; *s=(linkString *)malloc(sizeof(linkString)); (*s)->next=NULL; ts=*s; while(t[i]){ q=(linkString *)malloc(sizeof(linkString)); q->data=t[i]; q->next=NULL; ts->next=q; ts=q; ++i; } ts->next=NULL; } void display(linkString *s){ linkString *p=s->next; while(p){ cout<<p->data; p=p->next; } cout<<endl; } int main(){ //cout<<NULL<<endl; char t[SIZE]; cin>>t; linkString* ls=NULL; cout<<ls<<endl; //int ii; //int *pii=&ii; assign(&ls,t); display(ls); } /* 1 2 4 7 2 3 5 8 4 5 6 9 7 8 9 10 */ #include<iostream> using namespace std; const int SIZE=4; const int SIZE2=SIZE*(SIZE+1)/2; int main(){ int arr[SIZE][SIZE],k=0; int b[SIZE*(SIZE+1)/2]; for(int i=0;i<SIZE;++i){ for(int j=0;j<SIZE;++j){ cin>>arr[i][j]; if(i>=j) b[k++]=arr[i][j]; } } //dis cout<<"original:"<<endl; for(int i=0;i<SIZE;++i){ for(int j=0;j<SIZE;++j) cout<<arr[i][j]<<" "; cout<<endl; } cout<<"compress:"<<endl; for(int i=0;i<SIZE2;++i) cout<<b[i]; cout<<endl; cout<<"________________________"<<endl; for(int i=0;i<SIZE;++i){ for(int j=0;j<SIZE;++j){ if(i>=j) cout<<b[i*(i+1)/2+j]<<" "; else cout<<b[j*(j+1)/2+i]<<" "; } cout<<endl; } cout<<"Input col & row:"<<endl; int col,row; cin>>row>>col; cout<<"In the original array:"<<endl; cout<<arr[row][col]<<endl; cout<<"In the array for symmetry matrix:"<<endl; if(row>=col) cout<<b[row*(row+1)/2+col]<<endl; else cout<<b[col*(col+1)/2+row]<<endl; }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值