wu


私信TA

用户名:cncfvc

访问量:215748

签 名:

读研狗没有时间刷题了~~

等  级
排  名 2
经  验 36083
参赛次数 8
文章发表 265
年  龄 25
在职情况 学生
学  校 电子科技大学
专  业 通信工程

  自我简介:

写代码 真好玩 ~

解题思路:


这题做起来也可以很简单 ,但是我选择用链表来实现


注意事项:

注意链表的实现过程


参考代码:

#include<iostream>#include<cstdio>
#include<algorithm>
using namespace std;
struct LinkList
{
	int z;
	int fu;
	LinkList *next;
};
LinkList *BuildList(int n)
{
	LinkList *head=NULL;
	int zheng,fushu;
    while(n--)
    {
	   cin>>zheng>>fushu;
	   LinkList *new_node=(LinkList *)malloc(sizeof(LinkList));
		if(new_node==NULL) 
		{
			fprintf(stderr,"malloc failed");
			return head;
		}
		new_node->z=zheng;
		new_node->fu=fushu;
		LinkList *p;
	if(head==NULL)
	{
		new_node->next=NULL;
		head=new_node;
		p=head;
	}
	else 
	{

		p->next=new_node;
		new_node->next=NULL;
		p=new_node;
	} 
  }
	return head;
}
void CountList(LinkList *head)
{
	LinkList *p=head;
	int zheng=0,fu=0;
	while(p)
	{
		zheng+=p->z;
		fu+=p->fu; 
		p=p->next;
	}
    cout<<zheng<<"+"<<fu<<"i"<<endl;
}
int main()
{
	int n;
	cin>>n;
	LinkList *head=BuildList(n);
	CountList(head);
	return 0;
}


 

0.0分

6 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区

#include <bits/stdc++.h>
using namespace std;
int m,n;
double p[1005];
char s[1005];
double a[30][30];
double av[30];
char ss[30];
struct student{
    int cj; 
    char xz;
}zp[1005];
bool cmp(student aa,student bb){
    if(aa.cj!=bb.cj)
    return aa.cj>bb.cj;
    return aa.xz<bb.xz;
}
int main(){
    cin>>m>>n;
    for(int i=1;i<=m;i++){
        cin>>p[i];
        cin>>s[i];
    } 
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++){
        cin>>a[i][j];
    }
    for(int j=1;j<=n;j++){
        double sum=0.0,z=0.0;
        for(int i=1;i<=n;i++){
            sum+=a[i][j];
        }
2021-07-30 12:12:11
  • «
  • 1
  • »