diff --git a/Data Structure/实验1-顺序表/A - 数据结构上机测试1:顺序表的应用.cp b/Data Structure/实验1-顺序表/A - 数据结构上机测试1:顺序表的应用.cp new file mode 100644 index 0000000..3b0c828 --- /dev/null +++ b/Data Structure/实验1-顺序表/A - 数据结构上机测试1:顺序表的应用.cp @@ -0,0 +1,90 @@ +/* + Description + 在长度为n(n<1000)的顺序表中可能存在着一些值相同的“多余”数据元素(类型为整型),编写一个程序将“多余”的数据元素从顺序表中删除,使该表由一个“非纯表”(值相同的元素在表中可能有多个)变成一个“纯表”(值相同的元素在表中只能有一个)。 + Input + 第一行输入表的长度n; + 第二行依次输入顺序表初始存放的n个元素值。 + Output + 第一行输出完成多余元素删除以后顺序表的元素个数; + 第二行依次输出完成删除后的顺序表元素。 + Sample + Input + 12 + 5 2 5 3 3 4 2 5 7 5 4 3 + Output + 5 + 5 2 3 4 7 + Hint + 用尽可能少的时间和辅助存储空间。 + */ +#include + +using namespace std; + +struct Node +{ + int data; + Node *Next; +}; + +int main() +{ + int n; + int count=0; + Node *head=new Node; + Node *p=head; + Node *res=new Node; + + p->Next=nullptr; + + cin>>n; + + for(int i=0;i>t->data; + t->Next=p->Next; + p->Next=t; + p=t; + } + Node *p3=res; + Node *p2=nullptr; + p=head->Next; + int flag=0; + while(p) + { + flag=0; + p2=res; + while(p2) + { + if(p2->data==p->data) + { + flag=1; + break; + } + p2=p2->Next; + } + + + if(flag==0) + { + Node *t=new Node; + t->data=p->data; + t->Next=p3->Next; + p3->Next=t; + p3=t; + count++; + } + p=p->Next; + } + + p=res->Next; + cout<data<<" "; + p=p->Next; + } + cout< +#include + +using namespace std; + +bool ar[5001][5001]; +int main() +{ + int m,n,u,v; + + while(scanf("%d %d",&n,&m)!=EOF)//!=EOF要快于~(按位取反) + { + memset(ar,0,sizeof (ar));//0要快于false + + while(m--) + { + scanf("%d %d",&u,&v); + ar[u][v]= 1; + } + + scanf("%d",&m); + + while(m--) + { + scanf("%d %d",&u,&v); + if(ar[u][v]==1) + printf("Yes\n"); + else + { + printf("No\n"); + } + } + } + + return 0; +} diff --git a/Data Structure/实验6-图/B - 图的基本存储的基本方式二.cp b/Data Structure/实验6-图/B - 图的基本存储的基本方式二.cp new file mode 100644 index 0000000..bc46f86 --- /dev/null +++ b/Data Structure/实验6-图/B - 图的基本存储的基本方式二.cp @@ -0,0 +1,68 @@ +/* + Description + 请定一个无向图,顶点编号从0到n-1,用深度优先搜索(DFS),遍历并输出。遍历时,先遍历节点编号小的。 + + Input + 输入第一行为整数n(0 < n < 100),表示数据的组数。 对于每组数据,第一行是两个整数k,m(0 < k < 100,0 < m < k*k),表示有m条边,k个顶点。 下面的m行,每行是空格隔开的两个整数u,v,表示一条连接u,v顶点的无向边。 + + Output + 输出有n行,对应n组输出,每行为用空格隔开的k个整数,对应一组数据,表示DFS的遍历结果。 + + Sample + Input + 1 + 4 4 + 0 1 + 0 2 + 0 3 + 2 3 + Output + 0 1 2 3 + */ +#include +#include +#include + +using namespace std; + +vector a[500005]; + +int main() +{ + int n,m; + int u,v; + int q; + int len,flag; + while(scanf("%d %d",&n,&m)!=EOF) + { + memset(a,0,sizeof (a)); + while(m--) + { + scanf("%d %d",&u,&v); + a[u].push_back(v); + } + + scanf("%d",&q); + + while(q--) + { + flag=0; + + scanf("%d %d",&u,&v); + len=a[u].size(); + for(int i=0;i +#define ST_NUM 2 //学生数 +typedef struct +{ + int nu; //序号 + int num; //学号 + char name[9]; //姓名 + float mark; //学分 + float match; //数学 + float english; + float c; + float pe; + float modern_history; + float software; + float sum; + float average; +}student; +student ST[ST_NUM]; + +int input() +{ + + int i; + printf ("请输入%d个学生的信息:\n",ST_NUM); + for (i=0;i +#define ST_NUM 2 //学生总数,可随需要修改 +double average[6];//全局变量定义各科平均分,方便后续使用 +typedef struct +{ + int nu; //序号 + int num; //学号 + char name[9]; //姓名 + float mark; + float match; //数学 + float english; + float c_language; + float pe; + float history; + float software; + float sum; + float average; +}student; +student ST[ST_NUM]={0}; + +int input() +{ + + int i,t; + printf ("请输入%d个学生的信息:\n",ST_NUM); + for (i=0;i=60) + ST[i].mark+=5; + if(ST[i].english>=60) + ST[i].mark+=3; + if(ST[i].c_language>=60) + ST[i].mark+=3.5; + if(ST[i].pe>=60) + ST[i].mark+=2; + if(ST[i].history>=60) + ST[i].mark+=2; + if(ST[i].software>=60) + ST[i].mark+=2; + } + //计算各科平均分 + for(i=0;iST[j+1].mark) + { + temp=ST[j]; + ST[j]=ST[j+1]; + ST[j+1]=temp; + } + } + } + } + } +} + +void output() +{ + int i; + printf("序号\t学号\t姓名\t"); + printf("获得学分\t高等数学\t大学英语\tc语言\t大学体育\t近代史\t软件技术导论\t总分\t\t平均分\n"); + + for (i=0;i +#include +#define NUM 30//定义最大学生数 +typedef struct +{ + int no; + int score; +}Student; + +void create(Student a[],int n); +void display(Student a[],int n); +void findchj(int chj,Student a[],int n); +void findsxh(int sxh,Student a[],int n); +void sort_big(Student a[],int n); +void sort_small(Student a[],int n); +void insert(int sxh,int chj,Student a[],int n); +void remov(int sxh,Student a[],int *n);//remove函数名已在库函数中声明,故不能用在此处 +void replace(int sxh,Student a[],int n); + +void main() +{ + Student stu[NUM]={0}; + int n=0; + int flag=0; + int choice; + int chj,sxh; + + + system("cls");//系统命令:清除控制台显示的内容 + system("color f0");//系统命令:设置控制台背景颜色 + do + { + printf("1.成绩录入 2.成绩显示 3.按成绩查找\n"); + printf("4.按序号查找 5.成绩递减排序 6.成绩递增排序\n"); + printf("7.插入成绩 8.删除成绩 9.修改成绩\n"); + printf("0.退出系统\n\n"); + + printf("请输入您的选择:"); + scanf("%d",&choice); + fflush(stdin);//刷新输入缓冲区,清除缓冲区内容 + + switch(choice) + { + case 1: + if(flag==0) + { + printf("请输入学生人数:"); + scanf("%d",&n); + create(stu,n); + display(stu,n); + flag=1; + } + else if (flag==1) + printf("成绩数据库已建立,请不要重复建立\n"); + break; + + case 2: + if (flag==1) + display(stu,n); + else if (flag==0) + printf("数据库为空,请先建立数据库\n"); + break; + case 3: + if (flag==1) + { + printf("请输入要查询的成绩\n"); + scanf("%d",&chj); + findchj(chj,stu,n); + } + + else if (flag==0) + printf("数据库为空,请先建立数据库\n"); + break; + + case 4: + if (flag==1) + { + printf("请输入要查询的序号\n"); + scanf("%d",&sxh); + if(sxh>n||sxh<=0) + { + printf("顺序号超出范围,不能操作\n"); + break; + } + else + findsxh(sxh,stu,n); + } + else if (flag==0) + printf("数据库为空,请先建立数据库\n"); + break; + + case 5: + if (flag==1) + { + sort_big(stu,n); + printf("降序排序完成\n"); + } + else if (flag==0) + printf("数据库为空,请先建立数据库\n"); + break; + + case 6: + if (flag==1) + { + sort_small(stu,n); + printf("升序排序完成\n"); + } + else if (flag==0) + printf("数据库为空,请先建立数据库\n"); + break; + case 7: + if (flag==1) + { + printf("请以空格分隔输入要插入的序号及成绩:"); + scanf("%d %d",&sxh,&chj); + if(sxh>n||sxh<=0) + { + printf("顺序号超出范围,不能操作\n"); + break; + } + else + insert(sxh,chj,stu,n); + } + else if (flag==0) + printf("数据库为空,请先建立数据库\n"); + break; + + case 8: + if (flag==1) + { + printf("请输入要删除的顺序号:"); + scanf("%d", &sxh); + if(sxh>n||sxh<=0) + { + printf("顺序号超出范围,不能操作\n"); + break; + } + else + remov(sxh,stu,&n); + } + else if (flag==0) + printf("数据库为空,请先建立数据库\n"); + break; + case 9: + if (flag==1) + { + printf("请输入要修改的顺序号:"); + scanf("%d",&sxh); + if(sxh>n||sxh<=0) + { + printf("顺序号超出范围,不能操作\n"); + break; + } + else + replace(sxh,stu,n); + } + else if (flag==0) + printf("数据库为空,请先建立数据库\n"); + break; + case 0:printf("\n\t\t\t欢迎你再次使用,再见!\n"); + exit(0); + default: + printf("\n \t\t\t对不起,您的选择有误,请重新输入!! \n"); + } + + system("pause");//系统命令:暂停程序运行 + system("cls");//系统命令:清除控制台显示的内容 + }while(1); +} +//建立成绩数组 +void create(Student a[],int n) +{ + int i,t; + printf("请依次输入成绩,成绩之间用空格或回车分隔并以数字'000'结束输入\n"); + printf("请输入数据:"); + for (i=0;ia[j+1].score) + { + temp=a[j]; + a[j]=a[j+1]; + a[j+1]=temp; + } + } + } + printf("升序排序完成\n"); + printf("\n"); +} +//按给定顺序号插入成绩 +void insert(int sxh,int chj,Student a[],int n) +{ + int i; + Student temp; + for(i=n-1;i>=sxh;i--) + { + a[i].score=a[i-1].score; + } + a[sxh-1].score=chj; + printf("\n"); +} +//按给定顺序号删除成绩 +void remov(int sxh,Student a[],int *n) +{ + int i; + int t=*n; + for(i=sxh-1;i +#define ST_NUM 100 //学生数 +typedef struct +{ + int nu; //序号 + int SNo[11]; //学号 + char Name[9]; //姓名 + int GSHu; //数学 + int Dying;//大学英语 + int CCHeng;//c语言 + int DTi;//体育 + int JDaiSHi;//现代历史 + int RDao;//软件 + int FDaoYuan;//辅导员评分 + int BZHuRen;//班主任评分 + int Bjin;//班级同学评分 + int GKeFlag;//挂科标记 + double sum; + double ZHeFen;//综合成绩 + +}student; +student ST[ST_NUM]={0}; + +//输入函数 +int input(int num) +{ + int i; + + printf ("请输入%d个学生的信息:\n",num); + for (i=0;i +#include +#include + +struct System_Data +{ + char Flight_Number[20]; + char Take_Off[20]; + double Time_Cost; + char Land[20]; + int Price; + char Model[10]; + int Tickets_Left; + struct System_Data *Next; + +}; + +//-----------------ʼ---------------- +void Welcome(); + +struct System_Data * Initialization();// + +void menu(struct System_Data *head);//ϵͳ˵ + +void Data_input(struct System_Data *head);//ݶȡ + +void Check(struct System_Data *head);//Ʊѯ + +struct System_Data *Check_Flight_Number(struct System_Data *p);//Ųѯ + +struct System_Data *Check_Take_Off(struct System_Data *p, struct System_Data *Ans);//ѯ + +struct System_Data *Check_Land(struct System_Data *p, struct System_Data *Ans);//յѯ + +struct System_Data *Check_Time_Cost(struct System_Data *p, struct System_Data *Ans);//ʱѯ + +void Print(struct System_Data *Ans,struct System_Data *head); + +void print(struct System_Data *Ans,struct System_Data *head);//ȫƱ + +void Back(struct System_Data *head); + +void Copy(struct System_Data *p,struct System_Data *t); + +int Flights_Count; // + +//-------------------------------------------- + +int main() +{ + //Welcome();//ӭ + + //Sleep(3000); + //system("cls"); + + //ʼ + struct System_Data *head; + head=Initialization(); + + menu(head);//˵ + + system("pause"); + + return 0; +} + +void Welcome() +{ + printf("**************************\n"); + printf("* ӭ뺽ඩƱϵͳ *\n"); + printf("**************************\n"); + Sleep(1500); + system("cls"); + + printf("**********************\n"); + printf("* *\n"); + printf("**********************\n"); + printf("* ڼ *\n"); + printf("* ſԴ *\n"); + printf("* ¾ *\n"); + printf("* С *\n"); + printf("**********************\n"); +} + +struct System_Data *Initialization() +{ + struct System_Data *head=(struct System_Data*)malloc(sizeof(struct System_Data)); + head->Next=NULL; + + return head; +} + +void menu(struct System_Data *head) +{ + int select; + printf("*****************************\n"); + printf("* 񺽶Ʊϵͳ *\n"); + printf("* 1.Ϣ¼/ *\n"); + printf("* 2.ѯϢ *\n"); + printf("* 0. ϵ ͳ *\n"); + printf("*****************************\n"); + + + scanf("%d",&select); + switch(select) + { + case 1: + system("cls"); + Data_input(head); + case 2: + Check(head); + case 0: + exit(1); + case -1: + print(head,head); + default: + printf("Ƿ"); + exit(-1); + } +} + +void Data_input(struct System_Data *head) +{ + Flights_Count=0; + FILE *Data;//ļָ + char FileName[100] = "C:\\Users\\UDK_KL\\iCloudDrive\\ĩҵ\\ai.txt"; + + Data = fopen(FileName, "r"); + + if (!Data) + { + printf("ļ\n"); + system("pause"); + menu(head); + } + else + { + char Top_Line[100]; + + struct System_Data *p=head; + + fgets(Top_Line, 100, Data);//ȡһ˵ + + while (!feof(Data)) + { + struct System_Data *t = (struct System_Data *)malloc(sizeof(struct System_Data)); + + //ȡϢ; + fscanf(Data, "%s %s %s %lf %s %d %d",t->Flight_Number,t->Take_Off,t->Land,&t->Time_Cost,t->Model,&t->Price,&t->Tickets_Left); + + t->Next=NULL; + + p->Next=t; + p=t; + Flights_Count++; + } + + Flights_Count-=1; + printf("Ϣѵɹι%dϢ\n",Flights_Count); + + // Sleep(1000); + fclose(Data); + menu(head); + } + +} + +void Check(struct System_Data *head) +{ + system("cls"); + + struct System_Data *Ans=(struct System_Data*)malloc(sizeof(struct System_Data)); + + if(Flights_Count==0) + { + printf("δ⵽ݣȵ뺽\n"); + Back(head); + } + printf("*****************************\n"); + printf("* ѯʽ *\n"); + printf("*****************************\n"); + printf("* 1. *\n"); + printf("* 2.վ *\n"); + printf("* 3.յվ *\n"); + printf("* 4.ʱ *\n"); + printf("* 0.˵ *\n"); + printf("*****************************\n"); + + int sel; + + scanf("%d",&sel); + + switch(sel) + { + case 0: + menu(head); + break; + case 1: + Print(Check_Flight_Number(head),head); + break; + case 2: + print(Check_Take_Off(head,Ans),head); + + break; + case 3: + print(Check_Land(head, Ans),head); + break; + case 4: + print(Check_Time_Cost(head, Ans),head); + break; + case -1: + print(head,head); + break; + default: + printf("Ƿ"); + } +} + +struct System_Data *Check_Flight_Number(struct System_Data *head)//Ųѯ +{ + printf("뺽ţ\n"); + struct System_Data *p=head->Next; + + char Number[10]; + scanf("%s",Number); + while(p) + { + if(!strcmp(p->Flight_Number,Number)) + { + struct System_Data *t=(struct System_Data *)malloc(sizeof(struct System_Data)); + + Copy(p,t); + + t->Next=NULL; + return t; + } + p=p->Next; + } + system("cls"); + printf("δѯ\n"); + Back(head); +} + +struct System_Data *Check_Take_Off(struct System_Data *head, struct System_Data *Ans)//ѯ +{ + printf("㣺\n"); + int flag=0; + struct System_Data *p=head->Next; + + struct System_Data *Ap=Ans; + Ap->Next=NULL; + + char Place[30]= {0}; + getchar(); + gets(Place); + + while(p) + { + if(!strcmp(p->Take_Off,Place)) + { + struct System_Data *t =(struct System_Data*)malloc(sizeof(struct System_Data)); + *t=*p; + + t->Next=NULL; + Ap->Next= t; + Ap=t; + + flag=1; + } + p=p->Next; + } + + if(flag==0) + { + system("cls"); + printf("δѯ\n"); + Back(head); + } + else + return Ans; +} + +struct System_Data *Check_Land(struct System_Data *head, struct System_Data *Ans)//յѯ +{ + printf("յ㣺\n"); + int flag=0; + struct System_Data *p=head->Next; + + struct System_Data *Ap=Ans; + Ap->Next=NULL; + + char Place[30]= {0}; + getchar(); + gets(Place); + + while(p) + { + if(!strcmp(p->Land,Place)) + { + struct System_Data *t =(struct System_Data*)malloc(sizeof(struct System_Data)); + *t=*p; + + t->Next=NULL; + Ap->Next= t; + Ap=t; + + flag=1; + } + p=p->Next; + } + + if(flag==0) + { + system("cls"); + printf("δѯ\n"); + Back(head); + } + else + return Ans; +} + +struct System_Data *Check_Time_Cost(struct System_Data *head, struct System_Data *Ans)//ʱѯ +{ + printf("ʱ䣺\n"); + int flag=0; + struct System_Data *p=head->Next; + + struct System_Data *Ap=Ans; + Ap->Next=NULL; + + double Time; + scanf("%lf",&Time); + + while(p) + { + if(p->Time_Cost==Time) + { + struct System_Data *t =(struct System_Data*)malloc(sizeof(struct System_Data)); + *t=*p; + + t->Next=NULL; + Ap->Next= t; + Ap=t; + + flag=1; + } + p=p->Next; + } + + if(flag==0) + { + system("cls"); + printf("δѯ\n"); + Back(head); + } + else + return Ans; +} + +void Print(struct System_Data *p,struct System_Data *head) +{ + system("cls"); + printf("IJѯΪ\n\n"); + printf("\t\tյ\tʱ(Сʱ) \t۸\tƱ\n"); + + printf("%s\t%s\t%s\t %.2lf \t%s\t%d\t %d\n",p->Flight_Number,p->Take_Off,p->Land,p->Time_Cost,p->Model,p->Price,p->Tickets_Left); + free(p); + Back(head); +} + +void print(struct System_Data *Ans,struct System_Data *head) +{ + struct System_Data *p=Ans->Next; + struct System_Data *F=Ans; + free(F);//ͷڴ + + system("cls"); + + printf("IJѯΪ\n\n"); + printf("\t\tյ\tʱ(Сʱ) \t۸\tƱ\n"); + while(p) + { + F=p; + printf("%s\t%s\t%s\t %.2lf \t%s\t%d\t %d\n",p->Flight_Number,p->Take_Off,p->Land,p->Time_Cost,p->Model,p->Price,p->Tickets_Left); + p=p->Next; + free(F); + } + + Sleep(1000); + + menu(head); +} + + +void Back(struct System_Data *head) +{ + int sel; + + printf("\n0˳ϵͳ\n1ص˵\n"); + scanf("%d",&sel); + if(sel==0) + exit(0); + + else if(sel==1) + { + getchar(); + system("cls"); + menu(head); + } + else + { + printf("Ƿ"); + exit(-1); + } +} + +void Copy(struct System_Data *p,struct System_Data *t) +{ + strcpy(t->Flight_Number,p->Flight_Number); + strcpy(t->Take_Off,p->Take_Off); + t->Time_Cost=p->Time_Cost; + strcpy(t->Land,p->Land); + t->Price=p->Price; + strcpy(t->Model,p->Model); + t->Tickets_Left=p->Tickets_Left; +} diff --git a/HomeWork——Airplane/ai.txt b/HomeWork——Airplane/ai.txt new file mode 100644 index 0000000..a4652b1 --- /dev/null +++ b/HomeWork——Airplane/ai.txt @@ -0,0 +1,10 @@ +航班号 起点 终点 飞行时间 机型 价格 余票量 +CA1544 合肥 北京 1.55 A733 960 90 +MU5341 上海 广州 2.20 M90 1280 150 +CZ3869 重庆 深圳 2.05 733 1010 0 +MU3682 桂林 南京 2.20 M90 1380 0 +HU1836 上海 北京 2.25 738 1250 120 +CZ3528 成都 厦门 2.55 CRJ 1060 130 +MU4594 昆明 西安 2.30 328 1160 0 +SC7425 青岛 海口 5.10 DH4 1630 190 +CA1234 洛阳 上海 1.57 DH4 1050 0 diff --git a/LAN QIAO Collegiate Programming Contest/DNA.cp b/LAN QIAO Collegiate Programming Contest/DNA.cp new file mode 100644 index 0000000..dbe824b --- /dev/null +++ b/LAN QIAO Collegiate Programming Contest/DNA.cp @@ -0,0 +1,115 @@ +/* + 题目描述 + 小强从小就喜欢生命科学,他总是好奇花草鸟兽从哪里来的。终于, 小强上中学了,接触到了神圣的名词--DNA.它有一个双螺旋的结构。这让一根筋的小强抓破头皮,“要是能画出来就好了” 小强喊道。现在就请你帮助他吧 + + 输入 + 输入包含多组测试数据。第一个整数N(N<=15),N表示组数,每组数据包含两个整数a,b。a表示一个单位的DNA串的行数,a为奇数且 3<=a<=39。b表示重复度(1<=b<=20)。 + + 输出 + 输出DNA的形状,每组输出间有一空行。 + + 样例输入 + 2 + 3 1 + 5 4 + 样例输出 + X X + X + X X + + X X + X X + X + X X + X X + X X + X + X X + X X + X X + X + X X + X X + X X + X + X X + X X + */ +#include + +using namespace std; + +int main() +{ + int space,space2; + int n,a,b; + + cin>>n; + + while(n--) + { + cin>>a>>b; + + for(int k=0;k0&&co) + { + for(int j=0;j + +using namespace std; + +const int N=20; +int n; +char g[N][N]; +bool col[N],dg[N],udg[N]; + +void dfs(int u) +{ + if(u==n) + { + for (int i = 0; i < n; i++) + puts(g[i]); + puts(""); + return; + } + + + for(int i=0;i>n; + for(int i=0;i