| 讲 | 台 | ||||||
| 2021213147 | 2021213162 | 2021213177 | 2021213192 | 2021213236 | 2021213221 | ||
| 2021213148 | 2021213163 | 2021213178 | 2021213193 | 2021213207 | 2021213222 | ||
| 2021213149 | 2021213164 | 2021213179 | 2021213194 | 2021213208 | 2021213223 | ||
| 2021213150 | 2021213165 | 2021213180 | 2021213195 | 2021213209 | 2021213224 | ||
| 2021213151 | 2021213166 | 2021213181 | 2021213196 | 2021213210 | 2021213225 | ||
| 2021213152 | 2021213167 | 2021213182 | 2021213197 | 2021213211 | 2021213226 | 2020213630 | |
| 2021213153 | 2021213168 | 2021213183 | 2021213198 | 2021213212 | 2021213227 | 2020213634 | |
| 2021213154 | 2021213169 | 2021213184 | 2021213199 | 2021213213 | 2021213228 | 2017213151 | |
| 2021213155 | 2021213170 | 2021213185 | 2021213200 | 2021213214 | 2021213229 | 2017213207 | |
| 2021213156 | 2021213171 | 2021213186 | 2021213201 | 2021213215 | 2021213230 | 2018213230 | |
| 2021213157 | 2021213172 | 2021213187 | 2021213202 | 2021213216 | 2021213231 | ||
| 2021213158 | 2021213173 | 2021213188 | 2021213203 | 2021213217 | 2021213232 | ||
| 2021213159 | 2021213174 | 2021213189 | 2021213204 | 2021213218 | 2021213233 | ||
| 2021213160 | 2021213175 | 2021213190 | 2021213205 | 2021213219 | 2021213234 | ||
| 2021213161 | 2021213176 | 2021213191 | 2021213206 | 2021213220 | 2021213235 | 
时间排序:machine language , assembly language, non-procedural language ,high-level language 按时间排序
老师能介绍一下吗
#include <stdio.h>
#include <string.h>
struct data{
 char name[11];
 char id[11];
 int score[3];
};
void operation_1(struct data stu[], int, int); //add information
void operation_2(struct data stu[], int, int); //delete information
void operation_3(struct data stu[], int, int); //change information
void operation_4(struct data stu[], int, int); //average score
int main() 
{
 int order, i, n;
 struct data stu[130];
 
 scanf("%d", &n);
 for(i = 0; i < n ; i++) 
 {
 scanf("%d", &order);
 getchar();
 if(order == 1) 
 operation_1(stu, n, i);
 else if(order == 2) 
 operation_2(stu, n, i);
 else if(order == 3) 
 operation_3(stu, n, i);
 else if(order == 4) 
 operation_4(stu, n, i);
 }
 
 return 0;
}
void operation_1(struct data stu[], int n, int i) 
{
 char buffer[11];//buffer
 int flag = 1;
 scanf("%s", &buffer);
 for (int j = 0; j < n; j++) 
 {
 if (strcmp(buffer, stu[j].id) == 0) //search
 {
 flag = 0;
 j = 130;//equal to break
 }
 }
 getchar();
 if (flag == 1) 
 {
 strcpy(stu[i].id, buffer);
 scanf("%s%d%d%d", stu[i].name, &stu[i].score[0], &stu[i].score[1], &stu[i].score[2]);
 printf("Add success\n");
 }
 else printf("Students already exist\n");
}
void operation_2(struct data stu[], int n, int i) 
{
 char buffer[11];//buffer
 int flag = 1;
 scanf("%s", &buffer);
 for (int j = 0; j < n; j++) 
 {
 if (strcmp(buffer, stu[j].id) == 0) //search
 {
 flag = 0;
 stu[j]=stu[i+1];
 j=130;//equal to break
 }
 }
 getchar();
 if (flag == 0)
 {
 printf("Delete success\n");
 }
 else printf("Students do not exist\n"); 
}
void operation_3(struct data stu[], int n, int i) 
{
 char buffer[11];//buffer
 int flag = 1, t;
 scanf("%s", &buffer);
 for (int j = 0; j < n; j++) 
 {
 if (strcmp(buffer, stu[j].id) == 0) //search
 {
 flag = 0;
 t=j;
 j=130;//equal to break
 }
 }
 if(flag==0)
 {
 scanf("%d%d%d", &stu[t].score[0], &stu[t].score[1], &stu[t].score[2]);
 printf("Update success\n");
 }
 else printf("Students do not exist\n");
}
void operation_4(struct data stu[], int n, int i) 
{
 char buffer[11];//buffer
 int flag = 1, t;
 scanf("%s", &buffer);
 for (int j = 0; j < n; j++) 
 {
 if (strcmp(buffer, stu[j].id) == 0) //search 
 {
 flag = 0;
 t=j;
 j=130;//equal to break
 }
 }
 if(flag==0)
 {
 printf("Student ID:%s\n", stu[t].id);
 printf("Name:%s\n", stu[t].name);
 printf("Average Score:%.1lf\n", (stu[t].score[0]+stu[t].score[1]+stu[t].score[2])*1.0/3);
 }
 else printf("Students do not exist\n");
}
疑问一:我目前使用fgets函数的输入格式是(str , size , stdin ),其中第二项是大小的意思,所以是不是输入多少字符就是多少个字节呢?第三项是否所有情况都是输入stdin呢?
疑问二:在标准的fgets函数中会自动将字符串末尾的'\n'读入,所以在puts时会自动换行。如果是将字符串写入一个字符串数组,我知道如何处理掉末尾的换行符,那如果我使用fgets函数将一个字符串写入一个字符指针,如何将末尾的'\n'处理掉呢?
参考PTA练习13的编程第三题。代码如下:https://onlinegdb.com/95ykND2WbJ
Page 1 of 8
