5.8
This commit is contained in:
parent
b8f9c0af19
commit
662ac80781
90
Data Structure/实验1-顺序表/A - 数据结构上机测试1:顺序表的应用.cp
Normal file
90
Data Structure/实验1-顺序表/A - 数据结构上机测试1:顺序表的应用.cp
Normal file
@ -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<iostream>
|
||||
|
||||
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<n;i++)
|
||||
{
|
||||
Node *t=new Node;
|
||||
cin>>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<<count<<endl;
|
||||
while(p)
|
||||
{
|
||||
cout<<p->data<<" ";
|
||||
p=p->Next;
|
||||
}
|
||||
cout<<endl;
|
||||
return 0;
|
||||
}
|
61
Data Structure/实验6-图/A - 图的基本存储的基本方式一.cp
Normal file
61
Data Structure/实验6-图/A - 图的基本存储的基本方式一.cp
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
Description
|
||||
解决图论问题,首先就要思考用什么样的方式存储图。但是小鑫却怎么也弄不明白如何存图才能有利于解决问题。你能帮他解决这个问题么?
|
||||
|
||||
Input
|
||||
多组输入,到文件结尾。
|
||||
|
||||
每一组第一行有两个数n、m表示n个点,m条有向边。接下来有m行,每行两个数u、v代表u到v有一条有向边。第m+2行有一个数q代表询问次数,接下来q行每行有一个询问,输入两个数为a,b。
|
||||
|
||||
注意:点的编号为0~n-1,2<=n<=5000 ,n*(n-1)/2<=m<=n*(n-1),0<=q<=1000000,a!=b,输入保证没有自环和重边
|
||||
|
||||
Output
|
||||
对于每一条询问,输出一行。若a到b可以直接连通输出Yes,否则输出No。
|
||||
|
||||
Sample
|
||||
Input
|
||||
2 1
|
||||
0 1
|
||||
2
|
||||
0 1
|
||||
1 0
|
||||
Output
|
||||
Yes
|
||||
No
|
||||
*/
|
||||
#include<iostream>
|
||||
#include<cstring>
|
||||
|
||||
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;
|
||||
}
|
68
Data Structure/实验6-图/B - 图的基本存储的基本方式二.cp
Normal file
68
Data Structure/实验6-图/B - 图的基本存储的基本方式二.cp
Normal file
@ -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<iostream>
|
||||
#include<vector>
|
||||
#include<cstring>
|
||||
|
||||
using namespace std;
|
||||
|
||||
vector<int> 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<len;i++)
|
||||
{
|
||||
if(a[u][i]==v)
|
||||
{
|
||||
flag=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(flag==1)
|
||||
printf("Yes\n");
|
||||
else
|
||||
printf("No\n");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
BIN
Grade Management/.DS_Store
vendored
Executable file
BIN
Grade Management/.DS_Store
vendored
Executable file
Binary file not shown.
125
Grade Management/T1.c
Executable file
125
Grade Management/T1.c
Executable file
@ -0,0 +1,125 @@
|
||||
#include <stdio.h>
|
||||
#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<ST_NUM;i++)
|
||||
{
|
||||
printf("序号:");
|
||||
if(scanf("%d",&ST[i].nu)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
printf ("学号:");
|
||||
scanf ("%d",&ST[i].num);
|
||||
printf("姓名:");
|
||||
scanf ("%s",ST[i].name);
|
||||
printf("获得学分:");
|
||||
if(scanf("%f",&ST[i].mark)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
printf("高等数学的成绩:");
|
||||
if(scanf("%f",&ST[i].match)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("大学英语的成绩:");
|
||||
if(scanf("%f",&ST[i].english)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
printf("C语言程序设计的成绩:");
|
||||
if(scanf("%f",&ST[i].c)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
printf("大学体育的成绩:");
|
||||
if(scanf("%f",&ST[i].pe)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
printf("中国近代史纲要的成绩:");
|
||||
if(scanf("%f",&ST[i].modern_history)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
printf("软件技术导论成绩:");
|
||||
if(scanf("%f",&ST[i].software)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void output()
|
||||
{
|
||||
int i;
|
||||
printf("序号\t学号\t姓名\t");
|
||||
printf("获得学分\t高等数学\t大学英语\tc语言\t大学体育\t近代史\t软件技术导论\t总分\t\t平均分\n");
|
||||
|
||||
|
||||
|
||||
for (i=0;i<ST_NUM;i++)
|
||||
{
|
||||
printf("%d\t%d\t%s\t",ST[i].nu,ST[i].num,ST[i].name);
|
||||
printf("%3.2f\t",ST[i].mark);
|
||||
printf("%3.2f\t",ST[i].match);
|
||||
printf("%3.2f\t",ST[i].english);
|
||||
printf("%3.2f\t",ST[i].c);
|
||||
printf("%3.2f\t",ST[i].pe);
|
||||
printf("%3.2f\t",ST[i].modern_history);
|
||||
printf("%3.2f\t\t",ST[i].software);
|
||||
printf("%3.2f\t%3.2f\n",ST[i].sum,ST[i].average);
|
||||
}
|
||||
}
|
||||
|
||||
void process()
|
||||
{
|
||||
int i;
|
||||
for(i=0;i<ST_NUM;i++)
|
||||
{
|
||||
ST[i].sum=ST[i].mark+ST[i].match+ST[i].english+ST[i].c+ST[i].pe+ST[i].modern_history+ST[i].software;
|
||||
|
||||
ST[i].average=ST[i].sum/7;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if(input()==1)
|
||||
return 0;
|
||||
process();
|
||||
output();
|
||||
return 0;
|
||||
}
|
216
Grade Management/T2.c
Executable file
216
Grade Management/T2.c
Executable file
@ -0,0 +1,216 @@
|
||||
#include <stdio.h>
|
||||
#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<ST_NUM;i++)
|
||||
{
|
||||
printf("序号:");
|
||||
if(scanf("%d",&ST[i].nu)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
printf ("学号:");
|
||||
if(scanf("%d",&ST[i].num)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
printf("姓名:");
|
||||
scanf ("%s",ST[i].name);
|
||||
printf("高等数学的成绩:");
|
||||
if(scanf("%f",&ST[i].match)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("大学英语的成绩:");
|
||||
if(scanf("%f",&ST[i].english)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
printf("C语言程序设计的成绩:");
|
||||
if(scanf("%f",&ST[i].c_language)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
printf("大学体育的成绩:");
|
||||
if(scanf("%f",&ST[i].pe)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
printf("中国近代史纲要的成绩:");
|
||||
if(scanf("%f",&ST[i].history)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
printf("软件技术导论成绩:");
|
||||
if(scanf("%f",&ST[i].software)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void process()
|
||||
{
|
||||
int i,j;
|
||||
double sum[6]={0.0};
|
||||
//计算学生平均分
|
||||
for(i=0;i<ST_NUM;i++)
|
||||
{
|
||||
ST[i].sum=ST[i].mark+ST[i].match+ST[i].english+ST[i].c_language+ST[i].pe+ST[i].history+ST[i].software;
|
||||
|
||||
ST[i].average=ST[i].sum/7;
|
||||
}
|
||||
//赋学分
|
||||
for(i=0;i<ST_NUM;i++)
|
||||
{
|
||||
if(ST[i].match>=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;i<ST_NUM;i++)
|
||||
{
|
||||
sum[0]+=ST[i].match;
|
||||
sum[1]+=ST[i].english;
|
||||
sum[2]+=ST[i].c_language;
|
||||
sum[3]+=ST[i].pe;
|
||||
sum[4]+=ST[i].history;
|
||||
sum[5]+=ST[i].software;
|
||||
}
|
||||
for(i=0;i<6;i++)
|
||||
{
|
||||
average[i]=(double)sum[i]/ST_NUM;
|
||||
}
|
||||
}
|
||||
|
||||
void sort()//排名
|
||||
{
|
||||
student temp;
|
||||
int i,j,t,flag=1;
|
||||
//依据学分排名
|
||||
for(i=0;i<ST_NUM;i++)
|
||||
{
|
||||
for(j=0;j<ST_NUM-1-i;j++)
|
||||
{
|
||||
if(ST[j].mark<ST[j+1].mark)
|
||||
{
|
||||
temp=ST[j];
|
||||
ST[j]=ST[j+1];
|
||||
ST[j+1]=temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
//学分相同时依据平均分的排名
|
||||
for (t=0;t<ST_NUM-1;t+=flag)
|
||||
{
|
||||
flag=1;
|
||||
if(ST[t].mark==ST[t+1].mark)
|
||||
{
|
||||
for(i=t;i<ST_NUM;i++)
|
||||
{
|
||||
if(ST[i].mark!=ST[i+1].mark)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
flag++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(flag!=1)
|
||||
{
|
||||
for(i=t;i<t+flag-1;i++)
|
||||
{
|
||||
for(j=t;j<t+flag-1-i;j++)
|
||||
{
|
||||
if(ST[j].mark>ST[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<ST_NUM;i++)
|
||||
{
|
||||
printf("%d\t%d\t%s\t",ST[i].nu,ST[i].num,ST[i].name);
|
||||
printf("%3.2f\t",ST[i].mark);
|
||||
printf("%3.2f\t",ST[i].match);
|
||||
printf("%3.2f\t",ST[i].english);
|
||||
printf("%3.2f\t",ST[i].c_language);
|
||||
printf("%3.2f\t",ST[i].pe);
|
||||
printf("%3.2f\t",ST[i].history);
|
||||
printf("%3.2f\t\t",ST[i].software);
|
||||
printf("%3.2f\t%3.2f\n",ST[i].sum,ST[i].average);
|
||||
}
|
||||
printf("\n");
|
||||
printf("各科平均分\n\t\t\t\t\t高等数学\t大学英语\tc语言\t大学体育\t近代史\t软件技术导论\n");
|
||||
printf("\t\t\t\t");
|
||||
for(i=0;i<6;i++)
|
||||
{
|
||||
printf("\t%.2lf",average[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
if(input()==1)
|
||||
return 0;
|
||||
process();
|
||||
sort();
|
||||
output();
|
||||
return 0;
|
||||
}
|
302
Grade Management/T3.c
Executable file
302
Grade Management/T3.c
Executable file
@ -0,0 +1,302 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#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;i<n;i++)
|
||||
{
|
||||
a[i].no=i+1;
|
||||
scanf("%d",&t);
|
||||
if(t==000)
|
||||
{
|
||||
printf("输入结束\n");
|
||||
break;
|
||||
}
|
||||
else
|
||||
a[i].score=t;
|
||||
}
|
||||
printf("数据库建立完成\n");
|
||||
printf("\n");
|
||||
}
|
||||
//显示成绩
|
||||
void display(Student a[],int n)
|
||||
{
|
||||
int i;
|
||||
printf("序号\t成绩\t\n");
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
printf("%d\t%d\n",a[i].no,a[i].score);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
//按给定成绩查找
|
||||
void findchj(int chj,Student a[],int n)
|
||||
{
|
||||
int i,flag=0;
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
if(a[i].score==chj)
|
||||
{
|
||||
if(flag==0)
|
||||
{
|
||||
printf("序号\t成绩\t\n");//因为该语句嵌套与for循环中故设立标记让该语句仅执行一次
|
||||
flag=1;
|
||||
}
|
||||
printf("%d\t%d\n",a[i].no,a[i].score);
|
||||
}
|
||||
}
|
||||
if(flag==0)
|
||||
printf("输入的成绩没有对应的学生\n");
|
||||
printf("\n");
|
||||
}
|
||||
//按给定顺序号查找
|
||||
void findsxh(int sxh,Student a[],int n)
|
||||
{
|
||||
printf("序号\t成绩\t\n");
|
||||
printf("%d\t%d\n",a[sxh-1].no,a[sxh-1].score);
|
||||
printf("\n");
|
||||
}
|
||||
//从高到低排序
|
||||
void sort_big(Student a[],int n)
|
||||
{
|
||||
int i,j;
|
||||
Student temp;
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
for(j=0;j<n-1-i;j++)
|
||||
{
|
||||
if(a[j].score<a[j+1].score)
|
||||
{
|
||||
temp=a[j];
|
||||
a[j]=a[j+1];
|
||||
a[j+1]=temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("降序排序完成\n");
|
||||
printf("\n");
|
||||
}
|
||||
//从低到高排序
|
||||
void sort_small(Student a[],int n)
|
||||
{
|
||||
int i,j;
|
||||
Student temp;
|
||||
for(i=0;i<n;i++)
|
||||
{
|
||||
for(j=0;j<n-1-i;j++)
|
||||
{
|
||||
if(a[j].score>a[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<t-1;i++)
|
||||
{
|
||||
a[i].no=a[i+1].no;
|
||||
a[i].score=a[i+1].score;
|
||||
}
|
||||
a[t-1].score=0;
|
||||
a[t-1].no=0;
|
||||
printf("\n");
|
||||
}
|
||||
//按给定顺序号修改成绩
|
||||
void replace(int sxh,Student a[],int n)
|
||||
{
|
||||
printf("当前顺序号的成绩为:%d\n",a[sxh-1].score);
|
||||
printf("请输入修改后的成绩:");
|
||||
scanf("%d",&a[sxh-1].score);
|
||||
printf("\n");
|
||||
}
|
234
Grade Management/T4.c
Executable file
234
Grade Management/T4.c
Executable file
@ -0,0 +1,234 @@
|
||||
#include <stdio.h>
|
||||
#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<num;i++)
|
||||
{
|
||||
printf("序号:");
|
||||
if(scanf("%d",&ST[i].nu)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
printf ("学号:");
|
||||
scanf ("%d",&ST[i].SNo);
|
||||
|
||||
printf("姓名:");
|
||||
scanf ("%s",ST[i].Name);
|
||||
|
||||
printf("请输入业务考试成绩:\n");
|
||||
|
||||
printf("高等数学的成绩:");
|
||||
if(scanf("%d",&ST[i].GSHu)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("C语言程序设计的成绩:");
|
||||
if(scanf("%d",&ST[i].CCHeng)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("大学英语视听一的成绩:");
|
||||
if(scanf("%d",&ST[i].Dying)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("软件技术导论成绩:");
|
||||
if(scanf("%d",&ST[i].RDao)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("近代史的成绩:");
|
||||
if(scanf("%d",&ST[i].JDaiSHi)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("大学体育的成绩:");
|
||||
if(scanf("%d",&ST[i].DTi)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("请输入平时表现成绩:\n");
|
||||
|
||||
printf("辅导员评分:");
|
||||
if(scanf("%d",&ST[i].FDaoYuan)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("班主任评分:");
|
||||
if(scanf("%d",&ST[i].BZHuRen)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("同学评分:");
|
||||
if(scanf("%d",&ST[i].Bjin)!=1)
|
||||
{
|
||||
printf("输入错误");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//数据处理
|
||||
void process(int num)
|
||||
{
|
||||
int i;
|
||||
//挂科判断
|
||||
for(i=0;i<num;i++)
|
||||
{
|
||||
if(ST[i].Dying<60)
|
||||
{
|
||||
ST[i].GKeFlag=1;
|
||||
break;
|
||||
}
|
||||
if(ST[i].CCHeng<60)
|
||||
{
|
||||
ST[i].GKeFlag=1;
|
||||
break;
|
||||
}
|
||||
if(ST[i].DTi<60)
|
||||
{
|
||||
ST[i].GKeFlag=1;
|
||||
break;
|
||||
}
|
||||
if(ST[i].JDaiSHi<60)
|
||||
{
|
||||
ST[i].GKeFlag=1;
|
||||
break;
|
||||
}
|
||||
if(ST[i].RDao<60)
|
||||
{
|
||||
ST[i].GKeFlag=1;
|
||||
break;
|
||||
}
|
||||
if(ST[i].GSHu<60)
|
||||
{
|
||||
ST[i].GKeFlag=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//综合成绩计算;
|
||||
for(i=0;i<num;i++)
|
||||
{
|
||||
ST[i].sum+=(ST[i].Dying+ST[i].CCHeng+ST[i].DTi+ST[i].JDaiSHi+ST[i].RDao)*0.7+(ST[i].FDaoYuan+ST[i].BZHuRen+ST[i].Bjin)*0.3;
|
||||
}
|
||||
}
|
||||
//排名
|
||||
void sort(int num)
|
||||
{
|
||||
student temp;
|
||||
int i,j,t,flag=0;
|
||||
//依据是否挂科排名
|
||||
for(i=0;i<num;i++)
|
||||
{
|
||||
for(j=0;j<num-1-i;j++)
|
||||
{
|
||||
if(ST[j].GKeFlag<ST[j+1].GKeFlag)
|
||||
{
|
||||
temp=ST[j];
|
||||
ST[j]=ST[j+1];
|
||||
ST[j+1]=temp;
|
||||
flag++;
|
||||
}
|
||||
}
|
||||
}
|
||||
//未挂科同学排名
|
||||
for (t=0;t<flag-1;t++)
|
||||
{
|
||||
for(i=t;i<flag-1-t;i++)
|
||||
{
|
||||
if(ST[i].ZHeFen<ST[i+1].ZHeFen)
|
||||
{
|
||||
temp=ST[i];
|
||||
ST[i]=ST[i+1];
|
||||
ST[i+1]=temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void output(int num)
|
||||
{
|
||||
int i;
|
||||
double j1,j2,j3;
|
||||
printf("获得奖学金的同学:\n");
|
||||
printf("\t\t\t\t奖学金\t序号\t姓名\n");
|
||||
j1=num*0.03;
|
||||
j2=num*0.07;
|
||||
j3=num*0.2;
|
||||
//四舍五入
|
||||
j1=(int)(j1+0.5);
|
||||
j2=(int)(j2+0.5);
|
||||
j3=(int)(j3+0.5);
|
||||
for (i=0;i<=j1;i++)
|
||||
{
|
||||
printf("\t\t\t\t一等奖\t%d\t%s\t\n",ST[i].nu,ST[i].Name);
|
||||
}
|
||||
for (i=j1;i<j2;i++)
|
||||
{
|
||||
printf("\t\t\t二等奖\t");
|
||||
printf("%d\t%s\t\n",ST[i].nu,ST[i].Name);
|
||||
}
|
||||
for (i=j2;i<j3;i++)
|
||||
{
|
||||
printf("\t\t\t三等奖\t");
|
||||
printf("%d\t%s\t\n",ST[i].nu,ST[i].Name);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int num;
|
||||
printf("请输入学生人数:");
|
||||
scanf("%d",&num);
|
||||
if(input(num)==1)
|
||||
return 0;
|
||||
process(num);
|
||||
sort(num);
|
||||
output(num);
|
||||
return 0;
|
||||
}
|
||||
|
BIN
HomeWork——Airplane/.DS_Store
vendored
Normal file
BIN
HomeWork——Airplane/.DS_Store
vendored
Normal file
Binary file not shown.
426
HomeWork——Airplane/HomeWork——Airplane.c
Normal file
426
HomeWork——Airplane/HomeWork——Airplane.c
Normal file
@ -0,0 +1,426 @@
|
||||
#include<stdio.h>
|
||||
#include<windows.h>
|
||||
#include<string.h>
|
||||
|
||||
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("您的查询结果为:\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("您的查询结果为:\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("\n输入0退出系统\n输入1回到主菜单\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;
|
||||
}
|
10
HomeWork——Airplane/ai.txt
Normal file
10
HomeWork——Airplane/ai.txt
Normal file
@ -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
|
115
LAN QIAO Collegiate Programming Contest/DNA.cp
Normal file
115
LAN QIAO Collegiate Programming Contest/DNA.cp
Normal file
@ -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<iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int space,space2;
|
||||
int n,a,b;
|
||||
|
||||
cin>>n;
|
||||
|
||||
while(n--)
|
||||
{
|
||||
cin>>a>>b;
|
||||
|
||||
for(int k=0;k<b;k++)
|
||||
{
|
||||
space=a-2;
|
||||
space2=0;
|
||||
bool co= true;
|
||||
for(int i=0;i<a-1;i++)
|
||||
{
|
||||
if(space>0&&co)
|
||||
{
|
||||
for(int j=0;j<space2;j++)
|
||||
cout<<' ';
|
||||
space2++;
|
||||
|
||||
cout<<'X';
|
||||
|
||||
for(int j=0;j<space;j++)
|
||||
cout<<' ';
|
||||
space-=2;
|
||||
cout<<'X'<<endl;
|
||||
}
|
||||
else if(co)
|
||||
{
|
||||
for(int j=0;j<space2;j++)
|
||||
cout<<' ';
|
||||
cout<<'X'<<endl;
|
||||
space2--;
|
||||
co= false;
|
||||
space=1;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int j=0;j<space2;j++)
|
||||
cout<<' ';
|
||||
space2++;
|
||||
cout<<'X';
|
||||
|
||||
for(int j=0;j<space;j++)
|
||||
cout<<' ';
|
||||
space+=2;
|
||||
cout<<'X'<<endl;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
space=a-2;
|
||||
space2=0;
|
||||
for(int j=0;j<space2;j++)
|
||||
cout<<' ';
|
||||
space2++;
|
||||
|
||||
cout<<'X';
|
||||
|
||||
for(int j=0;j<space;j++)
|
||||
cout<<' ';
|
||||
space-=2;
|
||||
cout<<'X'<<endl<<endl;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
43
LAN QIAO Collegiate Programming Contest/n皇后.cp
Normal file
43
LAN QIAO Collegiate Programming Contest/n皇后.cp
Normal file
@ -0,0 +1,43 @@
|
||||
#include<iostream>
|
||||
|
||||
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;i++)
|
||||
{
|
||||
if(!col[i]&&!dg[u+i]&&!udg[n-u+i])
|
||||
{
|
||||
g[u][i]='Q';
|
||||
col[i]=dg[u+i]=udg[n-u+i]= true;
|
||||
dfs(u+1);
|
||||
col[i]=dg[u+i]=udg[n-u+i]= false;
|
||||
g[u][i]='.';
|
||||
}
|
||||
}
|
||||
}
|
||||
int main()
|
||||
{
|
||||
cin>>n;
|
||||
for(int i=0;i<n;i++)
|
||||
for(int j=0;j<n;j++)
|
||||
g[i][j]='.';
|
||||
|
||||
dfs(0);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user