lyh_de_father 2021-04-28 14:38 采纳率: 0%
浏览 30

xcode跑c语言程序出现(lldb)

我在跑下面的代码的sort()时出现了题目中的问题,网上的关于这个问题的讨论我看不懂,求大神帮我看看到底是为什么,我其他的函数都好好的。

//
//  main.c
//  202011059231_苏楚阳_大作业2
//
//  Created by Schuyn on 2021/4/28.
//
#include <stdio.h>
#include <string.h>
#define N 106
#define M 29
#define ull unsigned long long
#define ll long long
char no[N][100001],name[N][9],subject[M][20],place_no[N][100001],place_name[N][100001];
char choice,choice_query;
int score[N][M],tot_score[N],mmax[N],mmin[N],place_tot[N],place_score[N][M];
double ave_score[N],place_ave[N];
int people=0,course=0,tm=0;

void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}

void swap_dbl(double *a,double *b){
    double t=*a;
    *a=*b;
    *b=t;
}

void quicksort(int l,int r,int sbj){
    int i=l,j=r;
    int mid=place_score[(l+r)>>1][sbj];
    while(i<=j){
        while(place_score[i][sbj]<mid)
            i++;
        while(place_score[j][sbj]>mid)
            j--;
        if(i<=j){
            swap(&place_score[i++][sbj],&place_score[j--][sbj]);
        }
        if(i<r)
            quicksort(i, r, sbj);
        if(j>l)
            quicksort(l, j, sbj);
    }
}

void quicksort_tot(int l,int r){
    int i=l,j=r;
    int mid=place_tot[(l+r)>>1];
    while(i<=j){
        while(place_tot[i]<mid)
            i++;
        while(place_tot[j]>mid)
            j--;
        if(i<=j){
            swap(&place_tot[i++],&place_tot[j--]);
        }
        if(i<r)
            quicksort_tot(i,r);
        if(j>l)
            quicksort_tot(l,j);
    }
}

void quicksort_ave(int l,int r){
    int i=l,j=r;
    double mid=place_ave[(l+r)>>1];
    while(i<=j){
        while(place_ave[i]<mid)
            i++;
        while(place_ave[j]>mid)
            j--;
        if(i<=j){
            swap_dbl(&place_ave[i++],&place_ave[j--]);
        }
        if(i<r)
            quicksort_ave(i,r);
        if(j>l)
            quicksort_ave(l,j);
    }
}

void put(void){
    int t,sum=0;
    printf("请输入学号:\n");
    scanf("%s",no[++people]);
    strcpy(place_no[people], no[people]);
    printf("请输入姓名:\n");
    scanf("%s",name[people]);
    strcpy(place_name[people], name[people]);
    putchar('\n');
    printf("请问共有几个科目?\n");
    scanf("%d",&course);
    printf("各科目及其分数:\n");
    for(int i=1;i<=course;i++){
        scanf("%s",subject[i]);
        scanf("%d",&t);
        sum+=t;
        score[people][i]=t;
        place_score[people][i]=t;
        if(t>=mmax[people])
            mmax[people]=t;
        if(t<=mmin[people])
            mmin[people]=t;
    }
    tot_score[people]=sum;
    ave_score[people]=(sum/course);
    place_tot[people]=sum;
    place_ave[people]=ave_score[people];
}

void sort(void){
   if((!people)||(!course)){
        printf("尚无数据,请先输入或退出\n");
        return;
    }
    tm++;
    char choice1;
    char a[N][100001];
    ull n=strlen(place_no[1]);
    printf("你希望以哪种方式排序?\n1.学号\n2.姓名\n3.某门课程分数\n4.总分\n5.平均分\n0.退出\n");
    scanf(" %c",&choice1);
    if(choice1=='1'){
        for(int i=1;i<=people;i++){
            for(int j=1;j<=people-i;j++){
                if(strcmp(place_no[i],place_no[i+1])>0){
                    for(int k=0;k<n;k++)
                        a[j][k]=place_no[j][k];
                    for(int k=0;k<n;k++)
                        place_no[j][k]=place_no[j+1][k];
                    for(int k=0;k<n;k++)
                        place_no[j+1][k]=a[j][k];
                }
            }
        }
        printf("排序已完成\n");
        return;
    }
    else if(choice1=='2'){
        for(int i=1;i<=people;i++){
            for(int j=1;j<=people-i;j++){
                if(strcmp(place_name[i],place_name[i+1])>0){
                    for(int k=0;k<n;k++)
                        a[j][k]=place_name[j][k];
                    for(int k=0;k<n;k++)
                        place_name[j][k]=place_name[j+1][k];
                    for(int k=0;k<n;k++)
                        place_name[j+1][k]=a[j][k];
                }
            }
        }
        printf("排序已完成\n");
        return;
    }
    else if(choice1=='3'){
        int tm=0;
        char chs[M][100001];
        int sbj=course;
        printf("请输入科目\n");
        scanf("%s",chs[++tm]);
        for(int i=1;i<=course;i++)
            if(strcmp(subject[i], chs[tm])==0)
                sbj=i;
        quicksort(1, people, sbj);
        printf("排序已完成\n");
        return;
    }
    else if(choice1=='4'){
        quicksort_tot(1, people);
        printf("排序已完成\n");
        return;
    }
    else if(choice1=='5'){
        quicksort_ave(1, people);
        printf("排序已完成\n");
        return;
    }
    else if(choice1=='0')
        return;
    else{
        printf("选择菜单号错,重新输入\n");
        return;
    }
}

void query(void){
    if((!people)||(!course)){
        printf("尚无数据,请先输入或退出\n");
        return;
    }
    char choice1;
    int tmp=people;
    char whatever[N];
    double whatevr;
    printf("您希望按哪种方式查询?\n1.按学号\n2.按姓名\n3.按平均分\n4.按总分\n0.返回上一层\n");
    scanf(" %c",&choice1);
    if(choice1=='1'){
        printf("请输入学号:");
        scanf("%s",whatever);
        for(int i=1;i<=people;i++){
            if(no[i]==whatever)
                tmp=i;
        }
    }
    else if (choice1=='2'){
        printf("请输入姓名:");
        scanf("%s",whatever);
        for(int i=1;i<=people;i++){
            if(name[i]==whatever)
                tmp=i;
        }
    }
    else if (choice1=='3'){
        printf("请输入平均分:");
        scanf("%lf",&whatevr);
        for(int i=1;i<=people;i++){
            if(ave_score[i]==whatevr){
                if(tmp!=people){
                    printf("查询到重复,请使用其他查询方式\n");
                    break;
                }
                tmp=i;
            }
        }
    }
    else if (choice1=='4'){
        printf("请输入总分:");
        scanf("%lf",&whatevr);
        for(int i=1;i<=people;i++){
            if(tot_score[i]==whatevr){
                if(tmp!=people){
                    printf("查询到重复,请使用其他查询方式\n");
                    break;
                }
                tmp=i;
            }
        }
    }
    printf("请问您想要查询什么?\n");
    while(1){
        printf("1.各科分数\n");
        printf("2.平均分\n");
        printf("3.总分\n");
        printf("4.最高分\n");
        printf("5.最低分\n");
        printf("6.总分数排名\n");
        printf("7.科目分数排名\n");
        printf("0.返回上一级\n");
        printf("输入菜单号:");
        scanf(" %c",&choice_query);
        switch(choice_query){
            case '1':{
                for(int i=1;i<=course;i++){
                    printf("您的%s的成绩是%d\n",subject[i],score[tmp][i]);
                }
                break;
            }
            case '2':{
                printf("您的平均分是%lf\n",ave_score[tmp]);
                break;
            }
            case '3':{
                printf("您的总成绩是%d\n",tot_score[tmp]);
                break;
            }
            case '4':{
                printf("您的最高分是%d\n",mmax[tmp]);
                break;
            }
            case '5':{
                printf("您的最低分是%d\n",mmin[tmp]);
                break;
            }
            case '6':{
                if(!tm){
                    printf("请先排序\n");
                    break;
                }
                for(int i=people;i>0;i--){
                    if(place_tot[i]==tot_score[tmp])
                        printf("您的总分数排名是%d\n",people-i+1);
                }
                break;
            }
            case '7':{
                if(!tm){
                    printf("请先排序\n");
                    break;
                }
                int t=course;
                char whtever[10001];
                printf("请问您想要查询哪科分数?\n");
                scanf("%s",whtever);
                for(int i=1;i<=course;i++)
                    if(subject[i]==whtever)
                        t=i;
                for(int i=people;i>0;i--){
                    if(place_score[i][t]==score[tmp][t])
                        printf("您的%s的分数排名是%d\n",whtever,people-i+1);
                }
                break;
            }
            case '0':
                return;
            default:
                printf("选择菜单号错,重新输入\n");
      }
    }
    
}

void display(void){
    if((!people)||(!course)){
        printf("尚无数据,请先输入或退出\n");
        return;
    }
    int t1=people,t2=course;
    while(t1){
        printf("学号:%s 姓名:%s 总分:%d 平均分:%lf\n",no[t1],name[t1],tot_score[t1],ave_score[t1]);
        while(t2){
            printf("学科:%s的成绩为:%d分\n",subject[t2],score[t1][t2]);
            t2--;
        }
        if(!tm){
            printf("请先排序\n");
            return;
        }//判断是否排序,若没有则直接退出
        else{
            for(int i=people;i>0;i--){
                if(place_tot[i]==tot_score[t1])
                    printf("您的分数排名为%d\n",people-i+1);
            }
            for(int i=course;i>0;i--){
                for(int j=people;j>0;j--){
                    if(place_score[j][i]==score[t1][t2])
                        printf("您%s的排名是%d\n",subject[i],people-j+1);
                }
            }
            t1--;
        }
    }
}

int main(int argc, const char * argv[]) {
    memset(tot_score,0,N);
    memset(mmax,0,N);
    memset(mmin,1000,N);
    while(1){
        printf("1.输入\n");
        printf("2.查询\n");
        printf("3.显示\n");
        printf("4.排序\n");
        printf("0.退出\n");
        printf("输入菜单号:");
        scanf(" %c",&choice);
        switch(choice){
            case '1':
                put();//输入
                break;
            case '2':
                query();//查询,可查询各科分数、总分、平均分、最高分、最低分、总分数排名和各科分数排名
                break;
            case '3':
                display();//输出每名学生的学号、姓名、总分、平均分、各科成绩、总分数排名和各科分数排名
                break;
            case '4':{
                //printf("%d\n",course);
                sort();//排序,有按学号、姓名、某科分数、总分和平均分排序
                break;
            }
            case '0':
                break;
            default:
                printf("选择菜单号错,重新输入\n");
      }/* switch 语句结束 */
      if (choice == '0')
          break;
    }
    printf("Hello, World!\n");
    return 0;
}
  • 写回答

4条回答 默认 最新

  • 关注

    没有看到你的错误提示呀,把运行错误的信息贴出来看看。

    评论

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制