跳到正文

个人记录

多功能V5.0

Literally约 25 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年3月8日
篇幅
约 25 分钟

版本

  1. v1当前
C++
#include <iostream>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <iomanip>
#include <conio.h>
#include <windows.h>
#include <fstream>

using namespace std;
long double a[10010];
#define do 523
#define re 578
#define mi 659
#define fa 698
#define sol 784
#define la 880
#define ti 988

void qp(){
	cout<<endl<<"正在清屏中……………………………………………………"<<endl;
	Sleep(1000);
	system("cls");
	cout<<"清屏成功!"<<endl;
}

void ASCII(){
    int ch;
    cout<<"按esc退出哦!"<<endl;
    cout<<"输入一个键试试?"<<endl;
    while(true){
        if (_kbhit()){//是否按下
            ch = _getch();//当前按下的按键
            if (ch == 27){
                cout <<"退出成功!233"<< endl;
                break;
            }else if(ch==32){
                cout<<"("<<"空格"<<")"<<":"<<ch<<endl;
            }else{
            	cout<<char(ch)<<":"<<ch<<endl;
			}

        }
    }
    Sleep(1000);
    qp();
}

void swap(int &a,int &b){
    int temp;
    temp=a;
    a=b;
    b=temp;
}
long double jia(){
    long double m,n;
    cout<<"请输入两个加起来小于 "<<LONG_LONG_MAX<<" 的数:";
    cin >> m >> n;
    return m+n;
}
long double jian(){
    long double m,n;
    cout << "请输入被减数和减数:";
    cin >> m >> n;
    return m-n;
}
long double cheng(){
    long double m,n;
    cout<<"请输入两个乘数:";
    cin >> m >> n;
    return m,n;
}
void chu(){
    long double m,n;
    cout << "请输入被除数和除数:";
    cin >> m >> n;
    if(n==0) cout<<"非法运算哦23333";
    else cout<<m/n;
}
long double square(){
    int n;
    cout<<"请输入要平方的数:";
    cin>>n;
    return n*n;
}
void squareroot(){
    long double m;
    cout<<"请输入要平方根的数:";
    cin >> m;
    if(m<0){
        cout<<"非法运算"<<endl;
        return;
    }
    cout<<fixed<<setprecision(8)<<sqrt(m)<<endl;
}
long double jiecheng(){
    int s;
    long double n=1;
    cout<<"请输入要阶乘的数:";
    cin>>s;
    cout<<endl;
    for(int i=1;i<=s;i++){
        n*=i;
    }
    if(n<0){
        cout<<"非法运算";
    }else{
        cout<<"答案:"<<n<<endl;
    }
}
long double power(){
	cout<<"请输入m和n(结果是m的n次方):";
    long double m;
    double n;
    cin >> m >> n;
    cout<<pow(m,n)<<endl;
}

void math(){
    cout << "1 +,2 -,3 *,4 /,5平方,6平方根,7阶乘,8开方,0退出" << endl;
    char n;
    while(1){
    	cin >> n;
        if(n == '1') cout<<jia()<<endl;
    	else if(n == '2') cout<<jian()<<endl;
    	else if(n == '3') cout<<cheng()<<endl;
    	else if(n == '4') chu();
    	else if(n == '5') cout<<square()<<endl;
    	else if(n == '6') squareroot();
	    else if(n == '7') jiecheng();
	    else if(n == '8') cout<<power()<<endl;
	    else if(n == '0') break;
    	else cout<<"这是什么运算?我听不懂233"<<endl;
	}

}

void sortt(){
    int n,c;
    clock_t start,finish;
    cout<<endl<<"一共几个数?请回答:";
    cin >> n;
    cout<<endl<<"请问要从大到小排序还是从小到大排序?(从小到大1,从大到小2):";
    cin>>c;
    cout<<"请输入要排序的数"<<endl;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    start=clock();
    if(c==1){
        sort(a + 1,a + n + 1);
    }else if(c==2){
        if(n%2==0){
            for(int i=1;i<=n/2;i++){
                swap(a[i],a[n-i+1]);
            }
        }else{
            for(int i=1;i<=(n-1)/2;i++){
                swap(a[i],a[n-i+1]);
            }
        }
    }
    cout<<"-----------------------------------------------华丽丽的分割线-----------------------------------------------"<<endl;
    for(int i = 1; i <= n; i++){
        cout << a[i] << " ";
    }
    cout<<endl;
    finish=clock();
    cout<<"恭喜您,排序成功!用时:"<<(finish-start)/1000.0<<"s"<<endl;
    if((finish-start)/1000.0>1){
        cout<<"这要是交到洛谷,估计早TLE了(小声BB)"<<endl;
    }
}

void timme(){
    time_t now = time(0);
    tm *ltm = localtime(&now);
    cout << "年: "<< 1900 + ltm->tm_year << endl;
    cout << "月: "<< 1 + ltm->tm_mon<< endl;
    cout << "日: "<<  ltm->tm_mday << endl;
    cout << "时间: "<< ltm->tm_hour << ":";
    cout << ltm->tm_min << ":";
    cout << ltm->tm_sec << endl;
}

void hezi(){
    int roundd = 0;
    srand(time(NULL));
    int wohe = 0;
    int aihe = 0;
    while(1){
        int wog;
        int aig;
        cout << "盒子数" << wohe << endl ;
        cout << "回合数:" << roundd << endl << endl;
        cout << "0:盒子 9:防 1:冰 2:火球 3:闪电 4:天使 5:魔鬼" << endl << endl;
        cout << "玩家选择:";
        int n;
        cin >> n;
        if(n > wohe && n != 9){
            cout << "盒子不够" << endl << endl;
            continue;
        }
        wog = n;
        if(n == 0){
            wohe++;
        }else{
            if(n==1){
                if(wohe<1) {cout << "盒子不够" << endl << endl; continue;}
                else wohe--;
            }else if(n==2){
                if(wohe<2) {cout << "盒子不够" << endl << endl; continue;}
                else wohe-=2;
            }else if(n==3){
                if(wohe<3) {cout << "盒子不够" << endl << endl; continue;}
                else wohe-=3;
            }else if(n==4){
                if(wohe<4) {cout << "盒子不够" << endl << endl; continue;}
                else wohe-=4;
            }else if(n==5){
                if(wohe<5) {cout << "盒子不够" << endl << endl; continue;}
                else wohe-=5;
            }else if(n==9){

            }else{
                cout<<"盒子不够"<<endl << endl;continue;
            }
        }
        int s = rand() % 3 + 1;
        if(s == 1 || roundd == 0){
            aihe++;
            aig = 0;
        }
        else if(s == 2 || aihe == 0){
            aig = 9;
        }
        else{
            switch(aihe){
                case 1:
                    aig = 1;
                    aihe -= aig;
                    break;
                case 2:
                    aig = rand() % 2 + 1;
                    aihe -= aig;
                    break;
                case 3:
                    aig = rand() % 3 + 1;
                    aihe -= aig;
                    break;
                case 4:
                    aig = rand() % 4 + 1;
                    aihe -= aig;
                    break;
                default:
                    aig = 5;
                    aihe -= aig;
                    break;
            }
        }
        cout << "电脑选择:" << aig << endl << endl;
        if(wog != 9 && aig != 9){
            if(wog == aig)
            {
                cout << "平局!进入下一回合!" << endl << endl;
            }
            else if(wog > aig)
            {
                cout << "玩家胜!" << endl << endl;
                break;
            }
            else
            {
                cout << "电脑胜!" << endl << endl;
                break;
            }
        }
        else if((wog == 9 && aig != 5) || (aig == 9 && wog != 5) || (aig == 9 && wog == 9)){
            cout << "平局!进入下一回合!" << endl << endl;
        }
        else if(wog == 5 && aig == 9){
            cout << "玩家胜!" << endl << endl;
            break;
        }
        else if(wog == 9 && aig == 5){
            cout << "电脑胜!" << endl << endl;
            break;
        }
        roundd++;
    }
    Sleep(2000);
    qp();
}

void xiaohua(){
    cout<<"函数=含树 想一想,一个人含着一棵树!?"<<endl;
    cout<<"一次函数=一刺含树 想一想,一个人含着一棵带有一根刺的树!?"<<endl;
    cout<<"二次函数=二刺含树 想一想,一个人含着一棵带有两根刺的树!?"<<endl;
    cout<<"反函数=反含树 想一想,一个人反着含着一棵树!? "<<endl;
    cout<<"偶函数=藕含树 想一想,一个藕片含着一棵树!? "<<endl;
    cout<<"奇函数=鸡含树 一只鸡含着一棵树!?"<<endl;
    cout<<"高斯函数=高斯含树 高斯含着一棵树!?"<<endl;
    cout<<"三角函数=三角含树 三角含着一棵树!?"<<endl;
    cout<<"网友:23333"<<endl;
}

void repeat(){
    string x;
    cout<<"复读什么?"<<endl;
    cin>>x;
    int y;
    cout<<"复读多少次?"<<endl;
    cin>>y;
    for(int i=0;i<y;i++){
        cout<<x<<endl;
    }
    cout<<"报告!已将"<<y<<"条"<<x<<"复读完毕! 2333"<<endl;
    Sleep(1500);
    qp();
}

void color(){
	char colorr;
	cout<<"输入一个字符(颜色代码):"<<endl<<"0黑色,1蓝色,2绿色,3湖蓝色,4红色,5紫色,6黄色,7白色,8灰色,9淡蓝色,A淡绿色,B浅绿色,C淡红色,D淡紫色,E淡黄色,F白色,G退出"<<endl;
	while(1){
		cin>>colorr;
		switch(colorr){
			case '0':
				system("color 0F");
				break;
			case '1':
				system("color 1F");
				break;
			case '2':
				system("color 2F");
				break;
			case '3':
				system("color 3F");
				break;
			case '4':
				system("color 4F");
				break;
			case '5':
				system("color 5F");
				break;
			case '6':
				system("color 6F");
				break;
			case '7':
				system("color 7F");
				break;
			case '8':
				system("color 8F");
				break;
			case '9':
				system("color 9F");
				break;
			case 'A':
				system("color AF");
				break;
			case 'B':
				system("color BF");
				break;
			case 'C':
				system("color CF");
				break;
			case 'D':
				system("color DF");
				break;
			case 'E':
				system("color E5");
				break;
			case 'F':
				system("color F0");
				return;
			case 'G':
				break;
			default:
				cout<<"电脑:这颜色是神马?我不道啊"<<endl;
		}
	}
}

void music(){
	int n,ms,yin,choose;
	cout<<"输入1试听,输入2导入乐谱:"<<endl;
	cin>>choose;
	if(choose==1){
		cout<<"试听模式:输入赫兹数和音符长度(ms),系统会自动播放,输入0退出"<<endl;
		while(1){
			cin>>yin;
			if(yin==0){
				break;
			}else{
				cin>>ms;
				Beep(yin,ms);
			}
		}
	}else{
		cout<<"导入乐谱模式:在此代码同目录内新建一个名为yuepu.txt的文本文档,系统会识别,播放"<<endl;
		cout<<"格式:"<<endl;
		cout<<"3(音符个数)"<<endl;
		cout<<"音符1hz数 音符1长度(ms)"<<endl;
		cout<<"音符2hz数 音符2长度(ms)"<<endl;
		cout<<"音符3hz数 音符3长度(ms)"<<endl;
		cout<<"如果想暂停,就输入:"<<endl;
		cout<<"0 暂停时间(ms)"<<endl<<endl;
		cout<<"请在准备好之后输入OK"<<endl;
		string ok;
		cin>>ok;
		if(ok=="OK"){
			Sleep(500);
			ifstream in("yuepu.txt");
			in>>n;
			for(int i=1;i<=n;i++){
				in>>yin>>ms;
				if(yin==0){
					Sleep(ms);
				}else{
					Beep(yin,ms);
				}
			}
			in.close();
			cin.get();
			cout<<"播放成功!"<<endl;
			Sleep(1000);
			qp();
		}else{
			cout<<"这是什么输入?我不到啊"<<endl;
		}
	}
}

void gengxin(){
    cout<<"V2.0"<<endl<<endl;
    cout<<"修复了运算时输错导致崩溃的BUG"<<endl;
    cout<<"改了改码风,把多处 if - else 改成了switch,更美观"<<endl;
    cout<<"把ASCII部分优化,从40行缩到7行23333333"<<endl;
    cout<<"把math部分优化,减少了十几二十行2333"<<endl;
    cout<<"哦对了,输入s会发生什么呢?2333"<<endl;
    cout<<"把talk函数的cin改成了getline,顺便把和cstdio的同步去掉了2333"<<endl<<endl;
    cout<<"V2.1"<<endl<<endl;
    cout<<"把ASCII函数改得更加高级了233(划掉"<<endl<<endl;
    cout<<"V3.0"<<endl<<endl;
    cout<<"把sort函数改得更加高级了233"<<endl;
    cout<<"V1.0的时候sort函数谁写的啊,这么烂(划掉"<<endl<<endl;
    cout<<"V3.1"<<endl<<endl;
    cout<<"搞了个改颜色,酷B了(划掉"<<endl;
    cout<<"加了一键清屏,啊,爽多了~~~"<<endl;
    cout<<"改了一堆BUG"<<endl<<endl;
    cout<<"V4.0"<<endl<<endl;
    cout<<"搞了个音乐,酷B了(划掉"<<endl;
    cout<<"现在还不太好听,以后(再过亿天)肯定会优化"<<endl;
    cout<<"修改了一堆BUG"<<endl<<endl;
	cout<<"V5.0"<<endl<<endl;
	cout<<"V4.0的坑终于填上了!"<<endl;
	cout<<"还弄了导入乐谱,酷B了(划掉"<<endl;
	cout<<"稍微改了改ASCII部分"<<endl;
	cout<<"听了机房大佬的建议,改了改math部分"<<endl;
	cout<<"又修了几个bug,代码长度达到14kb"<<endl;
}
int main(){
    ios::sync_with_stdio(false);
    cout<<"欢迎来到多功能 V5.0!"<<endl;
    while(true){
        cout << "b:    退     出    " << endl;
        cout << "0:    A S C I I    " << endl;
        cout << "1:    运     算    " << endl;
        cout << "2:    排     序    " << endl;
        cout << "3:    时     间    " << endl;
        cout << "4:    盒     子    " << endl;
        cout << "5:    笑     话    " << endl;
        cout << "6:    复     读    " << endl;
        cout << "7:    颜     色    " << endl;
        cout << "8:    一键 清屏    " << endl;
        cout << "9:    音     乐    " << endl;
        cout << "g:    更新 日志    " << endl;
        char n;
        cin >> n;
        if(n!='b') cout << "---------------------------------------手动分割线233-------------------------------------------"<<endl;
        switch(n){
            case 'b':
                cout<<"再见,期待下次见面~"<<endl;
                cout<<"作者:liuzhixing0922,还有 洛谷team 44227 里面的几个人"<<endl;
        		cout<<"谨防抄袭!!!"<<endl;
				cout<<"其实抄也没什么的(划掉"<<endl;
                return 0;
            case '0':
                ASCII();
                break;
            case '1':
                math();
                break;
            case '2':
                sortt();
                break;
            case '3':
                timme();
                break;
            case '4':
                hezi();
                break;
            case '5':
                xiaohua();
                break;
            case '6':
                repeat();
                break;
            case '7':
            	color();
            	break;
            case '8':
            	qp();
            	break;
            case '9':
            	music();
            	break;
            case 'g':
                gengxin();
                break;
            case 's':
                cout<<"恭喜你,找到了彩蛋!!!"<<endl;
                cout<<"把下面的连接粘贴到浏览器上打开233!"<<endl;
                cout<<"https://www.bilibili.com/video/BV1gV411i7vq";
                cout<<"要是什么时候代码到达100kb我就满足你们10个要求!!!(真的)";
            default:
                cout<<"风太大,没听清,请重试233333"<<endl;
        }
    }
}
原文