C++大学作业源码汇总

最长字串

每行一个字符串,查找最长子串,子串的正序、倒序的2种形式都要查找
输入:

aabcccc
aacbabb
ccccabc

输出 (或cba):

abc

源码
#include "ac.h"
ofstream fout("in.txt");

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
bool cmplen(string a,string b){
	if (a.length()<b.length()) return 1; else return 0;
}
void t(){
	string ss,sr;
	vector<string> str,s; vector<int> x;
	char stmp[101]={0};
	cout<<"键入Ctrl+Z(即^Z)以结束输入:\n";
	while (cin.getline(stmp,101)) s.push_back(stmp);
	sort(s.begin(),s.end(),cmplen);
//	for (auto i:s) cout<<i<<"\t";
	int all=s.size()-1;
	for (int i=0; s[0].length()==s[i].length() && i<=all; i++){
		bool yes=1; ss=s[i]; sr=ss; reverse(sr.begin(),sr.end());
		for (int j=0; j<=all; j++) if (s[j].find(ss)==s[j].npos && s[j].find(sr)==s[j].npos) {yes=0; break;}
		if (yes) x.push_back(i);
	}
	cout<<"符合条件的子串有:";
	if (!x.empty()) {for (auto i:x) cout<<s[i]<<"\t"; return;}
	//下面判断等长字符串组中重复子串,只需要在第一个字符串中找子串(否则上面就已经找出来了)
	for (int i=s[0].length(); i>=1; i--){
		for (int p=0; p<=s[0].length()-i; p++){
			bool yes=1; ss=s[0].substr(p,i); db_(ss);
			if (!str.empty() && str.back().length()!=ss.length()) goto final;
			sr=ss; reverse(sr.begin(),sr.end());
			for (auto j:s) if (j.find(ss)==j.npos && j.find(sr)==j.npos) {db(j); yes=0; break;}
			if (yes) str.push_back(ss);
		}
	}
	final: if (!str.empty()) {for (auto i:str) cout<<i<<"\t"; return;}
	throw "请检查输入数据,或向程序员反馈bug";
}
void txt(int lines=20){
	while (lines--){
		int col=rd(10,10);
		while (col--) fout<<(char)(rd((int)'a',(int)'z'));
		fout<<endl;
	}
	fout.close();
}
int main(){
	txt(10000);
	changeio;
	try {t();} catch (const char* &e) {cout<<"Error: "<<e;}
}

期末大作业:数据处理系统

点击查看代码
//#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
//#include <cmath>
//#include <ctime>
#include <conio.h>
#include <algorithm>
//#include <limits>
#include <windows.h>
using namespace std;

#define apart() cout<<"_____________________________________________\n"
const char pic[]="\n ███████╗███████╗██████╗  █████╗ ████████╗ █████╗ ███╗   ███╗ ██████╗ ██████╗ \n ██╔════╝╚══███╔╝██╔══██╗██╔══██╗╚══██╔══╝██╔══██╗████╗ ████║██╔════╝ ██╔══██╗\n █████╗    ███╔╝ ██║  ██║███████║   ██║   ███████║██╔████╔██║██║  ███╗██████╔╝\n ██╔══╝   ███╔╝  ██║  ██║██╔══██║   ██║   ██╔══██║██║╚██╔╝██║██║   ██║██╔══██╗\n ███████╗███████╗██████╔╝██║  ██║   ██║   ██║  ██║██║ ╚═╝ ██║╚██████╔╝██║  ██║\n ╚══════╝╚══════╝╚═════╝ ╚═╝  ╚═╝   ╚═╝   ╚═╝  ╚═╝╚═╝     ╚═╝ ╚═════╝ ╚═╝  ╚═╝\n ";

#if 0
//ifstream cin("i.txt");
//#decine cin cin
//ifstream fout("o.txt");
//#decine cout fout
#include <assert.h>
string db_var;
int db_line=0;
#define db(x) {if (db_var!=#x) {db_var=#x; cerr<<'\n'<<#x;} \
if (db_line!=__LINE__) {db_line=__LINE__; cerr<<'@'<<__LINE__;} \
cerr<<":"<<x<<"_	"; }
#define dd() cout<<'\n'

#else
#define db(x)
#define dd()
#endif
//调试宏函数
//功能实现:排序、常规指标计算、数据迁移、错误处理、cmd交互

ifstream fin;
ofstream fout;
streambuf *stdcin=cin.rdbuf(); streambuf *stdcout=cout.rdbuf();
clock_t timer;
string input="",input_="",title="",error="",savename="o",inname="i.txt"; char kd; bool back=1,txt=1;
string cmdcolor[10]={"00","07","f0","6f","e0","2f","b0","3f","9f","df"};	//cf红,2f绿
struct student{
	string info[41];//至多:20个数据属性,如学号、姓名等+科目成绩
	float sc[21];	//至多:20个科目的成绩
	bool zero;
	float avg;
	short max=1,min=1;
} stu[501];			//至多:一个班有500个同学
int gra=1,fp=0,maxsub=0,info=2,refer=0,fsize=0,id=0,i=0,errcount=0,color=7;
char c1='f',c2='3';
bool save=false,str=true;

int H2int(char c){
	if (c>='a') c-=('a'-'A');
	return ((c>'9')?(c-'A'+10):(c-'0'));
}
void SetColor(char f=c1,char b=c2) {
	//db(H2int(f));
	WORD wColor = ((H2int(b) & 0x0F) << 4) + (H2int(f) & 0x0F);
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}
void wt(int wait,bool clear=1){
	for (int t=0; t<=wait; 	Sleep(5),t+=5) if (_kbhit()) {if (clear) _getch(); return;}
}
void typer(string text,int wait=40){
	for (int pos=0; pos<=text.length(); ++pos){
		cout<<text[pos];
		wt(wait);
	}
	wt(3000,0);
	cout<<"\033[1A\r\033[2k\n                        ";
}

void egg(){
	const char eggs[7][12]={" (-_-) "," (I_I) "," (IvI) "," (IvI)/"};
	do{
		for (int k=0; k<=100; ++k){
			cout<<"\033[1A\r\033[2k\n  "<<eggs[0];
			wt(400);
			cout<<"\033[1A\r\033[2k\n  "<<eggs[1];
			wt(100);
		}
		typer("眼皮子都快给你弄破了!有何贵干?");
	} while(!_kbhit());
	wt(500);
	do{
		for (int egg=1; egg<=3; ++egg){
			cout<<"\033[1A\r\033[2k\n  "<<eggs[egg];
			wt(700);
		}
		typer("给你一个眼神,自己体会         ");
	} while(!_kbhit());
	cout<<"\033[1A\r\033[2k                                 ";
}

void StuScoPro(bool jump=0); void StuScoExp(bool upside=0, short jump=0); void StuScoF(); void StuScoSys(); void StuScoSort();

bool enter(bool reset=1){	//判断文本回车符,原理是预读下一个字符
	fp=cin.tellg();	//dd(); db(fp);
	do{
		cin.get(kd);
	}while (kd==' ' || kd=='\t');
	if (cin.eof()) return 1;
	if (reset) cin.seekg(fp);
	if (kd==13 || kd=='\n' || kd==0) return 1;	//10回车,13换行
	return 0;
}

float cin_lack(float score=0){
	fp=cin.tellg();
	cin>>score; //db(score);
	if (cin) return score;
	cin.clear();	//清除-1状态
	cin.seekg(fp);	//恢复上次读写位置
	cin>>input; //db(input);
	stu[id].zero=1;
	return -1; 		//表示缺省值
}

bool cmp_sc(student a, student b){	//分数倒序
	return a.sc[refer]>b.sc[refer];
}
bool cmp_sc_(student a, student b){
	return a.sc[refer]<b.sc[refer];
}
bool cmp_str(student a, student b){
	return a.info[refer]>b.info[refer];
}
bool cmp_str_(student a, student b){	//字符串正序
	return a.info[refer]<b.info[refer];
}
student *base=NULL,*temp=NULL,*memory=NULL;
void ksort(int l,int r,int ref){
	system(("title [排序]"+title).c_str());
	if (str){
		db(str);
		sort(stu+1,stu+id+1,cmp_str_);
		stable_sort(stu+1,stu+id+1,cmp_str_);
	} else {
		sort(stu+1,stu+id+1,cmp_sc);
		stable_sort(stu+1,stu+id+1,cmp_sc);
	}
	//快排原理如下
	/*
	if (l>=r) return;
	int i=l,j=r;
	*base=stu[l];
	if (str) {
		while (stu[i].info[ref] >= base->info[ref] && i<j) ++i;
		while (stu[j].info[ref] <= base->info[ref] && i<j) --j;
		db(i); db(j); db(stu[j].info[ref]); db(stu[i].info[ref]);
		if (i<j) {
			*temp=stu[i]; stu[i]=stu[j]; stu[j]=*temp; db(stu[i].info[ref]);
			}
	} else
	while (i<j){
		while (stu[i].sc[ref] >= base->sc[ref] && i<j) ++i;
		while (stu[j].sc[ref] <= base->sc[ref] && i<j) --j;
		db(i); db(j); db(stu[j].sc[ref]); db(stu[i].sc[ref]);
		if (i<j) {*temp=stu[i]; stu[i]=stu[j]; stu[j]=*temp; db(stu[i].sc[ref]);}
	}
	stu[l]=stu[i];
	stu[i]=*base;
	ksort(l,i-1,ref);
	ksort(i+1,r,ref);
	*/
	system(("title "+title).c_str());
}

int x=0,y=1;
void stusearch(bool list=0,bool anti=0){
	system(("title ["+to_string(x)+"/"+to_string(id)+"搜索:"+input_+"]"+title).c_str());
	if (input_.empty()) return;
	for (; x<=id; ++x){
		for (; y<=info; ++y){
			if (stu[x].info[y].find(input_)!=stu[x].info[y].npos) {
				input=stu[x].info[y]; ++y;
				temp=&stu[x]; db(temp);
				if (list){		//如果需要列表
					cout<<'\n';
					for (int i=1; i<=info; ++i) cout<<temp->info[i]<<"  ";
					for (int i=1; temp->sc[i]!=-2; ++i) 
						 if (i==temp->max) {SetColor(c2,c1); cout<<temp->sc[i]<<"	"; SetColor();}
						 else if (i==temp->min) {SetColor('4',c2); cout<<temp->sc[i]<<"	"; SetColor();}
						 else cout<<temp->sc[i]<<"  ";
				}
				return;
			}
		}
		y=1;
	}
	x=0;
	if (temp==NULL) {system(("title [无结果]"+title).c_str()); return;}
	else temp=NULL;	//置空以返回'无结果'
	system(("title [搜索完毕]"+title).c_str());
}

void decer(short pos){	//单个删除、修改时减去数值
	for (int i=0; i<=maxsub && stu[x].sc[i]>0; ++i) stu[0].sc[i]-=stu[pos].sc[i];
}

void fix(){
	save=1;
	cout<<"\033[1A\r\033[2k\n每行必须输入"<<info<<"列 个人信息\n按原格式输入,-1为缺省值(缺省值或无信息),直到输入-2时停止:\n";
	i=0;
	do{
		++i;
		cin>>temp->info[i];
		if ("-1"==temp->info[i]) temp->info[i].clear();
		else if ("-2"==temp->info[i]) goto ender;
		db(temp->info[i]);
	} while ( i<info );
	if (temp->info[i]=="-2") temp->info[i]=="";
	i=0;
	do{
		++i;
		cin>>temp->sc[i]; db(temp->sc[i]);
		if (cin.fail()) throw "信息部分可键入任何字符,后面的数据部分只能键入数字";
	}while (temp->sc[i] >=-1);
	for (int i=1; i<=20; ++i) {
		switch((short)temp->sc[i]){
			case 0: continue;
			case -1: temp->zero=1; continue;
			case -2: goto ender;
			default: break;
		}
		stu[0].sc[i]+=temp->sc[i];
		stu[id].sc[0]+=temp->sc[i];
		stu[0].sc[0] +=temp->sc[i];
		if (temp->sc[i]>temp->sc[temp->max]) temp->max=i;
		if (temp->sc[i]<temp->sc[temp->min]) temp->min=i;
	}
	ender:;
}

bool AutoFill(bool reset=1){
	bool tab=0;
	if (reset) {temp=NULL;}
	kydown:
	cout<<" -.末尾插入  _.删除末尾  Tab.补全  Ctrl+Q.搜索出列表  Esc.返回\n要查找/操作的对象:"<<input;
	do{
	kd=getch();
	switch (kd) {
		case 27: return 1;
		case '\b':	//若按下退格键
			tab=0;
			if (input.length()>0) {
				cout<<'\b'<<(char)127<<'\b'; input.pop_back();	//退格字符与删除字符
			}
			continue;
		case '\t':	//若按下TAB键
			if (input.empty()) continue;
			if (!tab) {input_=input; tab=1;}
			for (int i=1; i<=input.length(); ++i) cout<<'\b'<<(char)127<<'\b';
			stusearch();
			cout<<input;
			continue;
		case 17:	//若按下Ctrl+Q
			if (input.empty()) continue;
			x=0; y=1; input_=input;
			do{
				stusearch(1);
			} while (temp!=NULL);
			cout<<'\n';
			goto kydown;
		case 13:	//若按下esc键
			if (temp==NULL) {input_=input; stusearch();} if (input.empty()) continue; return 0;
		case '_':
			decer(id);
			memset(&stu[id],0,sizeof(stu[id]));
			id-=1; save=1;
			throw "已删除";
		case '-':
			if (id>=500) throw "超过设定500人,无效操作";
			temp=&stu[id+1]; fix(); ++id; goto kydown;
	}
	cout<<kd;
	input=input+kd;
	} while (1);	//放心,肯定跳的出来
	return 0;
}

int main(int argc, char *argv[]){
	if (argc==2) inname=argv[1];
	cout<<pic;
	//db((int)(getch())); 
	try {StuScoPro(1); system("color 3f");} catch(const char* &e) {cout<<"自动导入>>>>"<<e<<"\n";}
	begining:
	cin.rdbuf(stdcin);  fin.close(); cout.rdbuf(stdcout);  fout.close(); cin.clear();
	//fin.open("inn.txt");
	//float a; fp=fin.tellg();  fin>>a; db(a);
	//if (!fin) cout<<"error"; cout<<a; fin.clear(); fin.seekg(fp); db(fin.tellg()); fin>>input; db(fin.tellg()); cout<<input;
	//fin.close();
	try{
		StuScoSys();	//try...catch结构很好的解决了异常抛出的问题
	}catch(const char* &e){
		system("color cf");
		error=e;
		cout<<"\n>>>>"<<e<<"\n";
		input="title 异常:";
		input=input+e;
		system(input.c_str());
		if (save) {
			cout<<"要尝试恢复并另存为文件吗?[Y/N]";
			kydown3: switch (getche()) {
				default: goto kydown3;
				case 'y': case 'Y': StuScoExp(); break;
				case 'n': case 'N': break;
			}
		}
	}
	if (back) goto begining;
	return 0;
}


string tip_ctrl_s(){
	if (save) return "Ctrl+S覆盖保存";
	else return "		 ";
}
void title_save(){
	db(save);
	if (save) title="*"+title+"[未保存]";
	system(("title "+title).c_str());
}

void check_null(){
	if (stu[1].info[1]=="") throw "无数据!请先导入!\n";
}

void StuScoSys(){
	beginer_: system(("color "+cmdcolor[color]).c_str());
	beginer:
	//system("cls");
	if (!error.empty()) cout<<"\n最近的异常:"<<error;
	title="简易数据管理系统 v0.2 "+inname+"→"+savename+".txt";
	title_save();
	cout<<"\n┌───────────────────────────────────────────┐\n│\t欢迎使用简易数据管理系统 v0.2\t    │\n│  "<<tip_ctrl_s()<<"    Shift+4/~可倒序输出    │\n│\t:)\t\t\tby LX       │\n└───────────────────────────────────────────┘"
	<<"\n 1.导入   2.排序   3.查找修改   4.另存为   0.关于   ~.预览   -.清屏   =.变色\n";
	apart();
	kydown:
	//与getchar()的区别:getch隐藏输入且仅接受一个字符;getchar正常显示输入,输入字符串存入“键盘缓冲区”这个盒子,再次getchar将只从盒子抽取单字,直到抽完为止再重新要求用户输入
	switch (getch()) {
		default: goto kydown;
		case 27:
			if (save) {
				cout<<"有未保存的数据,是否覆盖保存后退出?[Y是/N否/Esc暂不退出]\n";
				kydown2: switch (getche()) {
					default: goto kydown2;
					case 27: goto beginer;
					case 'y': case 'Y': StuScoExp(); exit(0);
					case 'n': case 'N': exit(0);
				}
			}
			exit(0);
		case '1': StuScoPro(); goto beginer_;
		case '2': check_null(); StuScoSort(); goto beginer;
		case '3': check_null(); StuScoF(); goto beginer;
		case '4': txt=true; cout<<"将保存在与输入文件同目录下,请输入文件名:"; cin>>savename; StuScoExp(); goto beginer;
		//win10权限限制
		case '0':
			cout<<"更新v0.2:控制台字体颜色可变,拖拽文件参数支持\n关于:本软件旨在解决简单数据处理与完成C语言作业的使命\n作者:李翔   \n";
			if (getch()==' '){MessageBox(GetForegroundWindow(),"(#°Д°)/你发现了空格彩蛋","Σ(っ °Д °;)っ",0); egg();}
			goto beginer;
		case '`': txt=false; StuScoExp(); goto beginer;
		case '~': txt=false; StuScoExp(1); goto beginer;
		case 19 : txt=true; if (save) {StuScoExp(0,1); cout<<"√已保存√"; goto beginer;} goto kydown;
		case '=':
			color%=9; ++color;
			c1=cmdcolor[color][1]; c2=cmdcolor[color][0]; db(to_string(c1)); db(("color "+to_string(c1)+to_string(c2)).c_str());
			system(("color "+cmdcolor[color]).c_str()); //db(input);
			goto kydown;
		case '-': system("cls"); goto beginer;
	}
}

void StuScoPro(bool jump){
	if (jump) goto autotxt;
	cout<<"输入范例:\n"
	<<"1\n1(一1班)\n001 胸针 0 -1 -\t(\"-1\"、\"-\"非法成绩作缺省值,不包括0分)\n002 真由理 6 8 7\n004 红莉栖 10 9.2 9.7\n"
	<<">> 1.文本导入   Esc.返回"; //2.屏幕输入
	kydown: 
	switch (getch()) {
		default: goto kydown;
		case 27 : return;
		case '1': txt=1; break;
		//case '2': txt=0; break;
	}
	cout<<"\r请输入个人信息列数:"; cin>>info;
	if (info<=0) throw "个人信息列数不能小于1";
	if (txt) {
		inname="i.txt";
		cout<<"请在同目录下将导入数据命名为\"i.txt\",含有中文请使用ANSI编码避免乱码,然后";
		system("pause");
		autotxt:
		fin.open(inname,ios::binary);
		if (fin.fail()) throw "打开"+inname+"文件失败";
		else {
			if ((fin.get() & 0x80)!=0) throw "文本不是ANSI编码,请手动转换!";
			//ansi用"7bit+最高位保留0"编码,0x80为"10000000",与ansi编码与运算后必能得到"10000000",否则不是ansi编码
			fin.clear();
		}
		fin.seekg(0,ios::end); fsize=fin.tellg(); fin.seekg(0,ios::beg);	//统计文本大小
		cin.rdbuf(fin.rdbuf());	//cin重定向为fin
	}
	int cls=1; errcount=0; 
	cin>>gra;
	timer=clock();
	while (!cin.eof()) {						//班级导入,知道文件结束
		id=0;
		cin>>cls;
		input="title 导入:"+to_string(gra)+"级"+to_string(cls)+"班_同学"+to_string(id)+"  缺"+to_string(errcount)+"处数据"; system(input.c_str());
		for (int j=1; j<=41; ++j){				//首行导入
			cin>>stu[0].info[j];
			if (enter()) break;
		}
		while (!cin.eof() && id<=100) {			//个人信息导入
			i=0; ++id; //db(id);
			for (int j=1; j<=info; ++j){
				cin>>stu[id].info[j];
				
			}
			while(!enter() && i<=20) {			//个人学科导入
				++i;
				if (txt) cout<<"已完成"<<cin.tellg()*100/fsize+1<<"%,已跳过"<<errcount<<",耗时"<<(clock()-timer)/1000.0<<"秒\r";
				stu[id].sc[i]=cin_lack(); //db(id); db(i); db(stu[id].sc[i]); dd();
				if (stu[id].sc[i]<=0) {++errcount; continue;};
				stu[id].sc[0]+=stu[id].sc[i];
				stu[0].sc[i] +=stu[id].sc[i];
				stu[0].sc[0] +=stu[id].sc[i];
				if (stu[id].sc[i]>stu[id].sc[stu[id].max]) stu[id].max=i;
				if (stu[id].sc[i]<stu[id].sc[stu[id].min]) stu[id].min=i;
			} 
			stu[id].avg=stu[id].sc[0]/i;
			stu[id].sc[i+1]=-2;
			if (maxsub<i) maxsub=i;
			if (id>=500) throw "班级人数上限500人已达,导入中断!";
		}
	}
	cin.rdbuf(stdcin); fin.close(); save=true; error="";	//状态重置为成功,输入流重置
	system("color 2f"); cout<<"\n√导入完成√";
	savename="o_"+to_string(gra)+" "+to_string(cls);
	system(("title 完成:"+to_string(gra)+"级"+to_string(cls)+"班_同学"+to_string(id)+"  缺"+to_string(errcount)+"处数据").c_str());
}

void StuScoExp(bool upside, short jump){
	if (upside) cout<<"[倒序]";
	cout<<"";
	if (jump==1) goto saver;
	else if(jump==-1) {txt=false; goto pre;}
	if (txt){
		fin.open(savename+".txt");
		if (!fin.fail()) {
			fin.close();
			cout<<"已有"<<savename<<".txt,是否覆盖?[Y/N]";
			kydown2:
			switch (getche()) {
				default: goto kydown2;
				case 'n': case 'N': return;
				case 'y': case 'Y': break;
			}
		}; saver:
		fout.open(savename+".txt",ios::out); cout.rdbuf(fout.rdbuf());
		if (fout.fail()) {throw "创建o.txt文件失败";}
	}
	pre:
	i=1; cout<<"序号\t";
	while (stu[0].info[i]!=""){
		cout<<stu[0].info[i]<<'\t';
		++i;
	}
	cout<<"总分   平均分\n";
	
	for (int k=1; k<=id; ++k){
		if(stu[i].zero) cout<<setw(3)<<k<<"* ";
		else cout<<setw(3)<<k<<"  ";
		if (upside) i=id-k+1; else i=k;	//倒序输出处理
		for (int j=1; j<=info; ++j)		cout<<stu[i].info[j]<<"	 ";
		for (int j=1; j<=maxsub; ++j)
		 if (stu[i].sc[j]<=-1)  {SetColor('7'); cout<<"缺	 "; SetColor();}
		 else if (j==stu[i].min) {SetColor(c1+1); cout<<stu[i].sc[j]<<"	 "; SetColor();}
		 else if (j==stu[i].max) {SetColor(c1+2); cout<<stu[i].sc[j]<<"	 "; SetColor();}
		 else cout<<stu[i].sc[j]<<"	 ";
		cout<<stu[i].sc[0]<<"	 "<<stu[i].avg<<"\n";
	}
	
	cout<<"总分";
	for (int i=0; i<=info; ++i) cout<<'\t';
	for (int i=1; i<=maxsub; ++i)		cout<<stu[0].sc[i]<<"	 ";
	cout<<stu[0].sc[0];
	
	cout<<"\n平均分";
		for (int i=0; i<=info; ++i) cout<<'\t';
		for (int i=1; i<=maxsub; ++i)		cout<<setprecision(5)<<stu[0].sc[i]/id<<"	 ";
		cout<<setprecision(5)<<stu[0].sc[0]/id;
	
	cout.rdbuf(stdcout);  fout.close();
	if (txt==true) save=false;
}

void StuScoSort(){
	cout<<"列头: -1.返回  0.总分  ";
	for (int i=1; stu[0].info[i]!=""; ++i) cout<<i<<"."<<stu[0].info[i]<<"  ";
	cout<<"\n按第几列:";
	cin>>refer;
	
	if (refer<0) return;
	else if (refer==0) str=0;
	else if ((refer-info)>0) {
		str=0;
		refer-=info;
	}
	//base = new(student); temp = new(student);	//系统给指针新的随机空间
	ksort(1,id,refer);
	//delete base; delete temp; temp=NULL; base=NULL;	//回收空间
	StuScoExp(0,-1);
	return;
}

void StuScoF(){
	input="";
	cout<<"可输入\"缺\"、\"lack\"来查看所有不正常录入个体\n";
	if (AutoFill()) return;
	if (input=="*" || input=="缺") {
		cout<<"\n缺省值名单:";
		for (int k=1; k<=id; ++k){
			if (stu[k].zero==1){
				cout<<'\n';
				for (int i=1; i<=info; ++i) cout<<stu[k].info[i]<<"  ";
				for (int i=1; stu[k].sc[i]!=-2; ++i) cout<<stu[k].sc[i]<<"  ";
			}
		}
		return;
	}
	if (temp==NULL) throw "无相关结果";
	cout<<"\n>>操作: 1.修改  2.删除  3.其前插入  #.其后插入  =.查找下一个  Esc.返回\n>>搜索到对象:";
	refind:
	if (temp!=NULL){
		for (int i=1; i<=info; ++i) cout<<temp->info[i]<<"  ";
		for (int i=1; temp->sc[i]!=-2; ++i) cout<<temp->sc[i]<<"  ";
	}
	kydown2:
	switch (getch()) {
		default: goto kydown2;
		case 27: return;
		case '1': decer(x); break;
		case '2':
			for (int i=x; i<=id-1; ++i) stu[i]=stu[i+1];
			decer(x);
			memset(&stu[id],0,sizeof(stu[id]));
			id-=1;
			return;
		case '3':
			for (int i=id; i>=x; --i) stu[i+1]=stu[i]; ++id;
			break;
		case '#':
			for (int i=id; i>=x+1; --i) stu[i+1]=stu[i]; ++id; temp=&stu[x+1];
			break;
		case '=': stusearch(); cout<<"\033[1A\r\033[2k\n>>搜索到对象:"; goto refind;	//这个033[1A...的是CMD自带的备用输出流
		//case '-': stusearch(0,1); cout<<"\033[1A\r\033[2k\n>>搜索到对象:"; goto refind; 双链表
	}
	fix();
	temp=NULL;
	return;
}
//终于写完了,TAT
posted @ 2022-03-20 18:32  Nolca  阅读(212)  评论(0)    收藏  举报