鱼C论坛

 找回密码
 立即注册
查看: 2402|回复: 15

[已解决]求解,急!

[复制链接]
发表于 2022-12-10 13:33:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
捕2获.PNG
捕4获.PNG
捕获.PNG
c++
最佳答案
2022-12-10 16:12:47
本帖最后由 jhq999 于 2022-12-10 16:53 编辑

第一题,没样例不知道有没有bug
struct child
{

    int *candys;
    int candycount;

};
int main()
{
    int m,n,r,x,y,a;

    scanf("%d%d%d",&m,&n,&r);
    struct child *childs=(struct child *)calloc(n,sizeof(struct child));
    for(int i=0; i<n; i+=1)
    {
        childs[i].candys=(int*)calloc(m,sizeof(int));
    }
    for(int i=0; i<m; i+=1)
    {
        scanf("%d",&a);
        childs[a].candys[childs[a].candycount]=i;
        childs[a].candycount+=1;


    }
    for(int i=0; i<r; i+=1)
    {
        scanf("%d%d",&x,&y);
        int *tmp=childs[x].candys;
        childs[x].candys=childs[y].candys;
        childs[y].candys=tmp;
        a=childs[x].candycount;
        childs[x].candycount=childs[y].candycount;
        childs[y].candycount=a;
    }
    for(int i=0; i<n; i+=1)
    {
        printf("%d  ",childs[i].candycount);
        for(int j=0;j<childs[i].candycount;j+=1)printf("%6d ",childs[i].candys[j]);
        printf("\n");

    }
    for(int i=0; i<n; i+=1)
    {
        free(childs[i].candys);
    }
    free(childs);
    return 0;
}
#include <stdio.h>
#include<stdlib.h>
struct candy
{
    int id;
    struct candy* next;
};
struct child
{

    struct candy candys;
    int candycount;

};

int main()
{
    int m,n,r,x,y,a;
    scanf("%d%d%d",&m,&n,&r);
    struct child childs[n];
    for(int i=0; i<n; i+=1)childs[i].candys.next=NULL,childs[i].candycount=0;
    for(int i=0; i<m; i+=1)
    {
        scanf("%d",&a);
        childs[a].candycount+=1;
        struct candy* c=(struct candy* )malloc(sizeof(struct candy));
        struct candy* p=&childs[a].candys;
        while(p->next)p=p->next;
        p->next=c;
        c->id=i,c->next=NULL;

    }
    for(int i=0; i<r; i+=1)
    {
        scanf("%d%d",&x,&y);
        struct candy* p=childs[x].candys.next;
        childs[x].candys.next=childs[y].candys.next;
        childs[y].candys.next=p;
        a=childs[x].candycount;
        childs[x].candycount=childs[y].candycount;
        childs[y].candycount=a;
    }
    for(int i=0; i<n; i+=1)
    {
        printf("%d  ",childs[i].candycount);
        struct candy* p=childs[i].candys.next;

        while(p)
        {
            printf("%6d ",p->id);
            p=p->next;
        }

    }
    for(int i=0; i<n; i+=1)
    {

        while(childs[a].candys.next)
        {
            struct candy* p=childs[a].candys.next;
            childs[a].candys.next=p->next;
            free(p);
        }
    }
    return 0;
}

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2022-12-10 13:34:46 | 显示全部楼层
共3题
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-12-10 14:49:58 | 显示全部楼层
第二道会了,还有2道,求解
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-12-10 15:37:35 | 显示全部楼层

回帖奖励 +2 鱼币

本帖最后由 zhangjinxuan 于 2022-12-10 15:38 编辑

第一题很简单,就是模拟,最后一道题你可以做一个统计他们武力值的数组
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-12-10 15:46:23 | 显示全部楼层

回帖奖励 +2 鱼币

急啥急,你是人家老板还是人家上辈子欠你啊?
你被回答是你的福气,不是别人的义务,请不要使用“急”“!!!”之类的内容
感谢您对鱼C的支持,相信鱼C的明天会变得更美好
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 2 反对 0

使用道具 举报

发表于 2022-12-10 16:12:47 | 显示全部楼层    本楼为最佳答案   

回帖奖励 +2 鱼币

本帖最后由 jhq999 于 2022-12-10 16:53 编辑

第一题,没样例不知道有没有bug
struct child
{

    int *candys;
    int candycount;

};
int main()
{
    int m,n,r,x,y,a;

    scanf("%d%d%d",&m,&n,&r);
    struct child *childs=(struct child *)calloc(n,sizeof(struct child));
    for(int i=0; i<n; i+=1)
    {
        childs[i].candys=(int*)calloc(m,sizeof(int));
    }
    for(int i=0; i<m; i+=1)
    {
        scanf("%d",&a);
        childs[a].candys[childs[a].candycount]=i;
        childs[a].candycount+=1;


    }
    for(int i=0; i<r; i+=1)
    {
        scanf("%d%d",&x,&y);
        int *tmp=childs[x].candys;
        childs[x].candys=childs[y].candys;
        childs[y].candys=tmp;
        a=childs[x].candycount;
        childs[x].candycount=childs[y].candycount;
        childs[y].candycount=a;
    }
    for(int i=0; i<n; i+=1)
    {
        printf("%d  ",childs[i].candycount);
        for(int j=0;j<childs[i].candycount;j+=1)printf("%6d ",childs[i].candys[j]);
        printf("\n");

    }
    for(int i=0; i<n; i+=1)
    {
        free(childs[i].candys);
    }
    free(childs);
    return 0;
}
#include <stdio.h>
#include<stdlib.h>
struct candy
{
    int id;
    struct candy* next;
};
struct child
{

    struct candy candys;
    int candycount;

};

int main()
{
    int m,n,r,x,y,a;
    scanf("%d%d%d",&m,&n,&r);
    struct child childs[n];
    for(int i=0; i<n; i+=1)childs[i].candys.next=NULL,childs[i].candycount=0;
    for(int i=0; i<m; i+=1)
    {
        scanf("%d",&a);
        childs[a].candycount+=1;
        struct candy* c=(struct candy* )malloc(sizeof(struct candy));
        struct candy* p=&childs[a].candys;
        while(p->next)p=p->next;
        p->next=c;
        c->id=i,c->next=NULL;

    }
    for(int i=0; i<r; i+=1)
    {
        scanf("%d%d",&x,&y);
        struct candy* p=childs[x].candys.next;
        childs[x].candys.next=childs[y].candys.next;
        childs[y].candys.next=p;
        a=childs[x].candycount;
        childs[x].candycount=childs[y].candycount;
        childs[y].candycount=a;
    }
    for(int i=0; i<n; i+=1)
    {
        printf("%d  ",childs[i].candycount);
        struct candy* p=childs[i].candys.next;

        while(p)
        {
            printf("%6d ",p->id);
            p=p->next;
        }

    }
    for(int i=0; i<n; i+=1)
    {

        while(childs[a].candys.next)
        {
            struct candy* p=childs[a].candys.next;
            childs[a].candys.next=p->next;
            free(p);
        }
    }
    return 0;
}

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-12-10 16:53:32 | 显示全部楼层
第三题
int main()
{
    int m,n;
    scanf("%d%d",&n,&m);
    int my[n][m],wlz[m];
    for(int i=0;i<n;i+=1)
        for(int j=0;j<m;j+=1)scanf("%d",&my[i][j]);
    for(int i=0;i<m;i+=1)
    {
        wlz[i]=0;
        int last=my[n-1][i];
        for(int j=0;j<n-1;j+=1)
        {
            if(last==my[j][i])wlz[i]+=1;
        }

    }
    for(int i=0;i<m;i+=1)printf("%d ",wlz[i] );
    return 0;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-12-10 21:35:33 | 显示全部楼层

回帖奖励 +2 鱼币

学习下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-12-10 23:06:06 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-12-10 23:59:32 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-12-11 09:35:57 | 显示全部楼层

回帖奖励 +2 鱼币

学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-12-11 09:55:16 | 显示全部楼层

回帖奖励 +2 鱼币

学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-12-11 16:03:23 | 显示全部楼层

回帖奖励 +2 鱼币

学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-12-11 18:07:59 | 显示全部楼层

回帖奖励 +2 鱼币

学习下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-12-12 09:03:26 | 显示全部楼层
学到了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-12-12 14:34:28 | 显示全部楼层
打扰了 只想领个币
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-20 21:18

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表