#include <bits/stdc++.h>
#include <windows.h>
#define NONE_ERR 0
#define OPR_NOT_TYPE 1
#define DEF_NOT_DEFINE 2
#define DEF_IS_DEFINED 3
#define LET_ERROR 4
#define TO_ERROR 5
#define PRINT_TYPE_ERROR 6
#define DEF_TYPE_ERROR 7
#define TYPE_NOT_INT 8
#define TYPE_NOT_STR 9
#define TYPE_NOT_DOUBLE 10
#define QUEUE_ERROR 11
#define STACK_ERROR 12
#define FILE_NOT_DEF 13
#define FILE_ERROR 14
#define WEB_ERROR 15
#define UNKNOW_ERROR 100000
#define ms 60000
const double pno[10][8] = {
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 32.70, 36.71, 41.20, 43.65, 49, 55, 61.74},
{0, 65.41, 73.42, 82.41, 87.31, 98, 110, 123.47},
{0, 130.81, 146.83, 164.81, 174.61, 196, 220.00, 246.94},
{0, 261.63, 293.66, 329.63, 349.23, 392, 440, 493.88},
{0, 523.25, 587.33, 659.26, 698.46, 783.99, 880, 987.77},
{0, 1046.5, 1174.66, 1318.51, 1396.91, 1567.98, 1760, 1975.53},
{0, 2093, 2349.32, 2637.02, 2793.83, 3135.96, 3520, 3951.07},
{0, 4186.01, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
};
const double pnos[10][8] = {
{0, 0, 0, 0, 0, 0, 29.14, 0},
{0, 34.65, 38.89, 0, 46.25, 51.91, 58.27, 0},
{0, 69.3, 77.78, 0, 92.5, 103.83, 116.54, 0},
{0, 138.59, 155.56, 0, 185, 207.65, 233.08, 0},
{0, 277.18, 311.13, 0, 369.99, 415.3, 466.16, 0},
{0, 554.37, 622.25, 0, 739.99, 830.61, 932.33, 0},
{0, 1108.73, 1244.51, 0, 1479.98, 1661.22, 1864.66, 0},
{0, 2217.46, 2489.02, 0, 2959.96, 3322.44, 3729.31, 0},
{0, 4186.01, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
};
using namespace std;
typedef const int IS_CNLE_ERROR;
vector<int> lvec(100001);
void music_happy_song(){
Beep(pno[4][3],ms/120*1);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][4],ms/120*1);
Beep(pno[4][5],ms/120*1);
Beep(pno[4][5],ms/120*1);
Beep(pno[4][4],ms/120*1);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][2],ms/120*1);
Beep(pno[4][1],ms/120*1);
Beep(pno[4][1],ms/120*1);
Beep(pno[4][2],ms/120*1);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][3],600/12*15);
Beep(pno[4][2],ms/120/2);
Beep(pno[4][2],ms/120*2);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][4],ms/120*1);
Beep(pno[4][5],ms/120*1);
Beep(pno[4][5],ms/120*1);
Beep(pno[4][4],ms/120*1);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][2],ms/120*1);
Beep(pno[4][1],ms/120*1);
Beep(pno[4][1],ms/120*1);
Beep(pno[4][2],ms/120*1);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][2],6000/120*15);
Beep(pno[4][1],ms/120/2);
Beep(pno[4][1],ms/120*2);
Beep(pno[4][2],ms/120*2);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][1],ms/120*1);
Beep(pno[4][2],ms/120*1);
Beep(pno[4][3],ms/120/2);
Beep(pno[4][4],ms/120/2);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][1],ms/120*1);
Beep(pno[4][2],ms/120*1);
Beep(pno[4][3],ms/120/2);
Beep(pno[4][4],ms/120/2);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][2],ms/120*1);
Beep(pno[4][1],ms/120*1);
Beep(pno[4][2],ms/120*1);
Beep(pno[3][5],ms/120*1);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][4],ms/120*1);
Beep(pno[4][5],ms/120*1);
Beep(pno[4][5],ms/120*1);
Beep(pno[4][4],ms/120*1);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][2],ms/120*1);
Beep(pno[4][1],ms/120*1);
Beep(pno[4][1],ms/120*1);
Beep(pno[4][2],ms/120*1);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][2],6000/120*15);
Beep(pno[4][1],ms/120/2);
Beep(pno[4][1],ms/120*2);
Beep(pno[4][2],ms/120*2);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][1],ms/120*1);
Beep(pno[4][2],ms/120*1);
Beep(pno[4][3],ms/120/2);
Beep(pno[4][4],ms/120/2);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][1],ms/120*1);
Beep(pno[4][2],ms/120*1);
Beep(pno[4][3],ms/120/2);
Beep(pno[4][4],ms/120/2);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][2],ms/120*1);
Beep(pno[4][1],ms/120*1);
Beep(pno[4][2],ms/120*1);
Beep(pno[3][5],ms/120*1);
Beep(pno[4][3],ms/120*2);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][4],ms/120*1);
Beep(pno[4][5],ms/120*1);
Beep(pno[4][5],ms/120*1);
Beep(pno[4][4],ms/120*1);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][2],ms/120*1);
Beep(pno[4][1],ms/120*2);
Beep(pno[4][2],ms/120*1);
Beep(pno[4][3],ms/120*1);
Beep(pno[4][2],6000/120*15);
Beep(pno[4][1],ms/120/2);
Beep(pno[4][1],ms/120*1);
}
void music_guyongzhe(){
double f4 = 12000 / 13, f2 = 24000 / 13, f8 = 6000 / 13, f16 = 3000 / 13, f8_ = 9000 / 13, f1 = 48000 / 13;
for (int i = 1; i <= 8; i++) {
Beep(pno[4][2], f8);
Beep(pno[3][7], f8);
Beep(pno[4][1], f8);
Beep(pno[3][6], f8);
}
Beep(pno[4][3], f2);
Beep(0, f4);
Beep(0, f16);
Beep(pno[4][1], f16);
Beep(pno[4][2], f16);
Beep(pno[4][1], f16);
Beep(pno[4][3], f2);
Beep(0, f8_);
Beep(pno[4][1], f16);
Beep(pno[4][2], f16);
Beep(pno[4][1], f16);
Beep(pno[4][2], f16);
Beep(pno[4][3], f16);
Beep(pno[3][6], f8_);
Beep(pno[4][1], f16);
Beep(pno[3][6], f8_);
Beep(pno[4][1], f16);
Beep(pno[3][6], f8_);
Beep(pno[4][1], f16);
Beep(pno[4][2], f8);
Beep(pno[4][1], f8);
Beep(pno[3][7], f1);
Beep(pno[4][3], f2);
Beep(0, f8_);
Beep(pno[4][1], f16);
Beep(pno[4][2], f16);
Beep(pno[4][1], f16);
Beep(pno[4][2], f16);
Beep(pno[4][3], f16);
Beep(pno[4][3], f2);
Beep(0, f8_);
Beep(pno[4][1], f16);
Beep(pno[4][2], f16);
Beep(pno[4][1], f16);
Beep(pno[4][2], f16);
Beep(pno[4][3], f16);
Beep(pno[3][6], f8_);
Beep(pno[4][1], f16);
Beep(pno[3][6], f8_);
Beep(pno[4][1], f16);
Beep(pno[3][6], f8_);
Beep(pno[4][1], f16);
Beep(pno[4][2], f8);
Beep(pno[4][1], f8);
Beep(pno[3][7], f1);
Beep(pno[3][6], f16);
Beep(pno[4][1], f16);
Beep(pno[4][6], f8_);
Beep(pno[4][6], f16);
Beep(pno[4][6], f16);
Beep(pno[4][5], f16);
Beep(pno[4][6], f8);
Beep(pno[4][6], f16);
Beep(pno[4][5], f16);
Beep(pno[4][6], f16);
Beep(pno[4][5], f16);
Beep(pno[4][6], f16);
Beep(pno[4][5], f16);
Beep(pno[4][3], f16);
Beep(pno[4][3], f2+f8);
Beep(0,f4+f8);
Beep(pno[3][6], f16);
Beep(pno[4][1], f16);
Beep(pno[4][6], f8_);
Beep(pno[4][6], f16);
Beep(pno[4][6], f16);
Beep(pno[4][5], f16);
Beep(pno[4][6], f16);
Beep(pno[4][5], f16);
Beep(pno[4][7], f8_);
Beep(pno[4][7], f16);
Beep(pno[4][7], f8);
Beep(pno[4][6], f16);
Beep(pno[4][7], f8);
Beep(pno[4][6], f8);
Beep(pno[4][3], f16);
Beep(pno[4][3], f2);
Beep(0, f16);
Beep(pno[4][3], f16);
Beep(pno[4][5], f16);
Beep(pno[4][3], f16);
Beep(pno[4][2], f8_);
Beep(pno[4][3], f16);
Beep(pno[4][2], f8_);
Beep(pno[4][3], f16);
Beep(pno[4][2], f8_);
Beep(pno[4][3], f16);
Beep(pno[4][5], f16);
Beep(pno[4][3], f16);
Beep(pno[4][5], f16);
Beep(pno[4][3], f16);
Beep(pno[4][2], f8_);
Beep(pno[4][3], f16);
Beep(pno[4][2], f8_);
Beep(pno[4][3], f16);
Beep(pno[4][2], f4);
Beep(0, f8);
Beep(pno[4][1], f16);
Beep(pno[4][2], f16);
Beep(pno[4][3], f8);
Beep(pno[3][6], f8);
Beep(pno[4][1], f8);
Beep(pno[4][3], f8);
Beep(pno[4][2], f8_);
Beep(pno[4][3], f16);
Beep(pno[4][2], f8);
Beep(pno[4][1], f16);
Beep(pno[4][1], f16);
Beep(pno[3][6], f2);
Beep(0, f4);
Beep(pno[3][6], f8);
Beep(pno[3][7], f8);
Beep(pno[4][1], f16);
Beep(pno[4][2], f16);
Beep(pno[3][7], f16);
Beep(pno[4][1], f16);
Beep(pno[4][1], f8);
Beep(pno[4][1], f16);
Beep(pno[3][7], f16);
Beep(pno[4][1], f16);
Beep(pno[4][2], f16);
Beep(pno[3][7], f16);
Beep(pno[4][1], f16);
Beep(pno[4][1], f8);
Beep(pno[4][1], f16);
Beep(pno[4][2], f16);
Beep(pno[4][3], f16);
Beep(pno[4][2], f16);
Beep(pno[4][3], f16);
Beep(pno[4][2], f16);
Beep(pno[4][3], f8);
Beep(pno[4][3], f16);
Beep(pno[4][2], f16);
Beep(pno[4][3], f8);
Beep(pno[4][5], f8);
Beep(pno[4][3], f8);
Beep(pno[3][6], f16);
Beep(pno[3][7], f16);
Beep(pno[4][1], f16);
Beep(pno[4][2], f16);
Beep(pno[3][7], f16);
Beep(pno[4][1], f16);
Beep(pno[4][1], f8);
Beep(pno[4][1], f16);
Beep(pno[3][7], f16);
Beep(pno[4][1], f16);
Beep(pno[4][2], f16);
Beep(pno[3][7], f16);
Beep(pno[4][1], f16);
Beep(pno[4][1], f8);
Beep(pno[4][1], f16);
Beep(pno[4][2], f16);
Beep(pno[4][3], f16);
Beep(pno[4][2], f16);
Beep(pno[4][3], f16);
Beep(pno[4][2], f16);
Beep(pno[4][3], f8);
Beep(pno[4][3], f16);
Beep(pno[4][2], f16);
Beep(pno[4][3], f8);
Beep(pno[4][5], f8);
Beep(pno[4][3], f8);
Beep(pno[4][5], f8);
Beep(pno[4][3], f8_);
Beep(pno[4][5], f16);
Beep(pno[4][3], f8_);
Beep(pno[4][5], f16);
Beep(pno[4][3], f16);
Beep(pno[4][5], f16);
Beep(pno[4][6], f16);
Beep(pno[4][3], f16);
Beep(pno[4][5], f8);
Beep(pno[4][5], f8);
Beep(pno[4][3], f8_);
Beep(pno[4][5], f16);
Beep(pno[4][3], f8_);
Beep(pno[4][5], f16);
Beep(pno[4][3], f16);
Beep(pno[4][5], f16);
Beep(pno[4][6], f16);
Beep(pno[4][3], f16);
Beep(pno[4][5], f8);
Beep(pno[4][5], f16);
Beep(pno[4][5], f16);
Beep(pno[4][3], f16);
Beep(pno[4][2], f16);
Beep(pno[4][2], f8);
Beep(pno[4][2], f8);
Beep(pno[4][1], f16);
Beep(pno[4][3], f16);
Beep(pno[4][3], f16);
Beep(pno[4][2], f16);
Beep(pno[4][2], f8);
Beep(pno[4][2], f8);
Beep(pno[4][1], f16);
Beep(pno[4][1], f16);
Beep(pno[3][6], f2);
Beep(0, f4);
Beep(pno[4][5], f8);
Beep(pno[4][5], f8);
Beep(pno[4][3], f16);
Beep(pno[4][2], f16);
Beep(pno[4][2], f8);
Beep(pno[4][2], f8);
Beep(pno[4][1], f16);
Beep(pno[4][3], f16);
Beep(pno[4][3], f16);
Beep(pno[4][2], f16);
Beep(pno[4][2], f8);
Beep(pno[4][2], f8);
Beep(pno[4][1], f16);
Beep(pno[4][1], f16);
Beep(pno[3][6], f8);
Beep(pno[3][7], f8);
Beep(pno[4][1], f8);
Beep(pno[3][6], f8);
for(int i=1;i<=6;i++) {
Beep(pno[4][2], f8);
Beep(pno[3][7], f8);
Beep(pno[4][1], f8);
Beep(pno[3][6], f8);
}
Beep(pno[4][2], f8);
Beep(pno[3][7], f8);
Beep(pno[4][1], f8);
Beep(pno[3][6], f8+f1);
}
double determinant(const vector<vector<double>>& matrix, int n) {
double det = 0;
if (n == 1) {
return matrix[0][0];
}
if (n == 2) {
return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
}
vector<vector<double>> subMatrix(n - 1, vector<double>(n - 1));
for (int x = 0; x < n; x++) {
int subi = 0;
for (int i = 1; i < n; i++) {
int subj = 0;
for (int j = 0; j < n; j++) {
if (j == x) continue;
subMatrix[subi][subj] = matrix[i][j];
subj++;
}
subi++;
}
double subDet = determinant(subMatrix, n - 1);
det += (x % 2 == 0 ? 1 : -1) * matrix[0][x] * subDet;
}
return det;
}
void end_cnle(IS_CNLE_ERROR ERR) {
std::cout << "--------------------------------\n";
std::cout << "This program is return.";
switch (ERR) {
case NONE_ERR:
std::cout << "This program is return.No error.";
break;
case OPR_NOT_TYPE:
std::cout << "[error]The opr is not the type.";
break;
case DEF_NOT_DEFINE:
std::cout << "[error]The def is not define!";
break;
case DEF_IS_DEFINED:
std::cout << "[error]The def is defined!";
break;
case LET_ERROR:
std::cout << "[error]The let was error.";
break;
case TO_ERROR:
std::cout << "[error]The to was error.";
break;
case PRINT_TYPE_ERROR:
std::cout << "[error]The print type was not a type.";
break;
case DEF_TYPE_ERROR:
std::cout << "[error]The def type was not a type.";
break;
case TYPE_NOT_INT:
std::cout << "[error]The def type was not int.";
break;
case TYPE_NOT_STR:
std::cout << "[error]The def type was not string.";
break;
case TYPE_NOT_DOUBLE:
std::cout << "[error]The def type was not double.";
break;
case STACK_ERROR:
std::cout << "[error]The stack was error.";
break;
case QUEUE_ERROR:
std::cout << "[error]The queue was error.";
break;
case FILE_NOT_DEF:
std::cout << "[error]The file is not define.";
break;
case FILE_ERROR:
std::cout << "[error]The file is error.";
break;
case WEB_ERROR:
std::cout << "[error]The website is error or none void.";
break;
default:
std::cout << "[error]Unkown error";
break;
}
std::cout << "\nPut the keyboard to continue. . .";
}
std::string operator*(std::string __a, int __b) {
if (!__b) {
return "";
}
std::string ___ans = "";
for (int ___it = 1; ___it <= __b; ___it++) {
___ans += __a;
}
return ___ans;
}
void operator*=(std::string &__a, int __b) {
std::string ___ans = "";
for (int ___it = 1; ___it <= __b; ___it++) {
___ans += __a;
}
__a = ___ans;
}
std::string operator/(std::string __a, int __b) {
std::string ___ans = "";
int ___len = __a.size() / __b;
for (int ___it = 0; ___it < ___len; ___it++) {
___ans += __a[___it];
}
return ___ans;
}
void operator/=(std::string &__a, int __b) {
std::string ___ans = "";
int ___len = __a.size() / __b;
for (int ___it = 0; ___it < ___len; ___it++) {
___ans += __a[___it];
}
__a = ___ans;
}
vector<double> operator+(vector<double> __a, vector<double> __b){
vector<double> __ans(__a.size(),0);
for(int i=1;i<int(__a.size());i++){
__ans.push_back(__a[i]+__b[i]);
}
return __ans;
}
vector<double> operator-(vector<double> __a, vector<double> __b){
vector<double> __ans(__a.size(),0);
for(int i=1;i<int(__a.size());i++){
__ans.push_back(__a[i]-__b[i]);
}
return __ans;
}
vector<double> operator*(vector<double> __a, vector<double> __b){
vector<double> __ans(__a.size(),0);
for(int i=1;i<int(__a.size());i++){
__ans.push_back(__a[i]*__b[i]);
}
return __ans;
}
vector<double> operator/(vector<double> __a, vector<double> __b){
vector<double> __ans(__a.size(),0);
for(int i=1;i<int(__a.size());i++){
__ans.push_back(__a[i]/__b[i]);
}
return __ans;
}
void SetConsoleColor(WORD attributes) {
HANDLE hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsoleOutput, attributes);
}
#define set_out SetConsoleColor(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED | FOREGROUND_GREEN)
#define set_in SetConsoleColor(FOREGROUND_RED | FOREGROUND_BLUE);
struct nodef {
int d;
double lf;
string s;
char ch;
bool b;
string type;
string type_sq;
void Nodef(int _d, double _lf, string _s, char _c, bool _b, string _type, string _sqtype) {
d = _d;
lf = _lf;
s = _s;
ch = _c;
b = _b;
type = _type;
type_sq = _sqtype;
}
};
map<string, nodef> def;
map<string, queue<int>> qi_def;
map<string, stack<int>> si_def;
map<string, queue<string>> qs_def;
map<string, stack<string>> ss_def;
map<string, queue<double>> qd_def;
map<string, stack<double>> sd_def;
int retnum;
string fopr;//the first operator
const string out = "out<<< ", in = "in>>> ";
inline int Fib(int __x) {
if (__x == 1) {
return 1;
} else if (__x == 2) {
return 2;
}
int ___a_number__ = 1, ___b_number__ = 2, ___c_number__;
for (int i = 3; i <= __x; i++) {
___c_number__ = ___a_number__ + ___b_number__;
___a_number__ = ___b_number__;
___b_number__ = ___c_number__;
}
return ___b_number__;
}
inline is_prime(int in) {
if (in == 2) {
return true;
}
if (in == 0 || in == 1 || in % 2 == 0) {
return false;
}
for (int i = 3; i * i <= in; i += 2) {
if (!(in % i)) {
return false;
}
}
return true;
}
std::string btstr(int in__bo) {
if (in__bo == -1) {
return "error";
}
return (in__bo) ? "True" : "False";
}
double double_value(std::string name) {
return def[name].lf;
}
int int_value(std::string name) {
return def[name].d;
}
std::string str_value(std::string name) {
return def[name].s;
}
char ch_value(std::string name) {
return def[name].ch;
}
bool b_value(std::string name) {
return def[name].b;
}
std::string deftype(std::string name) {
return def[name].type;
}
bool isopr(std::string __in) {
return (__in == fopr);
}
bool strtbo(std::string in_str) {
if (in_str == "true") {
return true;
} else {
return false;
}
}
inline void out_def(std::string name) {
if (deftype(name) == "int") {
cout << int_value(name) << " ";
} else if (deftype(name) == "string") {
cout << str_value(name) << " ";
} else if (deftype(name) == "double") {
cout << double_value(name) << " ";
} else if (deftype(name) == "char") {
cout << ch_value(name) << " ";
} else if (deftype(name) == "bool") {
cout << btstr(b_value(name)) << " ";
}
}
int pd_is(int a, int b, std::string opr_is) {
if (opr_is == "bigger_than" || opr_is == ">") {
return (a > b);
}
if (opr_is == "smaller_than" || opr_is == "<") {
return (a < b);
}
if (opr_is == "equal_to" || opr_is == "==") {
return (a == b);
}
if (opr_is == "bigger_equal_to" || opr_is == ">=") {
return (a >= b);
}
if (opr_is == "smaller_equal_to" || opr_is == "<=") {
return (a <= b);
}
if (opr_is == "not_equal_to" || opr_is == "!=") {
return (a != b);
}
if (opr_is == "square_of" || opr_is == "#=") {
return (b * b == a);
}
retnum = PRINT_TYPE_ERROR;
return -1;
}
int pd_is(double a, double b, string opr_is) {
if (opr_is == "bigger_than" || opr_is == ">") {
return (a > b);
}
if (opr_is == "smaller_than" || opr_is == "<") {
return (a < b);
}
if (opr_is == "equal_to" || opr_is == "==") {
return (a == b);
}
if (opr_is == "bigger_equal_to" || opr_is == ">=") {
return (a >= b);
}
if (opr_is == "smaller_equal_to" || opr_is == "<=") {
return (a <= b);
}
if (opr_is == "not_equal_to" || opr_is == "!=") {
return (a != b);
}
if (opr_is == "square_of" || opr_is == "#=") {
return (b * b == a);
}
retnum = PRINT_TYPE_ERROR;
return -1;
}
int pd_is(string a, string b, string opr_is) {
if (opr_is == "bigger_than" || opr_is == ">") {
return (a > b);
}
if (opr_is == "smaller_than" || opr_is == "<") {
return (a < b);
}
if (opr_is == "equal_to" || opr_is == "==") {
return (a == b);
}
if (opr_is == "bigger_equal_to" || opr_is == ">=") {
return (a >= b);
}
if (opr_is == "smaller_equal_to" || opr_is == "<=") {
return (a <= b);
}
if (opr_is == "not_equal_to" || opr_is == "!=") {
return (a != b);
}
retnum = PRINT_TYPE_ERROR;
return -1;
}
int let(string name_a, string name_b, string let_to_opr) {
string tp_a = deftype(name_a), tp_b = deftype(name_b), type;
if (tp_a != tp_b) {
return LET_ERROR;
}
type = tp_a;
if (type == "int") {
if (let_to_opr == "is" || let_to_opr == "=") {
def[name_a].d = def[name_b].d;
} else if (let_to_opr == "plus" || let_to_opr == "+=") {
def[name_a].d += def[name_b].d;
} else if (let_to_opr == "minus" || let_to_opr == "-=") {
def[name_a].d -= def[name_b].d;
} else if (let_to_opr == "times" || let_to_opr == "*=") {
def[name_a].d *= def[name_b].d;
} else if (let_to_opr == "divide" || let_to_opr == "/=") {
def[name_a].d /= def[name_b].d;
} else if (let_to_opr == "mod" || let_to_opr == "%=") {
def[name_a].d %= def[name_b].d;
} else if (let_to_opr == "and" || let_to_opr == "&&=") {
def[name_a].d &= def[name_b].d;
} else if (let_to_opr == "or" || let_to_opr == "||=") {
def[name_a].d |= def[name_b].d;
} else if (let_to_opr == "xor" || let_to_opr == "^^=") {
def[name_a].d ^= def[name_b].d;
} else if (let_to_opr == "nor" || let_to_opr == "!|=") {
def[name_a].d = ~(def[name_a].d | def[name_b].d);
} else if (let_to_opr == "lshift" || let_to_opr == "<<=") {
def[name_a].d <<= def[name_b].d;
} else if (let_to_opr == "rshift" || let_to_opr == ">>=") {
def[name_a].d >>= def[name_b].d;
} else if (let_to_opr == "nxor" || let_to_opr == "!^=") {
def[name_a].d = ~(def[name_a].d ^ def[name_b].d);
} else if (let_to_opr == "nand" || let_to_opr == "!&=") {
def[name_a].d = ~(def[name_a].d ^ def[name_b].d);
} else if (let_to_opr == "pow" || let_to_opr == "^=") {
def[name_a].d = int(pow(def[name_a].d, def[name_b].d));
} else {
return LET_ERROR;
}
} else if (type == "string") {
if (let_to_opr == "is" || let_to_opr == "=") {
def[name_a].s = def[name_b].s;
} else if (let_to_opr == "plus" || let_to_opr == "+=") {
def[name_a].s += def[name_b].s;
} else {
return LET_ERROR;
}
} else if (type == "double") {
if (let_to_opr == "is" || let_to_opr == "=") {
def[name_a].lf = def[name_b].lf;
} else if (let_to_opr == "plus" || let_to_opr == "+=") {
def[name_a].lf += def[name_b].lf;
} else if (let_to_opr == "minus" || let_to_opr == "-=") {
def[name_a].lf -= def[name_b].lf;
} else if (let_to_opr == "times" || let_to_opr == "*=") {
def[name_a].lf *= def[name_b].lf;
} else if (let_to_opr == "divide" || let_to_opr == "/=") {
def[name_a].lf /= def[name_b].lf;
} else if (let_to_opr == "mod" || let_to_opr == "%=") {
def[name_a].d = fmod(def[name_a].lf, def[name_b].lf);
} else if (let_to_opr == "pow" || let_to_opr == "^=") {
def[name_a].d = pow(def[name_a].lf, def[name_b].lf);
} else {
return LET_ERROR;
}
} else if (type == "char") {
if (let_to_opr == "is" || let_to_opr == "=") {
def[name_a].ch = def[name_b].ch;
} else if (let_to_opr == "plus" || let_to_opr == "+=") {
def[name_a].ch += def[name_b].ch;
} else if (let_to_opr == "minus" || let_to_opr == "-=") {
def[name_a].ch -= def[name_b].ch;
} else {
return LET_ERROR;
}
} else if (type == "bool") {
if (let_to_opr == "and" || let_to_opr == "&&=") {
def[name_a].b &= def[name_b].b;
} else if (let_to_opr == "or" || let_to_opr == "||=") {
def[name_a].b |= def[name_b].b;
} else if (let_to_opr == "xor" || let_to_opr == "^^=") {
def[name_a].b ^= def[name_b].b;
} else if (let_to_opr == "nor" || let_to_opr == "!|=") {
def[name_a].b = ~(def[name_a].b | def[name_b].b);
} else if (let_to_opr == "nxor" || let_to_opr == "!^=") {
def[name_a].b = ~(def[name_a].b ^ def[name_b].b);
} else if (let_to_opr == "nand" || let_to_opr == "!&=") {
def[name_a].b = ~(def[name_a].b ^ def[name_b].b);
} else if (let_to_opr == "not" || let_to_opr == "~=") {
def[name_a].b = !def[name_b].b;
}
}
return 0;
}
int math(string type, string name_math) {
if (type == "fib") {
string name_to;
cin >> name_to;
if (!def.count(name_math) || (!def.count(name_to) && name_to != "print")) {
retnum = DEF_NOT_DEFINE;
return -1;
}
if (deftype(name_math) != "int") {
retnum = TYPE_NOT_INT;
return -1;
}
if (name_to == "print") {
set_out;
cout << out << Fib(int_value(name_math)) << endl;
set_in;
} else {
def[name_to].d = Fib(int_value(name_math));
}
return 0;
} else if (type == "is_prime") {
string name_pr, pr_to;
cin >> name_pr >> pr_to;
if (deftype(name_pr) != "int" || (pr_to != "print" && !def.count(pr_to)) || (pr_to != "print" && deftype(pr_to) != "bool")) {
retnum = UNKNOW_ERROR;
}
if (pr_to == "print") {
set_out;
cout << out << is_prime(int_value(name_pr)) << endl;
set_in;
} else {
def[pr_to].b = is_prime(int_value(name_pr));
}
} else if (type == "sin" || type == "cos" || type == "tan"
|| type == "sqrt" || type == "cbrt" || type == "log2"
|| type == "log10") {
string name_math, name_to;
cin >> name_math >> name_to;
if (!def.count(name_math) || (!def.count(name_to) && name_to != "print")) {
retnum = DEF_NOT_DEFINE;
return -1;
}
if (deftype(name_math) != "double") {
retnum = TYPE_NOT_DOUBLE;
return -1;
}
if (name_to == "print") {
set_out;
if (type == "sin") {
cout << out << sin(double_value(name_math)) << endl;
} else if (type == "cos") {
cout << out << cos(double_value(name_math)) << endl;
} else if (type == "tan") {
cout << out << tan(double_value(name_math)) << endl;
} else if (type == "sqrt") {
cout << out << sqrt(double_value(name_math)) << endl;
} else if (type == "cbrt") {
cout << out << cbrt(double_value(name_math)) << endl;
} else if (type == "log2") {
cout << out << log2(double_value(name_math)) << endl;
} else if (type == "log10") {
cout << out << log10(double_value(name_math)) << endl;
}
set_in;
} else {
if (type == "sin") {
def[name_to].lf = sin(double_value(name_math));
} else if (type == "cos") {
def[name_to].lf = cos(double_value(name_math));
} else if (type == "tan") {
def[name_to].lf = tan(double_value(name_math));
} else if (type == "sqrt") {
def[name_to].lf = sqrt(double_value(name_math));
} else if (type == "cbrt") {
def[name_to].lf = cbrt(double_value(name_math));
} else if (type == "log2") {
def[name_to].lf = log2(double_value(name_math));
} else if (type == "log10") {
def[name_to].lf = log10(double_value(name_math));
}
}
return 0;
} else {
retnum = OPR_NOT_TYPE;
return -1;
}
return 0;
}
int stackdo(std::string name, std::string stack_do) {
if (stack_do == "push") {
if (def[name].type_sq == "int") {
int push_v;
cin >> push_v;
si_def[name].push(push_v);
} else if (def[name].type_sq == "string") {
string push_v;
cin >> push_v;
ss_def[name].push(push_v);
} else if (def[name].type_sq == "double") {
double push_v;
cin >> push_v;
sd_def[name].push(push_v);
} else {
return STACK_ERROR;
}
} else if (stack_do == "pop") {
if (def[name].type_sq == "int") {
si_def[name].pop();
} else if (def[name].type_sq == "string") {
ss_def[name].pop();
} else if (def[name].type_sq == "double") {
sd_def[name].pop();
} else {
return STACK_ERROR;
}
} else if (stack_do == "top") {
if (def[name].type_sq == "int") {
set_out;
cout << out << si_def[name].top() << endl;
set_in;
} else if (def[name].type_sq == "string") {
set_out;
cout << out << ss_def[name].top() << endl;
set_in;
} else if (def[name].type_sq == "double") {
set_out;
cout << out << sd_def[name].top() << endl;
set_in;
} else {
return STACK_ERROR;
}
} else {
return STACK_ERROR;
}
return NONE_ERR;
}
int main() {
int result = MessageBox(NULL, "Do you want to OpenCnle?", "Open Cnle?", MB_YESNO | MB_ICONQUESTION);
if (result == IDNO) {
return 0;
}
SetConsoleColor(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_BLUE);
cout << "----------------------[Cnle10.0]---------------------\n";
cout << "Enter \"help\" to looking Cnle10.0 type. |\n";
cout << "-----------------------------------------------------\n";
for (int line = 1; 1; line++) {
SetConsoleColor(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_RED);
cout << "line(" << line << ") ";
set_in;
cin >> fopr; //input
if (isopr("def")) {
//define num
string def_name, def_type;
bool flag = false;
cin >> def_type;
while (1) {
cin >> def_name;
if (def.count(def_name)) {
retnum = DEF_IS_DEFINED;
flag = true;
break;
}
if (def_type == "int") {
int def_value;
cin >> def_value;
def[def_name] = {def_value, 0, "", '\0', false, "int", "none"};
} else if (def_type == "string") {
string def_value;
cin >> def_value;
def[def_name] = {0, 0, def_value, '\0', false, "string", "none"};
} else if (def_type == "double") {
double def_value;
cin >> def_value;
def[def_name] = {0, def_value, "", '\0', false, "double", "none"};
} else if (def_type == "char") {
char def_value;
cin >> def_value;
def[def_name] = {0, 0, "", def_value, false, "char", "none"};
} else if (def_type == "bool") {
string def_value;
cin >> def_value;
if (def_value == "true") {
def[def_name] = {0, 0, "", '\0', true, "bool", "none"};
} else if (def_value == "false") {
def[def_name] = {0, 0, "", '\0', false, "bool", "none"};
} else {
retnum = UNKNOW_ERROR;
flag = 1;
break;
}
} else if (def_type == "stack<int>") {
def[def_name] = {0, 0, "", '\0', false, "stack", "int"};
} else if (def_type == "stack<string>") {
def[def_name] = {0, 0, "", '\0', false, "stack", "string"};
} else if (def_type == "stack<double>") {
def[def_name] = {0, 0, "", '\0', false, "stack", "double"};
} else if (def_type == "queue<int>") {
def[def_name] = {0, 0, "", '\0', false, "queue", "int"};
} else if (def_type == "queue<string>") {
def[def_name] = {0, 0, "", '\0', false, "queue", "string"};
} else if (def_type == "queue<double>") {
def[def_name] = {0, 0, "", '\0', false, "queue", "double"};
} else {
retnum = DEF_TYPE_ERROR;
flag = true;
break;
}
string and_;
cin >> and_;
if (and_ == "none" || and_ == ";") {
break;
} else if (and_ != "and" && and_ != ",") {
retnum = UNKNOW_ERROR;
flag = true;
break;
}
}
if (flag) {
break;
}
} else if (isopr("print")) {
set_out;
cout << out << " ";
set_in;
bool flag = false;
while (1) {
string def_print_name;
cin >> def_print_name;
if (def_print_name[0] != '\"') {
if (!def.count(def_print_name)) {
retnum = DEF_NOT_DEFINE;
flag = true;
break;
} else {
set_out;
out_def(def_print_name);
set_in;
}
} else {
def_print_name.erase(0, 1);
set_out;
cout << def_print_name << " ";
set_in;
}
string __and;
cin >> __and;
if (__and == "none" || __and == ";") {
break;
} else if (__and != "and" && __and != ",") {
retnum = PRINT_TYPE_ERROR;
flag = true;
break;
}
}
cout << endl;
if (flag) {
break;
}
} else if (isopr("bcomp")) {
string is_typename, comp_to_bool;
cin >> comp_to_bool >> is_typename;
if (is_typename == "value") {
string is_type_a, is_type_b, is_type_opr;
cin >> is_type_a >> is_type_opr >> is_type_b;
if (!def.count(is_type_a) || !def.count(is_type_b) || !def.count(comp_to_bool)) {
retnum = DEF_NOT_DEFINE;
break;
}
std::string mp_iserror = "";
if (deftype(is_type_a) == "int" && deftype(is_type_a) == "int") {
mp_iserror = btstr(pd_is(int_value(is_type_a), int_value(is_type_b), is_type_opr));
if (mp_iserror == "error") {
break;
}
def[comp_to_bool].b = strtbo(mp_iserror);
} else if (deftype(is_type_a) == "string" && deftype(is_type_a) == "string") {
mp_iserror = btstr(pd_is(str_value(is_type_a), str_value(is_type_b), is_type_opr));
if (mp_iserror == "error") {
break;
}
def[comp_to_bool].b = strtbo(mp_iserror);
} else if (deftype(is_type_a) == "double" && deftype(is_type_a) == "double") {
mp_iserror = btstr(pd_is(double_value(is_type_a), double_value(is_type_b), is_type_opr));
if (mp_iserror == "error") {
break;
}
def[comp_to_bool].b = strtbo(mp_iserror);
} else {
retnum = UNKNOW_ERROR;
break;
}
} else if (is_typename == "number") {
string is_type, mp_iserror = "";
cin >> is_type;
if (is_type == "int") {
int number_a, number_b;
string number_opr;
cin >> number_a >> number_opr >> number_b;
mp_iserror = btstr(pd_is(number_a, number_b, number_opr));
if (mp_iserror == "error") {
break;
}
def[comp_to_bool].b = strtbo(mp_iserror);
} else if (is_type == "string") {
string number_a, number_b, number_opr;
cin >> number_a >> number_opr >> number_b;
mp_iserror = btstr(pd_is(number_a, number_b, number_opr));
if (mp_iserror == "error") {
break;
}
def[comp_to_bool].b = strtbo(mp_iserror);
} else if (is_type == "double") {
double number_a, number_b;
string number_opr;
cin >> number_a >> number_opr >> number_b;
mp_iserror = btstr(pd_is(number_a, number_b, number_opr));
if (mp_iserror == "error") {
break;
}
def[comp_to_bool].b = strtbo(mp_iserror);
} else {
retnum = PRINT_TYPE_ERROR;
break;
}
}
} else if (isopr("file_in")) {
std::string kfile_name;
queue<string> finname;
int g;
cin >> kfile_name >> g;
for (int i = 1; i <= g; i++) {
string k;
cin >> k;
finname.push(k);
}
std::ifstream file(kfile_name);
while (!finname.empty()) {
string inf_name = finname.front();
finname.pop();
if (!def.count(inf_name)) {
string in_type;
file >> in_type;
def[inf_name].type = in_type;
if (in_type == "int") {
file >> def[inf_name].d;
} else if (in_type == "double") {
file >> def[inf_name].lf;
} else if (in_type == "string") {
file >> def[inf_name].s;
} else if (in_type == "char") {
file >> def[inf_name].ch;
} else if (in_type == "bool") {
string bts;
file >> bts;
def[inf_name].b = strtbo(bts);
} else {
file.close();
retnum = FILE_ERROR;
break;
}
} else if (deftype(inf_name) == "int") {
file >> def[inf_name].d;
} else if (deftype(inf_name) == "double") {
file >> def[inf_name].lf;
} else if (deftype(inf_name) == "string") {
file >> def[inf_name].s;
} else if (deftype(inf_name) == "char") {
file >> def[inf_name].ch;
} else if (deftype(inf_name) == "bool") {
file >> def[inf_name].b;
}
}
file.close();
} else if (isopr("file_out")) {
std::string kfile_name;
cin >> kfile_name;
bool flag = false;
std::ofstream file(kfile_name);
while (1) {
string def_name;
cin >> def_name;
if (def_name[0] != '\"') {
if (deftype(def_name) == "int") {
file << int_value(def_name);
} else if (deftype(def_name) == "string") {
file << str_value(def_name);
} else if (deftype(def_name) == "double") {
file << double_value(def_name);
} else if (deftype(def_name) == "char") {
file << ch_value(def_name);
} else if (deftype(def_name) == "bool") {
file << btstr(b_value(def_name));
} else {
file.close();
retnum = FILE_ERROR;
break;
}
file << " ";
} else {
def_name.erase(0,1);
file << def_name;
}
string an;
cin >> an;
if (an == ";" || an == "none") {
break;
} else if (an != ";" && an != "none" && an != "and" && an != ",") {
flag = true;
break;
}
}
file.close();
if (flag) {
retnum = PRINT_TYPE_ERROR;
break;
}
} else if (isopr("no_line") || isopr("//")) {
string no__line;
cin >> no__line;
} else if (isopr("let")) {
string let_a, let_b, let_opr;
int __isret;
cin >> let_a >> let_opr >> let_b;
if (deftype(let_a) == "string" && deftype(let_b) == "int") {
if (let_opr == "times" || let_opr == "*=") {
def[let_a].s *= int_value(let_b);
} else if (let_opr == "divide" || let_opr == "/=") {
def[let_a].s /= int_value(let_b);
} else {
retnum = LET_ERROR;
break;
}
} else {
__isret = let(let_a, let_b, let_opr);
if (__isret) {
retnum = __isret;
break;
}
}
} else if (isopr("stack")) {
string name, stack_do;
cin >> name >> stack_do;
if (!def.count(name)) {
retnum = DEF_NOT_DEFINE;
break;
}
retnum = stackdo(name, stack_do);
if (retnum) {
break;
}
} else if (isopr("queue")) {
string name, queue_do;
cin >> name >> queue_do;
if (!qd_def.count(name) && !qi_def.count(name) && !qs_def.count(name)) {
retnum = DEF_NOT_DEFINE;
break;
}
if (queue_do == "push") {
if (def[name].type_sq == "int") {
int push_v;
cin >> push_v;
qi_def[name].push(push_v);
} else if (def[name].type_sq == "string") {
string push_v;
cin >> push_v;
qs_def[name].push(push_v);
} else if (def[name].type_sq == "double") {
double push_v;
cin >> push_v;
qd_def[name].push(push_v);
} else {
retnum = QUEUE_ERROR;
break;
}
} else if (queue_do == "pop") {
if (def[name].type_sq == "int") {
qi_def[name].pop();
} else if (def[name].type_sq == "string") {
qs_def[name].pop();
} else if (def[name].type_sq == "double") {
qd_def[name].pop();
} else {
retnum = QUEUE_ERROR;
break;
}
} else if (queue_do == "front") {
if (def[name].type_sq == "int") {
set_out;
cout << out << qi_def[name].front() << endl;
set_in;
} else if (def[name].type_sq == "string") {
set_out;
cout << out << qs_def[name].front() << endl;
set_in;
} else if (def[name].type_sq == "double") {
set_out;
cout << out << qd_def[name].front() << endl;
set_in;
} else {
retnum = QUEUE_ERROR;
break;
}
} else {
retnum = UNKNOW_ERROR;
break;
}
} else if (isopr("to")) {
string a_type, a_name, dt;
cin >> a_name >> a_type;
if (!def.count(a_name)) {
retnum = DEF_NOT_DEFINE;
break;
}
dt = deftype(a_name);
if (a_type == deftype(a_name)) continue;
if (dt == "string") {
if (a_type == "int") {
int those_num = 0;
bool is_n = 1, is_err = false;
string thstr = str_value(a_name);
for (int i = 0; i < int(thstr.length()); i++) {
if (thstr[i] == '-' && i == 0) {
is_n = 0;
} else if (thstr[i] == '-') {
is_err = true;
retnum = TO_ERROR;
break;
} else {
those_num = those_num * 10 + thstr[i] - 48;
}
}
if (is_err) {
break;
}
def[a_name].d = (is_n) ? those_num : (-those_num);
def[a_name].s = "";
def[a_name].type = "int";
} else if (a_type == "double") {
double it = 0, those_num = 0, down = 0;
bool is_n = 1, flag = 0, kflag = false;
string thstr = str_value(a_name);
for (int i = 0; i < int(thstr.length()); i++) {
if (thstr[i] == '-' && i == 0) {
is_n = 0;
} else if (thstr[i] == '-') {
kflag = true;
retnum = TO_ERROR;
break;
} else if (thstr[i] == '.') {
if (i == 0 || i == int(thstr.length()) - 1) {
retnum = TO_ERROR;
kflag = true;
break;
} else {
flag = true;
}
} else if (thstr[i] >= '0' && thstr[i] <= '9') {
if (flag) {
down = down * 10.0 + thstr[i] - 48.0;
it++;
} else {
those_num = those_num * 10.0 + thstr[i] - 48.0;
}
} else {
retnum = TO_ERROR;
kflag = true;
break;
}
}
those_num += down / pow(10, it);
def[a_name].lf = (is_n) ? those_num : (-those_num);
if (kflag) {
break;
}
} else {
retnum = TO_ERROR;
break;
}
} else if (dt == "double") {
if (a_type == "int") {
def[a_name].d = floor(int_value(a_name));
def[a_name].lf = 0;
def[a_name].type = "int";
} else if (a_type == "string") {
retnum = TO_ERROR;
break;
}
} else if (dt == "int") {
if (a_type == "double") {
def[a_name].lf = double(int_value(a_name));
def[a_name].d = 0;
def[a_name].type = "double";
} else if (a_type == "string") {
string itstr = "";
int thisint = int_value(a_name);
if (thisint < 0) {
itstr = "-";
} else if (thisint == 0) {
itstr = "0";
} else {
while (thisint) {
itstr += char(thisint % 10 + '0');
thisint /= 10;
}
}
def[a_name].s = itstr;
def[a_name].type = "string";
def[a_name].d = 0;
} else if (a_type == "bool") {
def[a_name].b = (def[a_name].d != 0);
def[a_name].type = "bool";
def[a_name].d = 0;
} else if (a_type == "char") {
def[a_name].ch = def[a_name].d;
def[a_name].type = "char";
def[a_name].d = 0;
} else {
retnum = TO_ERROR;
break;
}
} else if (dt == "char") {
if (a_type == "int") {
def[a_name].d = int(def[a_name].ch);
def[a_name].type = "int";
def[a_name].ch = '\0';
} else {
retnum = TO_ERROR;
break;
}
} else if (dt == "bool") {
if (a_type == "int") {
def[a_name].d = def[a_name].b;
def[a_name].type = "int";
def[a_name].b = false;
} else if (a_type == "string") {
def[a_name].s = int(b_value(a_name)) ? "true" : "false";
def[a_name].type = "string";
def[a_name].b = false;
} else {
retnum = TO_ERROR;
break;
}
} else {
retnum = TO_ERROR;
break;
}
} else if (isopr("type")) {
string name;
cin >> name;
set_out;
cout << out << deftype(name) << endl;
set_in;
} else if (isopr("math")) {
string type, name_m;
cin >> type >> name_m;
int r = math(type, name_m);
if (r == -1) break;
} else if (isopr("if")) {
string if_name, ifn_a, ifn_b, ifn_opr;
cin >> if_name >> ifn_a >> ifn_opr >> ifn_b;
if (!def.count(if_name)) {
retnum = DEF_NOT_DEFINE;
break;
}
bool if_b = false;
if (deftype(if_name) == "int") {
if_b = bool(int_value(if_name));
} else if (deftype(if_name) == "bool") {
if_b = b_value(if_name);
} else if (deftype(if_name) == "string") {
if_b = (str_value(if_name) != "");
} else {
retnum = UNKNOW_ERROR;
break;
}
if (!if_b) {
continue;
}
if (ifn_opr == "fib") {
if (!def.count(ifn_b) || !def.count(ifn_a)) {
retnum = DEF_NOT_DEFINE;
break;
}
if (deftype(ifn_a) != "int") {
retnum = TYPE_NOT_INT;
break;
}
def[ifn_a].d = Fib(int_value(ifn_b));
} else if (ifn_opr == "is_prime") {
if (deftype(ifn_b) != "int" || !def.count(ifn_b) || !def.count(ifn_a) || deftype(ifn_a) != "bool") {
retnum = UNKNOW_ERROR;
break;
}
def[ifn_a].b = is_prime(int_value(ifn_b));
} else if (ifn_opr == "sin" || ifn_opr == "cos" || ifn_opr == "tan"
|| ifn_opr == "sqrt" || ifn_opr == "cbrt" || ifn_opr == "log2"
|| ifn_opr == "log10") {
if (!def.count(ifn_b) || !def.count(ifn_a)) {
retnum = DEF_NOT_DEFINE;
return -1;
}
if (deftype(ifn_b) != "double") {
retnum = TYPE_NOT_DOUBLE;
return -1;
}
if (ifn_opr == "sin") {
def[ifn_a].lf = sin(double_value(ifn_b));
} else if (ifn_opr == "cos") {
def[ifn_a].lf = cos(double_value(ifn_b));
} else if (ifn_opr == "tan") {
def[ifn_a].lf = tan(double_value(ifn_b));
} else if (ifn_opr == "sqrt") {
def[ifn_a].lf = sqrt(double_value(ifn_b));
} else if (ifn_opr == "cbrt") {
def[ifn_a].lf = cbrt(double_value(ifn_b));
} else if (ifn_opr == "log2") {
def[ifn_a].lf = log2(double_value(ifn_b));
} else if (ifn_opr == "log10") {
def[ifn_a].lf = log10(double_value(ifn_b));
}
} else if (deftype(ifn_a) == "string" && deftype(ifn_b) == "int") {
if (if_b) {
if (ifn_opr == "times" || ifn_opr == "*=") {
def[ifn_a].s *= int_value(ifn_b);
} else if (ifn_opr == "divide" || ifn_opr == "/=") {
def[ifn_a].s /= int_value(ifn_b);
} else {
retnum = LET_ERROR;
break;
}
}
} else {
if (if_b) {
retnum = let(ifn_a, ifn_b, ifn_opr);
if (retnum) break;
}
}
} else if (isopr("openhtm")) {
std::string url;
cin >> url;
if (url == "luogu") {
int res = system("start https://luogu.com.cn");
if (res != 0) {
retnum = WEB_ERROR;
break;
}
} else if (url == "bilibili") {
int res = system("start https://bilibili.com.cn");
if (res != 0) {
retnum = WEB_ERROR;
break;
}
} else if (url == "baidu") {
int res = system("start https://baidu.com");
if (res != 0) {
retnum = WEB_ERROR;
break;
}
} else if (url == "aiqiyi") {
int res = system("start https://iqiyi.com");
if (res != 0) {
retnum = WEB_ERROR;
break;
}
} else {
std::string urls = "start " + url;
int result = system(urls.c_str());
if (result != 0) {
retnum = WEB_ERROR;
break;
}
}
} else if (isopr("mesbox")) {
string title, text, reh;
cin >> title >> text >> reh;
if (reh == "yes/no") {
MessageBox(NULL, text.c_str(), title.c_str(), MB_YESNO);
} else if (reh == "ok/cancel") {
MessageBox(NULL, text.c_str(), title.c_str(), MB_OKCANCEL);
} else {
retnum = UNKNOW_ERROR;
break;
}
} else if (isopr("beep")) {
double hz;
int ms;
cin >> hz >> ms;
Beep(hz, ms);
} else if (isopr("beep_piano")) {
int pno_12;
string pno_dr;
double si, li;
cin >> pno_12 >> pno_dr >> si >> li;
si = 240000.0 / si / li;
if (pno_dr == "do") {
Beep(pno[pno_12][1], si);
} else if (pno_dr == "re") {
Beep(pno[pno_12][2], si);
} else if (pno_dr == "mi") {
Beep(pno[pno_12][3], si);
} else if (pno_dr == "fa") {
Beep(pno[pno_12][4], si);
} else if (pno_dr == "so") {
Beep(pno[pno_12][5], si);
} else if (pno_dr == "la") {
Beep(pno[pno_12][6], si);
} else if (pno_dr == "xi") {
Beep(pno[pno_12][7], si);
} else if (pno_dr == "do#") {
Beep(pnos[pno_12][1], si);
} else if (pno_dr == "re#") {
Beep(pnos[pno_12][2], si);
} else if (pno_dr == "mi#") {
Beep(pnos[pno_12][3], si);
} else if (pno_dr == "fa#") {
Beep(pnos[pno_12][4], si);
} else if (pno_dr == "so#") {
Beep(pnos[pno_12][5], si);
} else if (pno_dr == "la#") {
Beep(pnos[pno_12][6], si);
} else if (pno_dr == "xi#") {
Beep(pnos[pno_12][7], si);
} else {
retnum = UNKNOW_ERROR;
break;
}
} else if (isopr("let_piano")) {
bool flag_err = false;
double si, li, bpno[1000][2];
int i;
cin >> si;
for (i = 1; true; i++) {
int pno_12;
cin >> pno_12;
if (pno_12 == -1) {
break;
}
string pno_dr;
cin >> pno_dr >> li;
li = 240000.0 / si / li;
if (pno_dr == "no") {
bpno[i][0] = 0;
bpno[i][1] = li;
} else if (pno_dr == "do") {
bpno[i][0] = pno[pno_12][1];
bpno[i][1] = li;
} else if (pno_dr == "re") {
bpno[i][0] = pno[pno_12][2];
bpno[i][1] = li;
} else if (pno_dr == "mi") {
bpno[i][0] = pno[pno_12][3];
bpno[i][1] = li;
} else if (pno_dr == "fa") {
bpno[i][0] = pno[pno_12][4];
bpno[i][1] = li;
} else if (pno_dr == "so") {
bpno[i][0] = pno[pno_12][5];
bpno[i][1] = li;
} else if (pno_dr == "la") {
bpno[i][0] = pno[pno_12][6];
bpno[i][1] = li;
} else if (pno_dr == "xi") {
bpno[i][0] = pno[pno_12][7];
bpno[i][1] = li;
} else if (pno_dr == "do#") {
bpno[i][0] = pnos[pno_12][1];
bpno[i][1] = li;
} else if (pno_dr == "re#") {
bpno[i][0] = pnos[pno_12][2];
bpno[i][1] = li;
} else if (pno_dr == "mi#") {
bpno[i][0] = pnos[pno_12][3];
bpno[i][1] = li;
} else if (pno_dr == "fa#") {
bpno[i][0] = pnos[pno_12][4];
bpno[i][1] = li;
} else if (pno_dr == "so#") {
bpno[i][0] = pnos[pno_12][5];
bpno[i][1] = li;
} else if (pno_dr == "la#") {
bpno[i][0] = pnos[pno_12][6];
bpno[i][1] = li;
} else if (pno_dr == "xi#") {
bpno[i][0] = pnos[pno_12][7];
bpno[i][1] = li;
} else {
retnum = UNKNOW_ERROR;
flag_err = true;
break;
}
}
if (flag_err) break;
for (int j = 1; j < i; j++) {
Beep(bpno[j][0], bpno[j][1]);
}
} else if (isopr("music")) {
string music_hub;
cin >> music_hub;
if (music_hub == "happy_song") {
music_happy_song();
} else if (music_hub == "guyongzhe") {
music_guyongzhe();
}
} else if (isopr("det")) {
int j_det;
cin >> j_det;
vector<vector<double>> matrix(j_det, vector<double>(j_det));
for (int i = 0; i < j_det; i++) {
for (int j = 0; j < j_det; j++) {
cin >> matrix[i][j];
}
}
set_out;
cout << out << determinant(matrix, j_det) << endl;
set_in;
} else if (isopr("vector")) {
int g_v;
cin >> g_v;
vector<double> vec_a, vec_b;
vec_a.push_back(0);
vec_b.push_back(0);
for (int i = 1;i <= g_v;i++) {
double k_in_vec;
cin >> k_in_vec;
vec_a.push_back(k_in_vec);
}
for(int i=1;i<=g_v;i++){
double k_in_vec;
cin>>k_in_vec;
vec_b.push_back(k_in_vec);
}
string vec_opr,vec_opr_sec;
cin>>vec_opr>>vec_opr_sec;
if(vec_opr == "plus" || vec_opr == "+"){
for(int i=1;i<=g_v;i++){
vec_a[i] += vec_b[i];
}
}else if(vec_opr == "minus" || vec_opr == "-"){
for(int i=1;i<=g_v;i++){
vec_a[i]-=vec_b[i];
}
}else if(vec_opr == "times" || vec_opr == "*"){
for(int i=1;i<=g_v;i++){
vec_a[i]*=vec_b[i];
}
}else if(vec_opr == "divide" || vec_opr == "/"){
for(int i=1;i<=g_v;i++){
vec_a[i]/=vec_b[i];
}
}else{
retnum = UNKNOW_ERROR;
break;
}
if(vec_opr_sec == "print"){
set_out;
cout<<out;
for(int i=1;i<=g_v;i++){
cout<<vec_a[i]<<" ";
}
set_in;
cout<<endl;
}else{
if(!def.count(vec_opr_sec) || (deftype(vec_opr_sec) != "int" && deftype(vec_opr_sec) != "double")){
retnum = DEF_NOT_DEFINE;
break;
}else{
int p__;
cin>>p__;
if(deftype(vec_opr_sec) == "int"){
def[vec_opr_sec].d = vec_a[p__];
}else{
def[vec_opr_sec].lf = vec_a[p__];
}
}
}
} else if (isopr("shape")) {
string shape_type;
cin >> shape_type;
if (shape_type == "square") {
int aqua_bian_l;
string aqua_tian;
cin >> aqua_bian_l >> aqua_tian;
for(int i = 1; i <= aqua_bian_l; i++) {
for(int j = 1; j <= aqua_bian_l; j++) {
cout << aqua_tian;
}
cout << endl;
}
} else if (shape_type == "rectangle") {
int rec_a, rec_b;
string rec_ti;
cin >> rec_a >> rec_b >> rec_ti;
for(int i = 1; i <= rec_a; i++) {
for(int j = 1; j <= rec_b; j++) {
cout << rec_ti;
}
cout << endl;
}
} else if (shape_type == "map") {
int map_n;
cin >> map_n;
const int map_N = map_n;
int map_a[map_N+1]={0}, maxx, minn;
cin >> map_a[1];
maxx = map_a[1];
minn = map_a[1];
for (int i = 2; i <= map_n; i++) {
cin >> map_a[i];
maxx = (maxx >= map_a[i])? maxx:map_a[i];
minn = (minn <= map_a[i])? minn:map_a[i];
}
for (int i = maxx; i >= minn; i--) {
for (int j = 1; j <= map_n; j++) {
if (i > 0) {
cout << (map_a[j] >= i?"# ":" ");
} else if (i < 0) {
cout << (map_a[j] <= i?"# ":" ");
}
}
if (i) cout << endl;
}
}
} else if (isopr("list")) {
string list_type;
cin >> list_type;
if (list_type == "let") {
int x;
string let_to_opr, name_b;
cin >> x >> let_to_opr >> name_b;
if (let_to_opr == "is" || let_to_opr == "=") {
lvec[x] = def[name_b].d;
} else if (let_to_opr == "plus" || let_to_opr == "+=") {
lvec[x] += def[name_b].d;
} else if (let_to_opr == "minus" || let_to_opr == "-=") {
lvec[x] -= def[name_b].d;
} else if (let_to_opr == "times" || let_to_opr == "*=") {
lvec[x] *= def[name_b].d;
} else if (let_to_opr == "divide" || let_to_opr == "/=") {
lvec[x] /= def[name_b].d;
} else if (let_to_opr == "mod" || let_to_opr == "%=") {
lvec[x] %= def[name_b].d;
} else if (let_to_opr == "and" || let_to_opr == "&&=") {
lvec[x] &= def[name_b].d;
} else if (let_to_opr == "or" || let_to_opr == "||=") {
lvec[x] |= def[name_b].d;
} else if (let_to_opr == "xor" || let_to_opr == "^^=") {
lvec[x] ^= def[name_b].d;
} else if (let_to_opr == "nor" || let_to_opr == "!|=") {
lvec[x] = ~(lvec[x] | def[name_b].d);
} else if (let_to_opr == "lshift" || let_to_opr == "<<=") {
lvec[x] <<= def[name_b].d;
} else if (let_to_opr == "rshift" || let_to_opr == ">>=") {
lvec[x] >>= def[name_b].d;
} else if (let_to_opr == "nxor" || let_to_opr == "!^=") {
lvec[x] = ~(lvec[x] ^ def[name_b].d);
} else if (let_to_opr == "nand" || let_to_opr == "!&=") {
lvec[x] = ~(lvec[x] ^ def[name_b].d);
} else if (let_to_opr == "pow" || let_to_opr == "^=") {
lvec[x] = int(pow(lvec[x], def[name_b].d));
} else {
return LET_ERROR;
}
} else if (list_type == "set") {
bool flag_ = false;
while (1) {
int x, y;
cin >> x >> y;
lvec[x] = y;
string an;
cin >> an;
if (an == "none" || an == ";") {
break;
} else if (an != "and" && an != ",") {
flag_=true;
break;
}
}
if(flag_) {
retnum = PRINT_TYPE_ERROR;
break;
}
} else if (list_type == "print") {
set_out;
cout << out;
set_in;
bool flag_ = false;
while (1) {
int x;
cin >> x;
set_out;
cout << lvec[x] << " ";
set_in;
string an;
cin >> an;
if (an == "none" || an == ";") {
break;
} else if (an != "and" && an != ",") {
flag_=true;
break;
}
}
cout << endl;
if(flag_) {
retnum = PRINT_TYPE_ERROR;
break;
}
}
} else if (isopr("for") || isopr("{}")) {
string for_type, for_i, for_to, for_do, for_print_type, fprint_str, type;
cin >> for_i >> for_to >> for_do >> type;
if (type == "print") {
cin >> for_print_type;
if (for_print_type[0] != '\"') {
if (!def.count(for_print_type) && for_print_type != "FOR_NUM") {
retnum = DEF_NOT_DEFINE;
break;
}
} else {
fprint_str = for_print_type;
fprint_str.erase(0,1);
}
}
if (type == "list_print" || type == "print") {
set_out;
cout << out;
set_in;
}
for(int i = int_value(for_i); i <= int_value(for_to); i += int_value(for_do)) {
if (type == "list_print") {
set_out;
cout << lvec[i] << " ";
set_in;
} else if (type == "print") {
if (for_print_type == "FOR_NUM") {
cout << i << " ";
} else if (for_print_type[0] == '\"') {
cout << fprint_str << " ";
}
}
}
} else if (isopr("help") || isopr("<::")) {
string help_type;
cin >> help_type;
set_out;
if (help_type == "def") {
cout << "def定义 ---+--- 变量类型(int/double/string/char/bool) --- 变量名name --- 变量值val --- 分隔符(,/and/;/none)\n";
cout << " |\n";
cout << " +--- 变量类型(stack<(int/double/string)>/queue<(int/double/string)>) --- 分隔符(,/and/;/none)\n";
} else if (help_type == "print") {
cout << "print输出 ---+--- 变量名name --- 分隔符(,/and/;/none)\n";
cout << " |\n";
cout << " +--- 字符串k(输出) --- 分隔符(,/and/;/none)\n";
} else if (help_type == "stack") {
cout << "stack栈操作 ---+--- opr(top栈顶/pop弹出) \n";
cout << " | \n";
cout << " +--- opr(push压入) --- 常量val\n";
} else if (help_type == "queue") {
cout << "queue队列操作 ---+--- opr(front队首/pop弹出) \n";
cout << " | \n";
cout << " +--- opr(push压入) --- 常量val\n";
} else if (help_type == "let") {
cout << "let赋值及运算 --- 变量val_a --- 操作符号opr(string) --- 变量valb\n";
} else if (help_type == "no_line") {
cout << "no_line注释 --- 字符串line(string)\n";
} else if (help_type == "math") {
cout << "math数学运算 ---+--- opr(fib) --- val(int) \n";
cout << " | \n";
cout << " +--- opr(sin/cos/tan/sqrt) --- val(double)\n";
} else if (help_type == "file_in") {
cout << "file_in文件输入 --- 文件名fname --- 变量个数g --- 变量名(已定义)\n";
cout << " |\n";
cout << " +- 变量名(未定义,文件中的第一个字符串为变量类型名)\n";
} else if (help_type == "file_out") {
cout << "file_out文件输出 --- 文件名fname --- 变量名/\"字符串 --- 分隔符\n";
} else if (help_type == "to") {
cout << "to类型转换(有一些功能未开发) --- 变量名a --- 类型名type\n";
} else if (help_type == "bcomp") {
cout << "bcomp(bool值运算) --- value变量 --- val_a --- opr --- val_b\n";
cout << " |\n";
cout << " -- number常量 --- num_a --- opr --- num_b\n";
} else if (help_type == "if") {
cout << "if --- 变量i(bool) --- a --- let_opr --- b\n";
} else if (help_type == "mesbox") {
cout << "mesbox窗口 --- 标题title --- 正文text --- 类型op\n";
} else if (help_type == "openhtm") {
cout << "openhtm打开网址 --- name_htm网址\n";
} else if (help_type == "det") {
cout << "det行列式 --- j阶数 --- A(j,j)行列元素\n";
} else if (help_type == "beep") {
cout << "beep声音 --- pt频率 --- ms时间(毫秒)\n";
} else if (help_type == "beep_piano") {
cout << "beep_piano钢琴声音 --- j(int)音阶 --- h(string)音高 --- time(double)每分钟弹的4分音符数量 --- f(double)时长(几分音符)\n";
} else if (help_type == "shape") {
cout << "shape形状 -+- square正方形 --- a边长 --- ch(char)字符\n";
cout << " +- rectangle长方形 --- a长 --- b宽 --- ch(char)字符\n";
cout << " +- map条形图 --- r参数个数 --- k_(1 to r)参数\n";
} else if (help_type == "list") {
cout << "list数组 -+- set设置 --- x下标 --- y值 --- 分隔符\n";
cout << " +- print输出 --- x下标 --- 分隔符\n";
cout << " +- let输出 --- x下标 --- opr操作符 --- 变量a\n";
} else if (help_type == "for") {
cout << "for循环 --- for_i(int) --- for_to(int) --- for_do(int) --- print输出 --- a变量/字符串 --- 分隔符(,/and/;/none)\n";
cout << " +- list_print数组 --- 分隔符(,/and/;/none)\n";
}
set_in;
} else if (isopr("end")) {
cout << endl;
retnum = NONE_ERR;
break;
} else {
retnum = OPR_NOT_TYPE;
break;
}
}
if (retnum > 0) {
MessageBox(NULL, "错误!\nWrong!", "Cnle10.0 Wrong", MB_ICONERROR | MB_OK);
}
end_cnle(retnum);
return retnum;
}剪贴板
剪贴板 ulg2mayk
剪贴板信息
剪贴板信息
- 收录
- 更新