求解,急!
c++ 共3题 第二道会了,还有2道,求解{:10_266:} 本帖最后由 zhangjinxuan 于 2022-12-10 15:38 编辑
第一题很简单,就是模拟,最后一道题你可以做一个统计他们武力值的数组 急啥急,你是人家老板还是人家上辈子欠你啊?
你被回答是你的福气,不是别人的义务,请不要使用“急”“!!!”之类的内容
感谢您对鱼C的支持,相信鱼C的明天会变得更美好 本帖最后由 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.candys=(int*)calloc(m,sizeof(int));
}
for(int i=0; i<m; i+=1)
{
scanf("%d",&a);
childs.candys.candycount]=i;
childs.candycount+=1;
}
for(int i=0; i<r; i+=1)
{
scanf("%d%d",&x,&y);
int *tmp=childs.candys;
childs.candys=childs.candys;
childs.candys=tmp;
a=childs.candycount;
childs.candycount=childs.candycount;
childs.candycount=a;
}
for(int i=0; i<n; i+=1)
{
printf("%d",childs.candycount);
for(int j=0;j<childs.candycount;j+=1)printf("%6d ",childs.candys);
printf("\n");
}
for(int i=0; i<n; i+=1)
{
free(childs.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;
for(int i=0; i<n; i+=1)childs.candys.next=NULL,childs.candycount=0;
for(int i=0; i<m; i+=1)
{
scanf("%d",&a);
childs.candycount+=1;
struct candy* c=(struct candy* )malloc(sizeof(struct candy));
struct candy* p=&childs.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.candys.next;
childs.candys.next=childs.candys.next;
childs.candys.next=p;
a=childs.candycount;
childs.candycount=childs.candycount;
childs.candycount=a;
}
for(int i=0; i<n; i+=1)
{
printf("%d",childs.candycount);
struct candy* p=childs.candys.next;
while(p)
{
printf("%6d ",p->id);
p=p->next;
}
}
for(int i=0; i<n; i+=1)
{
while(childs.candys.next)
{
struct candy* p=childs.candys.next;
childs.candys.next=p->next;
free(p);
}
}
return 0;
}
第三题
int main()
{
int m,n;
scanf("%d%d",&n,&m);
int my,wlz;
for(int i=0;i<n;i+=1)
for(int j=0;j<m;j+=1)scanf("%d",&my);
for(int i=0;i<m;i+=1)
{
wlz=0;
int last=my;
for(int j=0;j<n-1;j+=1)
{
if(last==my)wlz+=1;
}
}
for(int i=0;i<m;i+=1)printf("%d ",wlz );
return 0;
}
学习下 {:10_261:} {:5_108:} 学习 学习 学习 学习下 学到了 打扰了 只想领个币
页:
[1]