{"action":"opened","issue":{"url":"https://api.github.com/repos/17070047/CodeStructureCourse/issues/101","repository_url":"https://api.github.com/repos/17070047/CodeStructureCourse","labels_url":"https://api.github.com/repos/17070047/CodeStructureCourse/issues/101/labels{/name}","comments_url":"https://api.github.com/repos/17070047/CodeStructureCourse/issues/101/comments","events_url":"https://api.github.com/repos/17070047/CodeStructureCourse/issues/101/events","html_url":"https://github.com/17070047/CodeStructureCourse/issues/101","id":392183716,"node_id":"MDU6SXNzdWUzOTIxODM3MTY=","number":101,"title":"丁逸群 17","user":{"login":"DingYiQunsmile","id":45334855,"node_id":"MDQ6VXNlcjQ1MzM0ODU1","avatar_url":"https://avatars1.githubusercontent.com/u/45334855?v=4","gravatar_id":"","url":"https://api.github.com/users/DingYiQunsmile","html_url":"https://github.com/DingYiQunsmile","followers_url":"https://api.github.com/users/DingYiQunsmile/followers","following_url":"https://api.github.com/users/DingYiQunsmile/following{/other_user}","gists_url":"https://api.github.com/users/DingYiQunsmile/gists{/gist_id}","starred_url":"https://api.github.com/users/DingYiQunsmile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DingYiQunsmile/subscriptions","organizations_url":"https://api.github.com/users/DingYiQunsmile/orgs","repos_url":"https://api.github.com/users/DingYiQunsmile/repos","events_url":"https://api.github.com/users/DingYiQunsmile/events{/privacy}","received_events_url":"https://api.github.com/users/DingYiQunsmile/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-12-18T14:34:43Z","updated_at":"2018-12-18T14:34:43Z","closed_at":null,"author_association":"NONE","body":"```c\r\n#include\"stdio.h\"\r\n#include\"stdlib.h\"\r\n#include\"string.h\"\r\n#define MAXSIZE 100\r\ntypedef struct {\r\n\tchar cardnum[30];\r\n\tchar id[25];\r\n\tchar name[30];\r\n\tchar specialty[30];\r\n\tchar classnum[30];\r\n}stu;\r\ntypedef struct{\r\n\tstu r[MAXSIZE];\r\n\tint length;\r\n}table;\r\n\r\nvoid create(table *tab,char *filename)\r\n{\r\n\tint i;\r\n\tFILE *fp;\r\n\tfp=fopen(filename,\"r\");\r\n\tprintf(\"输入学生个数:\\n\");\r\n\tif(fp)\r\n\t{\r\n\t\tfscanf(fp,\"%d\",&tab->length);\r\n\t\tfor(i=1;i<=tab->length;i++)\r\n\t\t{\r\n\t\t\tfscanf(fp,\"%s\",tab->r[i].cardnum);\r\n\t\t\tfscanf(fp,\"%s\",tab->r[i].specialty);\r\n\t\t\tfscanf(fp,\"%s\",tab->r[i].name);\r\n\t\t\tfscanf(fp,\"%s\",tab->r[i].classnum);\r\n\t\t\tfscanf(fp,\"%s\",tab->r[i].id);\t\t\t\t\t\t\r\n\t\t}\r\n\t\tprintf(\"学生信息读入成功!\\n\");\r\n\t}\r\n\telse\r\n\t\tprintf(\"学生信息读入失败!\\n\");\r\n}\r\nvoid print(table *tab)\r\n{\r\n\tint i;\r\n\tif (tab->length!= 0)\r\n\t{\r\n\t\tprintf(\"输出所有的学生信息：\\n\");\r\n\t\tprintf(\"%22s%15s%12s%20s%18s\\n\", \"借书卡号\", \"专业\", \"姓名\", \"班级号\", \"学号\");\r\n\t\tfor(i = 1;i<=tab->length; i++)\r\n\t\t\tprintf(\"%20s%20s%10s%20s%20s\\n\", tab->r[i].cardnum, tab->r[i].specialty, tab->r[i].name, tab->r[i].classnum, tab->r[i].id);\r\n\t}\r\n\telse\r\n\t\tprintf(\"借书证系统还没有借书记录！！\\n\");\r\n}\r\nvoid cardnumsort(table *tab)//二分法排序\r\n{\r\n\tint i,j,left,right,mid;\r\n\tfor(i=2;i<=tab->length;i++)\r\n\t{\r\n\t\ttab->r[0]=tab->r[i];\r\n\t\tleft=1;\r\n\t\tright=i-1;\r\n\t\twhile(left<=right)\r\n\t\t{\r\n\t\t\tmid=(left+right)/2;\r\n\t\t\tif(strcmp(tab->r[i].cardnum,tab->r[mid].cardnum)<0)\r\n\t\t\t\tright=mid-1;\r\n\t\t\telse\r\n\t\t\t\tleft=mid+1;\r\n\t\t}\r\n\t\tfor(j=i-1;j>=left;j--)\r\n\t\t\ttab->r[j+1]=tab->r[j];\r\n\t\ttab->r[left]=tab->r[0];\r\n\t}\r\n}\r\nvoid classnumsort(table *tab)//二分法排序\r\n{\r\n\tint i,j,left,right,mid;\r\n\tfor(i=2;i<=tab->length;i++)\r\n\t{\r\n\t\ttab->r[0]=tab->r[i];\r\n\t\tleft=1;\r\n\t\tright=i-1;\r\n\t\twhile(left<=right)\r\n\t\t{\r\n\t\t\tmid=(left+right)/2;\r\n\t\t\tif(strcmp(tab->r[i].classnum,tab->r[mid].classnum)<0)\r\n\t\t\t\tright=mid-1;\r\n\t\t\telse\r\n\t\t\t\tleft=mid+1;\r\n\t\t}\r\n\t\tfor(j=i-1;j>=left;j--)\r\n\t\t\ttab->r[j+1]=tab->r[j];\r\n\t\ttab->r[left]=tab->r[0];\r\n\t}\r\n}\r\nvoid specialtysort(table *tab)//shell排序\r\n{\r\n\tint i,j,d;\r\n\td=tab->length/2;\r\n\twhile(d>=1)\r\n\t{\r\n\t\tfor(i=d+1;i<=tab->length;i++)\r\n\t\t{\r\n\t\t\ttab->r[0]=tab->r[i];\r\n\t\t\tj=i-d;\r\n\t\t\twhile(j>0&&tab->r[0].specialty<tab->r[i].specialty)\r\n\t\t\t{\r\n\t\t\t\ttab->r[j+d]=tab->r[j];\r\n\t\t\t\tj=j-d;\r\n\t\t\t}\r\n\t\t\ttab->r[j+d]=tab->r[0];\r\n\t\t}\r\n\t\td=d/2;\r\n\t}\r\n}\r\nvoid idsort(table *tab)//shell排序\r\n{\r\n\tint i,j,d;\r\n\td=tab->length/2;\r\n\twhile(d>=1)\r\n\t{\r\n\t\tfor(i=d+1;i<=tab->length;i++)\r\n\t\t{\r\n\t\t\ttab->r[0]=tab->r[i];\r\n\t\t\tj=i-d;\r\n\t\t\twhile(j>0&&tab->r[0].id<tab->r[i].id)\r\n\t\t\t{\r\n\t\t\t\ttab->r[j+d]=tab->r[j];\r\n\t\t\t\tj=j-d;\r\n\t\t\t}\r\n\t\t\ttab->r[j+d]=tab->r[0];\r\n\t\t}\r\n\t\td=d/2;\r\n\t}\r\n}\r\n/*int namesearch(table *tab,char *key)//二分法检索(需要有序)\r\n{\r\n\tint low=1,high=tab->length,mid;\r\n\twhile(low<=high)\r\n\t{\r\n\t\tmid=(low+high)/2;\r\n\t\tif(strcmp(tab->r[mid].name,key)==0)\r\n\t\t\treturn mid;\r\n\t\telse if(strcmp(tab->r[mid].name,key)>0)\r\n\t\t\thigh=mid-1;\r\n\t\telse\r\n\t\t\tlow=mid+1;\r\n\t}\r\n\treturn -1;\r\n}*/\r\nint cardnumsearch(table *tab,char *key)//二分法检索\r\n{\r\n\tint low=1,high=tab->length,mid;\r\n\twhile(low<=high)\r\n\t{\r\n\t\tmid=(low+high)/2;\r\n\t\tif(strcmp(tab->r[mid].cardnum,key)==0)\r\n\t\t\treturn mid;\r\n\t\telse if(strcmp(tab->r[mid].cardnum,key)>0)\r\n\t\t\thigh=mid-1;\r\n\t\telse\r\n\t\t\tlow=mid+1;\r\n\t}\r\n\treturn -1;\r\n}\r\nvoid sort()\r\n{\r\n\tprintf(\"1.对卡号排序并输出\\n\");\r\n    printf(\"2.对学号排序并输出\\n\");\r\n\tprintf(\"3.对班级排序并输出\\n\");\r\n\tprintf(\"4.对学院排序并输出\\n\");\r\n\tprintf(\"5.输出指定卡号\\n\");\r\n\tprintf(\"6.输出指定姓名\\n\");\r\n\tprintf(\"7.输出指定班号\\n\");\r\n\tprintf(\"8.输出指定学院\\n\");\r\n}\r\nvoid menu(table *tab)\r\n{\r\n\tint i=1,c;\r\n\tchar key1[30],key2[30],key3[30],key4[30];\r\n\tint result1, result2;\r\n\tprintf(\"输入操作选项：\\n\");\r\n\tscanf(\"%d\",&c);\r\n\tswitch(c)\r\n\t{\r\n\t\tcase 1:\r\n\t\t{\r\n\t\t\tcardnumsort(tab);\r\n\t\t\tprint(tab);\r\n\t\t\tmenu(tab);\r\n\t\t}\r\n\t\tbreak;\r\n\tcase 2:\r\n\t\t{\r\n\t\t\tidsort(tab);\r\n\t\t\tprint(tab);\r\n\t\t\tmenu(tab);\r\n\t\t}\r\n\t\tbreak;\r\n\tcase 3:\r\n\t\t{\r\n\t\t\tclassnumsort(tab);\r\n\t\t\tprint(tab);\r\n\t\t\tmenu(tab);\r\n\t\t}\r\n\t\tbreak;\r\n\tcase 4:\r\n\t\t{\r\n\t\t\tspecialtysort(tab);\r\n\t\t\tprint(tab);\r\n\t\t\tmenu(tab);\r\n\t\t}\r\n\t\tbreak;\r\n\tcase 5:\r\n\t\t{\r\n\t\t\tprintf(\"输入要查找的卡号：\\n\");\r\n\t\t\tscanf(\"%s\",&key1);\r\n\t\t\tresult1=cardnumsearch(tab,key1);\r\n\t\t\tif(result1!=-1)\r\n\t\t\t{\r\n\t\t\t\tprintf(\"%22s%15s%12s%20s%18s\\n\", \"借书卡号\", \"专业\", \"姓名\", \"班级号\", \"学号\");\r\n\t\t\t\tprintf(\"%20s%20s%10s%20s%20s\\n\", tab->r[result1].cardnum, tab->r[result1].specialty,tab->r[result1].name, tab->r[result1].classnum, tab->r[result1].id);\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t\tprintf(\"没有找到该借书证信息！\\n\");\r\n\t\t\tmenu(tab);\r\n\t\t}\r\n\t\tbreak;\r\n\tcase 6:\r\n\t\t{\r\n\t\t\tprintf(\"输入要查找的姓名：\\n\");\r\n\t\t\tscanf(\"%s\",&key2);\r\n\t\t\tprintf(\"%22s%15s%12s%20s%18s\\n\", \"借书卡号\", \"专业\", \"姓名\", \"班级号\", \"学号\");\r\n\t\t\twhile(i<=tab->length&&i>=1)\r\n\t\t\t{\r\n\t\t\t\tif (strcmp(tab->r[i].name,key3) == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tprintf(\"%20s%20s%10s%20s%20s\\n\", tab->r[i].cardnum, tab->r[i].specialty,\r\n\t\t\t\t\t\ttab->r[i].name, tab->r[i].classnum, tab->r[i].id);\r\n\t\t\t\t}\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t\tmenu(tab);\r\n\t\t}\r\n\t\tbreak;\r\n\tcase 7:\r\n\t\t{\r\n\t\t\tprintf(\"输入要查找的班级：\\n\");\r\n\t\t\tscanf(\"%s\",&key3);\r\n\t\t\tprintf(\"%22s%15s%12s%20s%18s\\n\", \"借书卡号\", \"专业\", \"姓名\", \"班级号\", \"学号\");\r\n\t\t\twhile(i<=tab->length&&i>=1)\r\n\t\t\t{\r\n\t\t\t\tif (strcmp(tab->r[i].classnum,key3) == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tprintf(\"%20s%20s%10s%20s%20s\\n\", tab->r[i].cardnum, tab->r[i].specialty,\r\n\t\t\t\t\t\ttab->r[i].name, tab->r[i].classnum, tab->r[i].id);\r\n\t\t\t\t}\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t\tmenu(tab);\r\n\t\t}\r\n\t\tbreak;\r\n\tcase 8:\r\n\t\t{\r\n\t\t\tprintf(\"输入要查找的学院：\\n\");\r\n\t\t\tscanf(\"%s\",&key4);\r\n\t\t\tprintf(\"%22s%15s%12s%20s%18s\\n\", \"借书卡号\", \"专业\", \"姓名\", \"班级号\", \"学号\");\r\n\t\t\twhile(i<=tab->length&&i>=1)\r\n\t\t\t{\r\n\t\t\t\tif (strcmp(tab->r[i].specialty,key4) == 0)\r\n\t\t\t\t{\r\n\t\t\t\t\tprintf(\"%20s%20s%10s%20s%20s\\n\", tab->r[i].cardnum, tab->r[i].specialty,\r\n\t\t\t\t\t\ttab->r[i].name, tab->r[i].classnum, tab->r[i].id);\r\n\t\t\t\t}\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t\tmenu(tab);\r\n\t\t}\r\n\t\tbreak;\r\n\tdefault:\r\n\t\tprintf(\"已退出！\\n\");\r\n\t\texit(0);\r\n\t\tbreak;\r\n\t}\r\n}\r\n\r\nint main()\r\n{\r\n\ttable tab;\r\n\tchar filename[]=\"D:\\\\7.txt\";\r\n\tcreate(&tab,filename);\r\n\tprint(&tab);\r\n\tsort();\r\n\tmenu(&tab);\r\n\treturn 0;\r\n}\r\n![1](https://user-images.githubusercontent.com/45334855/50160651-d5a37780-0314-11e9-8891-131430ccf727.png)\r\n![2](https://user-images.githubusercontent.com/45334855/50160753-05527f80-0315-11e9-8d0e-7eb4bfb655e6.png)\r\n\r\n![3](https://user-images.githubusercontent.com/45334855/50160683-e3f19380-0314-11e9-9927-972487f17096.png)\r\n"}}
{"actor":{"display_login":"DingYiQunsmile"}}