#include<iostream>
#include<stdio.h>
#include<string.h>
#include <Windows.h>
#include<time.h>
#include <graphics.h>
#include <conio.h>
#include<algorithm>
#include<stdlib.h>
#include <random>
#include <string>
#include <fstream>
#include <ddraw.h>
#include<iomanip>
#include <sapi.h> // 语音头文件
#include <sphelper.h> // 语音识别头文件
#include <thread> //多线程
//vs2019自定义控制台代码模板 by mao
//作者QQ1296193245
using namespace std;
#pragma warning(disable : 4996)
#pragma comment (lib,"ddraw.lib")
#pragma comment(lib,"sapi.lib")
#pragma comment(lib,"ole32.lib")
#pragma intrinsic(__rdtsc)
unsigned __int64 t1, t2, t3, t4;
double run_time; //微秒级算法时间计时器
LARGE_INTEGER time_start; //开始时间
LARGE_INTEGER time_over; //结束时间
double dqFreq; //计时器频率
LARGE_INTEGER f; //计时器频率
double tt;
long double totaltime;
inline void runstart()
{
QueryPerformanceFrequency(&f);
dqFreq = (double)f.QuadPart;
t1 = __rdtsc();
QueryPerformanceCounter(&time_start); //计时开始
}
inline void runend()
{
QueryPerformanceCounter(&time_over); //计时结束
run_time = 1000 * (time_over.QuadPart - time_start.QuadPart) / dqFreq;
t2 = __rdtsc();
t3 = t2 - t1;
}
void rundisplay()
{
cout << endl;
cout << "-------------------------------------------------------" << endl;
if (t3 < 10000)
{
cout << "CPU脉冲数:" << (t3) << endl;
}
else if (t3 < 100000000 && t3 >= 10000)
{
tt = t3;
cout << "CPU脉冲数:" << (tt) / 10000 << "万" << endl;
}
else if (t3 > 100000000000)
{
t4 = t3;
t4 = t3 / 10000000;
tt = t4;
cout << "CPU脉冲数:" << (tt) / 10 << "亿" << endl;
}
else
{
t4 = t3;
t4 = t3 / 10000;
tt = t4;
cout << "CPU脉冲数:" << (tt) / 10000 << "亿" << endl;
}
if (run_time > 10000)
{
cout << "算法运行时间:" << run_time / 1000 << "秒" << endl;
}
else if (run_time < 1)
{
cout << "算法运行时间:" << run_time * 1000 << "微秒" << endl;
}
else
{
cout << "算法运行时间:" << run_time << "毫秒" << endl;
}
totaltime = clock();
cout << "程序运行时间:" << totaltime / 1000 << "秒" << endl;
if (run_time > 0.4)
{
double frequency = t3 / run_time / 1000;
cout << "CPU频率:" << frequency << "MHZ" << endl;
}
cout << "CPU名字";
system("wmic cpu get Name");
cout << "CPU使用率";
system("wmic cpu get loadpercentage");
cout << "-------------------------------------------------------" << endl;
}
/* ****************************************
void FpsTime(const time_t* t0, time_t* t1, const time_t* t2)// 图形界面计算显示FPS和运行时间
{
if (!t0 || !t1 || !t2)
return;
static int FPS = 0;
static int fps = 0;
static wstring fpsTime;
if (*t2 - *t1 == 1)
{
FPS = ++fps;
}
fpsTime = L"FPS: ";
fpsTime += to_wstring(FPS);
fpsTime += L" 运行时间: ";
fpsTime += to_wstring(*t2 - *t0);
fpsTime += L"s";
settextcolor(LIGHTMAGENTA);
outtextxy(0, 0, fpsTime.c_str());
if (*t2 - *t1 == 1)
{
fps = 0;
*t1 = time(nullptr);
}
else
{
fps++;
}
}
*/ //*************************************
/*bool cmp(const int a, const int b)
{
return a > b;
}*/
/* ***************************************
bool ChangeDisSize(int cx, int cy) // 分辨率设置为 cx × cy,退出程序时自动还原
{
LPDIRECTDRAW DXW;
HRESULT ddrval;
ddrval = DirectDrawCreate(NULL, &DXW, NULL);
if (DD_OK != DD_OK) return FALSE; // 创建DirectDraw对象失败返回
ddrval = DXW->SetCooperativeLevel(NULL, DDSCL_NORMAL);
if (DD_OK != DD_OK) return FALSE; // 取得窗口模式失败返回
ddrval = DXW->SetDisplayMode(cx, cy, 16);
if (DD_OK != DD_OK) return FALSE; // 设置显示模式失败返回
}
*/
//**************************************************************//************************非主函数
int top = -1;//top变量时刻表示栈顶元素所在位置
void push(char* a, int elem)
{
a[++top] = elem;
}
void pop(char* a)
{
if (top == -1)
{
return;
}
top--;
}
char visit(char* a)
{
//调取栈顶元素,不等于弹栈,如果栈为空,为使程序不发生错误,返回空字符
if (top != -1)
{
return a[top];
}
else
{
return ' ';
}
}
//**************************************************************//************************
int main()
{
/* *************************************
constexpr int MIN = 1; //随机数
constexpr int MAX = 100;
constexpr int numm = 10;
random_device rd;
default_random_engine eng(rd());
uniform_int_distribution<int> distr(MIN, MAX);
for (int n = 0; n < numm; ++n)
{
cout << distr(eng) << ",";
}
*/ //***********************************
/* //************************************
SYSTEMTIME sys; //获取系统时间
GetLocalTime(&sys);
cout << sys.wYear << "/" << sys.wMonth << "/" << sys.wDay << " ";
cout<< setfill('0') << setw(2) << sys.wHour << ":" << setfill('0') << setw(2) << sys.wMinute << ":" << setfill('0') << setw(2) << sys.wSecond << endl;
*/ //***********************************
/* ************************************* //全屏图形窗口模板
int rw, rh;
rw = GetSystemMetrics(SM_CXSCREEN); // 屏幕宽度 像素
rh = GetSystemMetrics(SM_CYSCREEN); // 屏幕高度 像素
HWND hwnd = initgraph(rw, rh); // 初始化绘图窗口并获取窗口句柄
setbkcolor(GREEN);
cleardevice();
LONG l_WinStyle = GetWindowLong(hwnd, GWL_STYLE); // 获取窗口信息
// 设置窗口信息 最大化 取消标题栏及边框
SetWindowLong(hwnd, GWL_STYLE, (l_WinStyle | WS_POPUP | WS_MAXIMIZE) & ~WS_CAPTION & ~WS_THICKFRAME & ~WS_BORDER); // 修改窗口样式
SetWindowPos(hwnd, HWND_TOP, 0, 0, rw, rh, 0);
*/ //***********************************
/* ***********************************
initgraph(1600, 900);
setbkcolor(WHITE);
cleardevice();
*/ //***********************************
/* *********************************** //后台方式运行,Unicode字符集改成多字节字符集
HWND hwnd; if (hwnd = ::FindWindow("ConsoleWindowClass", NULL)) //找到控制台句柄
{
::ShowWindow(hwnd, SW_HIDE); //隐藏控制台窗口
}
//unicode字符集下:
const char* sss = "ConsoleWindowClass";
WCHAR wszName[200];
memset(wszName, 0, sizeof(wszName));
MultiByteToWideChar(CP_ACP, 0, sss, strlen(sss) + 1, wszName,
sizeof(wszName) / sizeof(wszName[0]));
HWND hwnd; if (hwnd = ::FindWindow(wszName, NULL)) //找到控制台句柄
{
::ShowWindow(hwnd, SW_HIDE); //隐藏控制台窗口
}
*/ //**********************************
//*************************************************************************
//*************************************************************************
runstart();
//*************************计时开始***************************************
int length, i;
char a[30];
char bracket[100];
printf("请输入括号序列:");
scanf("%s", bracket);
getchar();
length = (int)strlen(bracket);
for (i = 0; i < length; i++)
{
//如果是左括号,�