#include<stdio.h>
#include <stdlib.h>
#include<string.h>
typedef struct stu {
	char first_name[100], last_name[100];
	char id[13];
	int score;
	char GPA[3];
	int isreexam;
	int rank;
} student;
struct stu students[100];
struct stu stu[100];
char id[13];
int count = 0;
void add() {
	int n;
	printf("student num:");
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
    	printf("student %d frist_name:\n", i + 1);
    	scanf("%s", stu[i].first_name);

		printf("student %d last_name:\n", i + 1);
		scanf("%s", stu[i].last_name);

		printf("student %d number:\n", i + 1);
		scanf("%s",stu[i].id);

        printf("student %d score:\n", i + 1);
		scanf("%d", &stu[i].score);
		if (strncmp(stu[i].id, "2022", 4) == 0) {
			stu[i].isreexam =1;
		}
		else {
			stu[i].isreexam =0;
		}
		if (stu[i].score < 0) {
			printf("Invalid score!\n");
			return;
		}
     	if (stu[i].score >= 90) {
     	    strcpy(stu[i].GPA, "A+");
		}
		else if (stu[i].score >= 85) {
			strcpy(stu[i].GPA, "A");
		}
		else if (stu[i].score >= 80) {
			strcpy(stu[i].GPA, "B+");
		}
		else if (stu[i].score >= 75) {
			strcpy(stu[i].GPA, "B");
		}
		else if (stu[i].score >= 70) {
			strcpy(stu[i].GPA, "C+");
		}
		else if (stu[i].score >= 60) {
			strcpy(stu[i].GPA, "C");
		}
		else if (stu[i].score >= 50) {
			strcpy(stu[i].GPA, "D");
		}
		else {
			strcpy(stu[i].GPA, "F");
		}
		stu[i].rank = 1;
		for (int j = 0; j <= count; j++) {
			if (students[j].score > stu[i].score) {
				stu[i].rank = students[j].rank + 1;
			} else if (students[j].score == stu[i].score) {
				stu[i].rank = students[j].rank;
			} else if (students[j].score < stu[i].score) {
				students[j].rank++;
			}
		}
		count++;
		students[count]=stu[i];
		printf("Added successfully.\n");
	}   
}
void Delete() {
	printf("Delete student of id:\n");
	scanf("%s",id);
	for (int i = 0; i <=count; i++) {
		if (strcmp(students[i].id, id)==0) {
			    for (int j = i; j <= count; j++) {
				    students[j] = students[j + 1];
			    }
			count--;
			printf("Deleted successfully.\n");
			return;
		}
   }
	printf("Student not found.\n");
}

void Search() {
	printf("Input the id of the students:");
	scanf("%s",id);
	for (int i = 0; i <= count; i++) {
	    if(strcmp(students[i].id, id) == 0){
			printf("%s %s %s %d %s %d %d\n", students[i].first_name, students[i].last_name, students[i].id, students[i].score, students[i].GPA, students[i].isreexam, students[i].rank);
			return;
		}
	}
	printf("Student not found.\n");
	return;
}
void sort_by_score() {
	struct stu temp;
	for (int i = 0; i <= count; i++) {
		for (int j = i + 1; j <= count; j++) {
			if (students[i].score < students[j].score) {
				temp = students[i];
				students[i] = students[j];
				students[j] = temp;
			}
		}
	}
	printf("%-20s%-20s%-12s%-20s %-20s %-2s %-20s\n", "first_name", "last_name", "ID", "score", "reexam", "GPA", "rank");
	for (int i = 0; i <=count-1; i++)
	{
		printf("%-20s%-20s%-12s %-20d %-20d %-2s% -20d\n", students[i].first_name, students[i].last_name, students[i].id, students[i].score, students[i].isreexam, students[i].GPA, students[i].rank);
	}
}
void analysis()
{
	int Ap = 0, A = 0, Bp = 0, B = 0, Cp = 0, C = 0, D = 0, F = 0;
	for (int i = 0; i <= count; i++) {
		if (strcmp(students[i].GPA, "A+")==0)
		{
			Ap++;
		}
		else if (strcmp(students[i].GPA, "A")==0)
		{
			A++;
		}
		else if (strcmp(students[i].GPA, "B+")==0)
		{
			Bp++;
		}
		else if (strcmp(students[i].GPA, "B")==0) {
			B++;
		}
		else if (strcmp(students[i].GPA, "C+")==0) {
			Cp++;
		}
		else if (strcmp(students[i].GPA, "C")==0) {
			C++;
		}
		else if (strcmp(students[i].GPA, "D")==0) {
			D++;
		}
		else {
			F++;
		}
	}
	printf("A+: %d\nA: %d\nB+: %d\nB: %d\nC+: %d\nC: %d\nD: %d\nF: %d\n", Ap, A, Bp, B, Cp, C, D, F);
}
void encrypt(int key, student* stus, int count, char *encrypted) {
	memset(encrypted, 0, count*3);
    int i, j=0;
    for (i = 1; i <= count; i++) {
        int digit = stus[i].score;
		int tenDigit = digit / 10; // 提取十位数
		int unitDigit = digit % 10; // 提取个位数
		int newDigit = unitDigit * 10 + tenDigit; // 调换十位数和个位数
		while (newDigit > 0) {
			int remainder = newDigit % 10;
			newDigit /= 10;
			int encryptedDigit = (remainder + key) % 10;
			encrypted[j] = encryptedDigit + '0';
			j++;
		}
	}
    encrypted[i] = '\0';
}

void decrypt(int key, char *str, char *res) {
    int length = strlen(str);
    int i;
    for (i = 0; i < length; i++) {
        int digit = str[i] - '0';
        int decryptedDigit = (digit + key + 10) % 10;
        res[i] = decryptedDigit + '0';
    }
    res[i] = '\0';
	}
void biao(){
	int key;
    int choice;
	char str[100], res[100]; 
	printf("Okay, data upload finished. What do you what to do next? You can enter a number totell me.\n");
	printf("1 add\n2 delete\n3 search\n4 sort by score\n5 encrypt\n6 decrypt\n7 analysis\n0 exit\nchoice:");
	scanf("%d", &choice);
	switch (choice) {
	    case 1:
		    add();
			biao();
			break;
		case 2:
		    Delete();
		    biao();
		    break;
    	case 3:
        	Search();
		    biao();
		    break;
	    case 4:
		    sort_by_score();
		    biao();
		    break;
	    case 5:
			printf("请输入key值：");
			scanf("%d", &key);
		    encrypt(key, students, count, str);
			printf("%s\n", str);
		    biao();
		    break;
	    case 6:
			printf("请输入key值：");
			scanf("%d", &key);
			printf("请输入字符串：");
			scanf("%s", str);
		    decrypt(key, str, res);
			printf("%s\n", res);
		    biao();
		    break;
    	case 7:
	    	analysis();
		    biao();
		    break;
	    case 0:
		    break;
    }
    
}
int main() {
	printf("Hello, please input a series of student information!\n");
	add();
	biao();
	return 0;
}请为我写注释