17070047 / 17070047/CodeStructureCourse

解宇飞

未關閉
#84 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
C++
星號
16
分支
2
PR 合併指標
30 天內沒有已合併 PR

描述

```c
#include
using namespace std;
const int maxn = 10000 + 10;
struct Node
{
int department;//院号
int number;//借书证卡号
char name[maxn];//姓名
char student_id[maxn];//学号
};
Node a[maxn];
void quicksort(Node a[], int left, int right)//按照卡号进行排名
{
int i, j;
if (left >= right)
return;

i = left, j = right;
a[0] = a[i];
while (i != j)
{
while (a[j].number > a[0].number && i < j)
--j;
if (i < j)
{
a[i] = a[j];
i++;
}
while (a[i].number < a[0].number && i < j)
++i;
if (i < j)
{
a[j] = a[i];
j--;
}
}
a[i] = a[0];
quicksort(a, left, i - 1);
quicksort(a, i + 1, right);

}

void bin_search(Node a[], int n, int x)
{
int left = 1, right = n;
int ans = 0;
while (left <= right)
{
int mid = (left + right) / 2;
if (a[mid].department == x)
{
ans = mid;
break;
}
else if (a[mid].department < x)
{
left = mid + 1;
}
else
{
right = mid - 1;
}
}
if (!ans)
{
printf("没找到\n");
}
else
{
int start = ans, ends = ans;
while (a[start].department == x)
start--;
while (a[ends].department == x)
ends++;
printf("%d院的信息为:\n", x);
for (int i = start + 1; i < ends; i++)
{
printf("%d %d %s %s\n", a[i].department, a[i].number, a[i].name, a[i].student_id);
}
}
}
int main()
{
int n;
int i;
printf("请输入信息系统学生的个数:\n");
scanf("%d", &n);
printf("请输入学生学院号、卡号、姓名、学号:\n");
for (i = 1; i <= n; i++)
{
scanf("%d%d%s%s", &(a[i].department), &a[i].number, &a[i].name, &a[i].student_id);
}
quicksort(a, 1, n);
printf("按照卡号顺序输出学生信息:\n");
for (i = 1; i <= n; i++)
{
printf("%d %d %s %s\n", a[i].department, a[i].number, a[i].name, a[i].student_id);
}
int x;
printf("请输入要查找的学院号:\n");
scanf("%d", &x);
bin_search(a, n, x);
return 0;
}
```

![default](https://user-images.githubusercontent.com/45333717/49681036-689f0f00-fad6-11e8-97c7-a74c62c982cd.PNG)

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

The issue contains a C program with a quicksort and binary search for student records. The problem is not described; the image link is broken. To start, examine the code for logical errors, such as off-by-one indexing (arrays start at 1) or incorrect binary search on unsorted department field. Run the program with sample input to see if it crashes or produces wrong output. Check the repository for similar programs or assignment instructions to understand the expected behavior.

由索引模型根據 Issue 內容生成。

評估

技術堆疊
c, cpp
領域
cli
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
需要釐清
新手友好度
20/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。