老冉


私信TA

用户名:rgq673227233

访问量:2506

签 名:

等  级
排  名 11519
经  验 969
参赛次数 0
文章发表 4
年  龄 0
在职情况 学生
学  校 中国人民大学
专  业

  自我简介:


解题思路:





注意事项:





参考代码:

#include <stdio.h>
#include <stdlib.h>
struct students{
    char number[100];
    char name[100];
    int score1,score2,score3;
};

void input(struct students* p,int n)
{
    int i,t;
    for(i=0;i<n;i++){
        t=0;
        do{
            scanf("%c",((p+i)->number)+t);
            t++;
        }while(((p+i)->number[t-1])!=' ');
        ((p+i)->number[t-1])='\0';
        t=0;
        do{
            scanf("%c",((p+i)->name)+t);
            t++;
        }while(((p+i)->name[t-1])!=' ');
        ((p+i)->name[t-1])='\0';
        scanf("%d",&((p+i)->score1));
        scanf("%d",&((p+i)->score2));
        scanf("%d",&((p+i)->score3));
    }
}

void print(struct students* p,int n)
{
    int i;
    for(i=0;i<n;i++){
        printf("%s,%s,%d,%d,%d\n",
        (p+i)->number+1,//去回车
        (p+i)->name,
        (p+i)->score1,
        (p+i)->score2,
        (p+i)->score3);
    }
}
int main(int argc, char **argv)
{
    int n;
    scanf("%d",&n);
    struct students *a=(struct students*)malloc(n*(sizeof(struct students)));
    input(a,n);
    print(a,n);
	return 0;
}


 

0.0分

3 人评分

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

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区

这个思路是真厉害
2021-01-28 15:43:15
  • «
  • 1
  • »