鱼C论坛

 找回密码
 立即注册
查看: 2910|回复: 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
  1. struct child
  2. {

  3.     int *candys;
  4.     int candycount;

  5. };
  6. int main()
  7. {
  8.     int m,n,r,x,y,a;

  9.     scanf("%d%d%d",&m,&n,&r);
  10.     struct child *childs=(struct child *)calloc(n,sizeof(struct child));
  11.     for(int i=0; i<n; i+=1)
  12.     {
  13.         childs[i].candys=(int*)calloc(m,sizeof(int));
  14.     }
  15.     for(int i=0; i<m; i+=1)
  16.     {
  17.         scanf("%d",&a);
  18.         childs[a].candys[childs[a].candycount]=i;
  19.         childs[a].candycount+=1;


  20.     }
  21.     for(int i=0; i<r; i+=1)
  22.     {
  23.         scanf("%d%d",&x,&y);
  24.         int *tmp=childs[x].candys;
  25.         childs[x].candys=childs[y].candys;
  26.         childs[y].candys=tmp;
  27.         a=childs[x].candycount;
  28.         childs[x].candycount=childs[y].candycount;
  29.         childs[y].candycount=a;
  30.     }
  31.     for(int i=0; i<n; i+=1)
  32.     {
  33.         printf("%d  ",childs[i].candycount);
  34.         for(int j=0;j<childs[i].candycount;j+=1)printf("%6d ",childs[i].candys[j]);
  35.         printf("\n");

  36.     }
  37.     for(int i=0; i<n; i+=1)
  38.     {
  39.         free(childs[i].candys);
  40.     }
  41.     free(childs);
  42.     return 0;
  43. }
复制代码
  1. #include <stdio.h>
  2. #include<stdlib.h>
  3. struct candy
  4. {
  5.     int id;
  6.     struct candy* next;
  7. };
  8. struct child
  9. {

  10.     struct candy candys;
  11.     int candycount;

  12. };

  13. int main()
  14. {
  15.     int m,n,r,x,y,a;
  16.     scanf("%d%d%d",&m,&n,&r);
  17.     struct child childs[n];
  18.     for(int i=0; i<n; i+=1)childs[i].candys.next=NULL,childs[i].candycount=0;
  19.     for(int i=0; i<m; i+=1)
  20.     {
  21.         scanf("%d",&a);
  22.         childs[a].candycount+=1;
  23.         struct candy* c=(struct candy* )malloc(sizeof(struct candy));
  24.         struct candy* p=&childs[a].candys;
  25.         while(p->next)p=p->next;
  26.         p->next=c;
  27.         c->id=i,c->next=NULL;

  28.     }
  29.     for(int i=0; i<r; i+=1)
  30.     {
  31.         scanf("%d%d",&x,&y);
  32.         struct candy* p=childs[x].candys.next;
  33.         childs[x].candys.next=childs[y].candys.next;
  34.         childs[y].candys.next=p;
  35.         a=childs[x].candycount;
  36.         childs[x].candycount=childs[y].candycount;
  37.         childs[y].candycount=a;
  38.     }
  39.     for(int i=0; i<n; i+=1)
  40.     {
  41.         printf("%d  ",childs[i].candycount);
  42.         struct candy* p=childs[i].candys.next;

  43.         while(p)
  44.         {
  45.             printf("%6d ",p->id);
  46.             p=p->next;
  47.         }

  48.     }
  49.     for(int i=0; i<n; i+=1)
  50.     {

  51.         while(childs[a].candys.next)
  52.         {
  53.             struct candy* p=childs[a].candys.next;
  54.             childs[a].candys.next=p->next;
  55.             free(p);
  56.         }
  57.     }
  58.     return 0;
  59. }
复制代码


小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2022-12-10 13:34:46 | 显示全部楼层
共3题
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-12-10 14:49:58 | 显示全部楼层
第二道会了,还有2道,求解
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

回帖奖励 +2 鱼币

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

第一题很简单,就是模拟,最后一道题你可以做一个统计他们武力值的数组
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

回帖奖励 +2 鱼币

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

使用道具 举报

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

回帖奖励 +2 鱼币

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

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

  3.     int *candys;
  4.     int candycount;

  5. };
  6. int main()
  7. {
  8.     int m,n,r,x,y,a;

  9.     scanf("%d%d%d",&m,&n,&r);
  10.     struct child *childs=(struct child *)calloc(n,sizeof(struct child));
  11.     for(int i=0; i<n; i+=1)
  12.     {
  13.         childs[i].candys=(int*)calloc(m,sizeof(int));
  14.     }
  15.     for(int i=0; i<m; i+=1)
  16.     {
  17.         scanf("%d",&a);
  18.         childs[a].candys[childs[a].candycount]=i;
  19.         childs[a].candycount+=1;


  20.     }
  21.     for(int i=0; i<r; i+=1)
  22.     {
  23.         scanf("%d%d",&x,&y);
  24.         int *tmp=childs[x].candys;
  25.         childs[x].candys=childs[y].candys;
  26.         childs[y].candys=tmp;
  27.         a=childs[x].candycount;
  28.         childs[x].candycount=childs[y].candycount;
  29.         childs[y].candycount=a;
  30.     }
  31.     for(int i=0; i<n; i+=1)
  32.     {
  33.         printf("%d  ",childs[i].candycount);
  34.         for(int j=0;j<childs[i].candycount;j+=1)printf("%6d ",childs[i].candys[j]);
  35.         printf("\n");

  36.     }
  37.     for(int i=0; i<n; i+=1)
  38.     {
  39.         free(childs[i].candys);
  40.     }
  41.     free(childs);
  42.     return 0;
  43. }
复制代码
  1. #include <stdio.h>
  2. #include<stdlib.h>
  3. struct candy
  4. {
  5.     int id;
  6.     struct candy* next;
  7. };
  8. struct child
  9. {

  10.     struct candy candys;
  11.     int candycount;

  12. };

  13. int main()
  14. {
  15.     int m,n,r,x,y,a;
  16.     scanf("%d%d%d",&m,&n,&r);
  17.     struct child childs[n];
  18.     for(int i=0; i<n; i+=1)childs[i].candys.next=NULL,childs[i].candycount=0;
  19.     for(int i=0; i<m; i+=1)
  20.     {
  21.         scanf("%d",&a);
  22.         childs[a].candycount+=1;
  23.         struct candy* c=(struct candy* )malloc(sizeof(struct candy));
  24.         struct candy* p=&childs[a].candys;
  25.         while(p->next)p=p->next;
  26.         p->next=c;
  27.         c->id=i,c->next=NULL;

  28.     }
  29.     for(int i=0; i<r; i+=1)
  30.     {
  31.         scanf("%d%d",&x,&y);
  32.         struct candy* p=childs[x].candys.next;
  33.         childs[x].candys.next=childs[y].candys.next;
  34.         childs[y].candys.next=p;
  35.         a=childs[x].candycount;
  36.         childs[x].candycount=childs[y].candycount;
  37.         childs[y].candycount=a;
  38.     }
  39.     for(int i=0; i<n; i+=1)
  40.     {
  41.         printf("%d  ",childs[i].candycount);
  42.         struct candy* p=childs[i].candys.next;

  43.         while(p)
  44.         {
  45.             printf("%6d ",p->id);
  46.             p=p->next;
  47.         }

  48.     }
  49.     for(int i=0; i<n; i+=1)
  50.     {

  51.         while(childs[a].candys.next)
  52.         {
  53.             struct candy* p=childs[a].candys.next;
  54.             childs[a].candys.next=p->next;
  55.             free(p);
  56.         }
  57.     }
  58.     return 0;
  59. }
复制代码


小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-12-10 16:53:32 | 显示全部楼层
第三题
  1. int main()
  2. {
  3.     int m,n;
  4.     scanf("%d%d",&n,&m);
  5.     int my[n][m],wlz[m];
  6.     for(int i=0;i<n;i+=1)
  7.         for(int j=0;j<m;j+=1)scanf("%d",&my[i][j]);
  8.     for(int i=0;i<m;i+=1)
  9.     {
  10.         wlz[i]=0;
  11.         int last=my[n-1][i];
  12.         for(int j=0;j<n-1;j+=1)
  13.         {
  14.             if(last==my[j][i])wlz[i]+=1;
  15.         }

  16.     }
  17.     for(int i=0;i<m;i+=1)printf("%d ",wlz[i] );
  18.     return 0;
  19. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

回帖奖励 +2 鱼币

学习下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

回帖奖励 +2 鱼币

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

回帖奖励 +2 鱼币

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

回帖奖励 +2 鱼币

学习
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

回帖奖励 +2 鱼币

学习
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

回帖奖励 +2 鱼币

学习
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

回帖奖励 +2 鱼币

学习下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-12-12 09:03:26 | 显示全部楼层
学到了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-12-12 14:34:28 | 显示全部楼层
打扰了 只想领个币
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-22 22:47

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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