求大佬救救孩子

change_2 2021-04-18 08:23:01
萌新真的啥也不会
...全文
2278 32 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
32 条回复
切换为时间正序
请发表友善的回复…
发表回复
源代码大师 2021-04-26
  • 打赏
  • 举报
回复
C和C++ 完整教程:https://blog.csdn.net/it_xiangqiang/category_10581430.html C和C++ 算法完整教程:https://blog.csdn.net/it_xiangqiang/category_10768339.html
mangci331 2021-04-24
  • 打赏
  • 举报
回复
救不了了。。
清风实验室 2021-04-21
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
你这,我看的都不敢学了
真真333 2021-04-21
  • 打赏
  • 举报
回复
引用 11 楼 qzjhjxj 的回复:
抽空写了个,感觉输出时的序号有点想头,供参考:
#include<stdio.h>
#define STUDENTS 10 //按题目要求<10个学生

void  input();
int   sum(int m,int e,int c);
void  sort();
void  print();

typedef struct{ //自定义结构体类型
	int   numcode;
	int   math;
	int   english;
	int   chinese;
    int   sum;
    int   avg;
}STUDENT;

STUDENT student[STUDENTS];//定义10个学生数组
int stu_num;              //学生人数

void main()
{
      input(); //输入
      sort();  //排序,从大到小
      print(); //输出
      //system("pause");
}

void input()
{
     printf("Input students number:");
     scanf("%d",&stu_num);
     if(stu_num >= STUDENTS){
        printf("Please input 1-9.\n");
        exit(0);
     }
     for(int i = 0; i < stu_num; i++){
        scanf("%d %d %d %d", &student[i].numcode,&student[i].math,
                             &student[i].english,&student[i].chinese);
        student[i].sum = sum(student[i].math,student[i].english,student[i].chinese);
        student[i].avg = student[i].sum/3;
     }
}

int sum(int m,int e,int c)
{
     return m+e+c;
}

void sort()
{
      STUDENT temp;
      for (int i = 0; i < stu_num ;i++){
         for (int k = 0; k < stu_num - 1 -i ;k++){
           if(student[k].sum < student[k+1].sum ) {
                  temp        = student[k];
                  student [k] = student[k+1];
                  student[k+1]= temp;
           }
         }
      }
}

void print()
{
     int j=0;
     for(int i = 0; i < stu_num; i++){ //打印输出
       printf("%4d   %10d   %5d   %5d   %5d\n",
           i==0?(j=i+1):(student[i].sum == student[i-1].sum?(j):(j=i+1)),
           student[i].numcode,student[i].math,student[i].english,student[i].chinese);
      }

}

//Input students number:8
//39060405 78 82 69
//39060412 95 85 91
//39060413 95 86 90
//39060415 98 88 85
//39060419 75 89 88
//39060421 89 88 75
//39060425 85 78 93
//39060427 87 92 88
//   1     39060412      95      85      91
//   1     39060413      95      86      90
//   1     39060415      98      88      85
//   4     39060427      87      92      88
//   5     39060425      85      78      93
//   6     39060419      75      89      88
//   6     39060421      89      88      75
//   8     39060405      78      82      69
//请按任意键继续. . .
不错
宾灬 2021-04-20
  • 打赏
  • 举报
回复

#include "stdio.h"
#include "stdlib.h"
/**
 * 学生成绩结构体
 */
typedef struct student_grade{
    char no[10]; //学号
    int mathGrade; //数学成绩
    int enGrade;//英语成绩
    int chGrade;//语文成绩
    int total;//总分
    int avg; //平均分
    int rank; //排名
}StudentGrade;

/**
 * 学生列表
 */
typedef struct student_list{
    StudentGrade * arr[10]; //数组 最大10个
    int n;//学生数量 小于10
}StudentList;

/**
 * 创建 学生
 * @return
 */
static StudentGrade * createStudentGrade();

/**
 * 释放内存
 * @param grade
 */
static void freeStudentGrade(StudentGrade* grade);

/**
 * 创建列表
 * @return
 */
static StudentList * createStudentList(int n);

/**
 * 释放内存
 * @param studentList
 */
static void freeStudentList(StudentList* studentList);


/**
 * 排序
 * @param studentList
 */
static void sortStudentList(StudentList* studentList);

/**
 * 打印学生成绩列表
 * @param studentList
 */
static void printStudentList(StudentList* studentList);


/**
 * 获取输入数字
 * @param min 最小值
 * @param max 最大值
 * @return
 */
static int getNumFromInput(int min, int max);

/**
 * 输入学生成绩
 * @param grade
 */
static void inputStudentGrade(StudentGrade* grade);

/**
 * 程序入口
 * @return
 */
int main(){
    //输入学生人数 1-9
    printf("please input the number of students:\n");
    int n = getNumFromInput(1, 9);
    int i;
    //创建列表
    StudentList * studentList = createStudentList(n);
    for(i = 0; i < n; i++){
        printf("please input the no.%d student's grade\n", i+1);
        //输入成绩
        inputStudentGrade(studentList->arr[i]);
    }
    //排名
    sortStudentList(studentList);
    //打印
    printStudentList(studentList);
    freeStudentList(studentList);
    return 0;
}

/**
 * 创建
 * @return
 */
static StudentGrade * createStudentGrade(){
    return (StudentGrade*)calloc(1, sizeof (StudentGrade));
}

/**
 * 释放内存
 * @param grade
 */
static void freeStudentGrade(StudentGrade* grade){
    free(grade);
}
/**
 * 创建列表
 * @return
 */
static StudentList * createStudentList(int n){
    //分片内存
    StudentList * list = calloc(1, sizeof (StudentList));
    if(n > 10){
        printf("list size must less than 10\n");
        exit(1);
    }
    list->n = n;
    for(int i = 0; i < n; i++){
        //创建学生成绩对象
        list->arr[i] = createStudentGrade();
    }
    return list;
}
/**
 * 排序
 * @param studentList
 */
static void sortStudentList(StudentList* studentList){
    StudentGrade * temp;
    //冒泡排序
    for(int i = 0; i < studentList->n; i++){
        for(int j = 0; j < studentList->n - i -1; j++){
            if(studentList->arr[j]->total < studentList->arr[j+1]->total){
                temp = studentList->arr[j];
                studentList->arr[j] = studentList->arr[j+1];
                studentList->arr[j+1] = temp;
            }
        }
    }
    //设置排名
    int rank = 1;
    studentList->arr[0]->rank = rank++;
    for(int i = 1; i < studentList->n; i++){
        if(studentList->arr[i]->total == studentList->arr[i-1]->total){
            rank--;
        }
        studentList->arr[i]->rank = rank++;
    }
}

/**
 * 释放内存
 * @param studentList
 */
static void freeStudentList(StudentList* studentList){
    for(int i = 0; i < studentList->n; i++){
        //释放学生对象 内存
        freeStudentGrade(studentList->arr[i]);
    }
    //释放列表内存
    free(studentList);
}
/**
 * 获取输入数字
 * @param min 最小值
 * @param max 最大值
 * @return
 */
static int getNumFromInput(int min, int max){
    int n;
    int i;
    while (1){
        i =  scanf("%d", &n);
        if(i == 1 && getchar() == '\n'){
            if(n > max || n < min){
                printf("the number should be %d-%d!\n", min, max);
                continue;
            }
            break;
        }else {
            printf("please input a number!\n");
        }
        while(1)//清空缓存区
        {
            char c = getchar();
            if(c == '\n')
                break;
        }

    }
    return n;
}

/**
 * 输入学生成绩,格式: 学号 数学 英语 语文
 * @param grade
 */
static void inputStudentGrade(StudentGrade* grade){
    scanf("%s %d %d %d", grade->no, &grade->mathGrade, &grade->enGrade,&grade->chGrade);
    grade->total = grade->mathGrade + grade->enGrade + grade->chGrade;
    grade->avg = grade->total/3;
    printf("no:%s, math:%d, en:%d, ch:%d, total:%d, avg:%d\n", grade->no, grade->mathGrade,
           grade->enGrade, grade->chGrade, grade->total, grade->avg);
}
/**
 * 打印学生成绩列表
 * @param studentList
 */
static void printStudentList(StudentList* studentList){
    printf("rank result:\n");
    printf("%4s%10s%5s%5s%5s%10s%5s\n", "rank","no", "math","en", "ch","total", "avg");
    for(int i = 0;i < studentList->n; i++){
        printf("%4d%10s%5d%5d%5d%10d%5d\n",
               studentList->arr[i]->rank,
               studentList->arr[i]->no,
               studentList->arr[i]->mathGrade,
               studentList->arr[i]->enGrade,
               studentList->arr[i]->chGrade,
               studentList->arr[i]->total,
               studentList->arr[i]->avg);
    }
}

yiyoyiyocc 2021-04-20
  • 打赏
  • 举报
回复
我的回复收到了吗?怎么感觉被吞了
加油馒头 2021-04-20
  • 打赏
  • 举报
回复
6666666,我也不会哦
haoge100835 2021-04-20
  • 打赏
  • 举报
回复
大兄弟啊,你还是不适合编程呢
change_2 2021-04-19
  • 打赏
  • 举报
回复
引用 7 楼 自信男孩的回复:
[quote=引用 6 楼 change_2 的回复:][quote=引用 5 楼 change_2的回复:][quote=引用 4 楼 自信男孩的回复:][quote=引用 3 楼 change_2 的回复:][quote=引用 2 楼 自信男孩的回复:]做不出来,是一条代码都写不出来吗?现在哭好像没啥用,学习的时候着急,应该学的就会很认真了。

先自己写写吧,或者参考一下网上的代码,自己改改。什么都不做,就要调试好的,不现实~

是的,是一条代码也不会写,专业不需要这个,只学一学期,网上找的是错的[/quote]
是错的描述,意思是不满足你的要求吧,还是网上的代码本身就有问题?
我想不会每个代码都是自身有问题的吧[/quote]
编译运行的时候出错了,运行不了[/quote]
就是这个论坛的代码,编译运行时错误[/quote]
编译和运行的错误是两个独立的错误,先确定是编译出错,还是运行出错。另外,代码也得贴出来呀~[/quote] 这个代码提示编译错误,还有我想把里面关于姓名的东西给删掉,怎么删?
change_2 2021-04-19
  • 打赏
  • 举报
回复
引用 7 楼 自信男孩的回复:
[quote=引用 6 楼 change_2 的回复:][quote=引用 5 楼 change_2的回复:][quote=引用 4 楼 自信男孩的回复:][quote=引用 3 楼 change_2 的回复:][quote=引用 2 楼 自信男孩的回复:]做不出来,是一条代码都写不出来吗?现在哭好像没啥用,学习的时候着急,应该学的就会很认真了。

先自己写写吧,或者参考一下网上的代码,自己改改。什么都不做,就要调试好的,不现实~

是的,是一条代码也不会写,专业不需要这个,只学一学期,网上找的是错的[/quote]
是错的描述,意思是不满足你的要求吧,还是网上的代码本身就有问题?
我想不会每个代码都是自身有问题的吧[/quote]
编译运行的时候出错了,运行不了[/quote]
就是这个论坛的代码,编译运行时错误[/quote]
编译和运行的错误是两个独立的错误,先确定是编译出错,还是运行出错。另外,代码也得贴出来呀~[/quote] #include <stdio.h> #include <stdlib.h> #include <string.h> #define N 10 typedef struct Students { int id; char name[10]; int math; int en; int ch; }STU; STU stu[N]; void sortInfo(STU stu[], int n); void swapInfo(STU *p, STU *q); int main() { int n = 10, m = 0, w = 1; scanf("%d", &n); if (n>9||n<1) { printf("Please input 1-9."); return 0; } for (int i = 0; i<n; i++) { scanf("%d%s%d%d%d", &stu[i].id, &stu[i].name, &stu[i].math, &stu[i].en, &stu[i].ch); } sortInfo(stu, n); for (int i = 0; i < n; i++) { if (i >0) { if ((stu[i].en + stu[i].ch + stu[i].math) == (stu[i - 1].en + stu[i - 1].ch + stu[i - 1].math)) { m++; printf("%4d", w - m); } else { printf("%4d", w); m = 0; } } else { printf("%d", w); } printf("%10d%10s%5d%5d%5d\n", stu[i].id, stu[i].name, stu[i].math, stu[i].en, stu[i].ch); w++; } return 0; } void sortInfo(STU stu[], int n) { int i, j; for (i = 0; i < n - 1; i++) { for (j = 0; j < n - 1 - i; j++) { int a = stu[j].en + stu[j].ch + stu[j].math, b = stu[j + 1].en + stu[j + 1].ch + stu[j + 1].math; if (a<b) { swapInfo(&stu[j], &stu[j + 1]); } else if ((a == b) && (stu[j].id >stu[j + 1].id)) { swapInfo(&stu[j], &stu[j + 1]); } } } } void swapInfo(STU *p, STU *q) { STU trmp; trmp = *p; *p = *q; *q = trmp; }
qq_38292437 2021-04-19
  • 打赏
  • 举报
回复
6666666,我也不会哦
自信男孩 2021-04-19
  • 打赏
  • 举报
回复
引用 6 楼 change_2 的回复:
[quote=引用 5 楼 change_2的回复:][quote=引用 4 楼 自信男孩的回复:][quote=引用 3 楼 change_2 的回复:][quote=引用 2 楼 自信男孩的回复:]做不出来,是一条代码都写不出来吗?现在哭好像没啥用,学习的时候着急,应该学的就会很认真了。

先自己写写吧,或者参考一下网上的代码,自己改改。什么都不做,就要调试好的,不现实~

是的,是一条代码也不会写,专业不需要这个,只学一学期,网上找的是错的[/quote]
是错的描述,意思是不满足你的要求吧,还是网上的代码本身就有问题?
我想不会每个代码都是自身有问题的吧[/quote]
编译运行的时候出错了,运行不了[/quote]
就是这个论坛的代码,编译运行时错误[/quote]
编译和运行的错误是两个独立的错误,先确定是编译出错,还是运行出错。另外,代码也得贴出来呀~
change_2 2021-04-19
  • 打赏
  • 举报
回复
引用 5 楼 change_2的回复:
[quote=引用 4 楼 自信男孩的回复:][quote=引用 3 楼 change_2 的回复:][quote=引用 2 楼 自信男孩的回复:]做不出来,是一条代码都写不出来吗?现在哭好像没啥用,学习的时候着急,应该学的就会很认真了。

先自己写写吧,或者参考一下网上的代码,自己改改。什么都不做,就要调试好的,不现实~

是的,是一条代码也不会写,专业不需要这个,只学一学期,网上找的是错的[/quote]
是错的描述,意思是不满足你的要求吧,还是网上的代码本身就有问题?
我想不会每个代码都是自身有问题的吧[/quote] 编译运行的时候出错了,运行不了[/quote] 就是这个论坛的代码,编译运行时错误
change_2 2021-04-19
  • 打赏
  • 举报
回复
引用 4 楼 自信男孩的回复:
[quote=引用 3 楼 change_2 的回复:][quote=引用 2 楼 自信男孩的回复:]做不出来,是一条代码都写不出来吗?现在哭好像没啥用,学习的时候着急,应该学的就会很认真了。

先自己写写吧,或者参考一下网上的代码,自己改改。什么都不做,就要调试好的,不现实~

是的,是一条代码也不会写,专业不需要这个,只学一学期,网上找的是错的[/quote]
是错的描述,意思是不满足你的要求吧,还是网上的代码本身就有问题?
我想不会每个代码都是自身有问题的吧[/quote] 编译运行的时候出错了,运行不了
自信男孩 2021-04-19
  • 打赏
  • 举报
回复
引用 3 楼 change_2 的回复:
[quote=引用 2 楼 自信男孩的回复:]做不出来,是一条代码都写不出来吗?现在哭好像没啥用,学习的时候着急,应该学的就会很认真了。

先自己写写吧,或者参考一下网上的代码,自己改改。什么都不做,就要调试好的,不现实~

是的,是一条代码也不会写,专业不需要这个,只学一学期,网上找的是错的[/quote]
是错的描述,意思是不满足你的要求吧,还是网上的代码本身就有问题?
我想不会每个代码都是自身有问题的吧
change_2 2021-04-19
  • 打赏
  • 举报
回复
引用 2 楼 自信男孩的回复:
做不出来,是一条代码都写不出来吗?现在哭好像没啥用,学习的时候着急,应该学的就会很认真了。

先自己写写吧,或者参考一下网上的代码,自己改改。什么都不做,就要调试好的,不现实~
是的,是一条代码也不会写,专业不需要这个,只学一学期,网上找的是错的
自信男孩 2021-04-19
  • 打赏
  • 举报
回复
做不出来,是一条代码都写不出来吗?现在哭好像没啥用,学习的时候着急,应该学的就会很认真了。

先自己写写吧,或者参考一下网上的代码,自己改改。什么都不做,就要调试好的,不现实~
Open开袁 2021-04-19
  • 打赏
  • 举报
回复
这个不是很难
qzjhjxj 2021-04-19
  • 打赏
  • 举报
回复
把上面的代码复制,点左上角红圈的地方就可以复制,然后再粘贴到你的编译器里。
加载更多回复(12)

70,024

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧