#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>//标准输入输出
#include <stdlib.h>//内存动态分配,要用
#include<stdbool.h>//true,false
#include <string.h>//字符串数组
// 定义正确的账号和密码
const char* correct_username = "1";
const char* correct_password = "1";
// 检查用户名和密码是否正确
int check_credentials(const char* username, const char* password)
{
return strcmp(username, correct_username) == 0 && strcmp(password, correct_password) == 0;
}
typedef struct Train
{
int id;
char name[20];
int count; // 添加计数器
struct Train* next;
} Train;
Train* head = NULL;
//数据录入
void add_train(int id, const char* name)
{
Train* new_train = (Train*)malloc(sizeof(Train));
new_train->id = id;
strcpy(new_train->name, name);
new_train->count = 1; // 初始化计数器为1
new_train->next = head;
head = new_train;
}
//数据输出(显示)
void print_trains()
{
Train* current = head;
printf(" ID Name\n");
while (current != NULL)
{
printf(" %-10d %-10s\n", current->id, current->name);
current = current->next;
}
}
//用于插入火车信息
void insert_train(int position, int id, const char* name)
{
Train* new_train = (Train*)malloc(sizeof(Train));
new_train->id = id;
strcpy(new_train->name, name);
if (position == 1)
{
new_train->next = head;
head = new_train;
}
else
{
Train* current = head;
for (int i = 1; i < position - 1 && current != NULL; i++)
{
current = current->next;
}
if (current != NULL)
{
new_train->next = current->next;<