正文
增加 33 行删除 33 行
9 行未改动101112131415161718192021222324252627282930313233343536372 行未改动404142434445464748495051525354555657585960616263646 行未改动717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111229 行未改动14214314414514614714814915033 行未改动184185186187188189190191192193194195196197198199200212 行未改动全部展开41341441541641741841942042173 行未改动49549649749849950050150250350 行未改动55455555655755855956056156237 行未改动60060160260360460560660760831 行未改动64064164264364464564664764811 行未改动660661662663664665666667668127 行未改动全部展开79679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183245 行未改动9 行未改动// 追加模式:不会删除原有内容void AppendKeywordsInteractive() {vector<string> keywords;string input;cout << "一行一个关键字,输入done结束" << endl;while (true) {cout << "> ";getline(cin, input);if (input == "done") {break;}if (!input.empty()) {keywords.push_back(input);}}if (keywords.empty()) {return;}// OPEN_ALWAYS: 存在则打开,不存在则创建HANDLE hFile = CreateFileA("keywords.txt",GENERIC_WRITE,2 行未改动OPEN_ALWAYS, // 改为这个!不会覆盖已有内容FILE_ATTRIBUTE_NORMAL,NULL);if (hFile == INVALID_HANDLE_VALUE) {return; // 不要提示!}// 移动到文件末尾(追加)SetFilePointer(hFile, 0, NULL, FILE_END);// 写入新内容for (const auto& keyword : keywords) {string line = keyword + "\n";DWORD bytesWritten;WriteFile(hFile, line.c_str(), (DWORD)line.length(), &bytesWritten, NULL);}CloseHandle(hFile);// 可选:显示结果但不提示错误cout << "输入了 " << keywords.size() << " 个关键字." << endl;}6 行未改动OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);if (hFile == INVALID_HANDLE_VALUE) {return 1;}DWORD fileSize = GetFileSize(hFile, NULL);if (fileSize == 0) {CloseHandle(hFile);return 1;}char* buffer = new char[fileSize + 1];DWORD bytesRead;ReadFile(hFile, buffer, fileSize, &bytesRead, NULL);buffer[bytesRead] = '\0';string fileContent = buffer;size_t pos = 0;while ((pos = fileContent.find('\n')) != string::npos) {string line = fileContent.substr(0, pos);if (!line.empty() && line.back() == '\r') {line.pop_back();}if (line == name) {delete[] buffer;CloseHandle(hFile);return 0;}fileContent.erase(0, pos + 1);}delete[] buffer;CloseHandle(hFile);return 1;}29 行未改动return -1 ;int x = 1 ;long long ans = 0 ;if(sum[0] == '-')x = -1 , sum.erase(sum.begin()) ;for(auto i : vl){if(i.name == name)return -2 ;33 行未改动ans += (sum.at(i) - '0') ;if(ans < 0)return -1 ;}for(int i = 0 ; i < vl.size() ; i ++){if(vl[i].name == name){vl[i].sum = ans * x ;return 0 ;}}return -3 ;}if(lx == 's' || lx == 'n')212 行未改动全部展开i ++ ;for(; i < zj.size() ; i ++)name += zj[i] ;int fh = cr_var(name , "0" , x) ;switch(fh){case 0 :{73 行未改动break;}case -3 :{rt = "未找到变量" ;break;}case -4 :{50 行未改动case -1 :{rt = "未找到变量" ;break;}case -3 :{rt = "不是我都防过了,怎么还有奇怪的变量类型" ;break;37 行未改动wait() ;rt = "正确" ;return rt ;}else if(kt == "inv"){string lx = "" ;int i ;31 行未改动break;}case -5 :{rt = "未找到变量" ;break;}case -4 :{11 行未改动else if(kt == "exit"){rt = "exit" ;return kt ;}else if(kt == "mth"){string n1 = "" , n2 = n1 , n3 = n2 , x = n3 ;char lx , fh2 ;127 行未改动全部展开c++解释与代码示例中()包裹的为前置条件&表示同步执行的条件(类似c++中的逗号表达式,但只可在代码示例中可用)cv 创建变量用法:cv [类型] [变量名]例:cv int a要注意,有一些关键词不可作为变量名类型只能为mvs 将变量值修改为常量值用法:mvs (类型,默认为自动选择(优先选择int类型)) [变量名] [常量值]例:(cv int a) mvs int a 10也可写成 mvs int a 10上面一行的写法要注意int类型和string类型变量名重名时只会修改int类型的值mvv 将变量值修改为另外的变量值用法:mvv [两个变量的类型 类型必须相同] [需赋值变量名] [给前者赋值的变量名]例:(cv int a & cv int b)mvv int a b上面一行的代码用c++解释为(long long a , b ;)a = b ;ptv 打印(输出)变量用法:ptv (类型,默认为自动选择(优先选择int类型)) [变量名] [是(1)否(0)换行]例:(cv int a & mvs int a 10)ptv int a 1上面一行的写法要注意int类型和string类型变量名重名时只会输出int类型的值pts 打印(输出)字符串用法:pts [是(1)否(0)换行] [字符串]例:pts 1 hello world!cls 清屏用法:cls无示例45 行未改动9 行未改动101112131415161718192021222324252627282930313233343536372 行未改动404142434445464748495051525354555657585960616263646 行未改动717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111229 行未改动14214314414514614714814915033 行未改动184185186187188189190191192193194195196197198199200212 行未改动全部展开41341441541641741841942042173 行未改动49549649749849950050150250350 行未改动55455555655755855956056156237 行未改动60060160260360460560660760831 行未改动64064164264364464564664764811 行未改动660661662663664665666667668127 行未改动全部展开79679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183245 行未改动9 行未改动// 追加模式:不会删除原有内容void AppendKeywordsInteractive() {vector<string> keywords;string input;cout << "一行一个关键字,输入done结束" << endl;while (true) {cout << "> ";getline(cin, input);if (input == "done") {break;}if (!input.empty()) {keywords.push_back(input);}}if (keywords.empty()) {return;}// OPEN_ALWAYS: 存在则打开,不存在则创建HANDLE hFile = CreateFileA("keywords.txt",GENERIC_WRITE,2 行未改动OPEN_ALWAYS, // 改为这个!不会覆盖已有内容FILE_ATTRIBUTE_NORMAL,NULL);if (hFile == INVALID_HANDLE_VALUE) {return; // 不要提示!}// 移动到文件末尾(追加)SetFilePointer(hFile, 0, NULL, FILE_END);// 写入新内容for (const auto& keyword : keywords) {string line = keyword + "\n";DWORD bytesWritten;WriteFile(hFile, line.c_str(), (DWORD)line.length(), &bytesWritten, NULL);}CloseHandle(hFile);// 可选:显示结果但不提示错误cout << "输入了 " << keywords.size() << " 个关键字." << endl;}6 行未改动OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);if (hFile == INVALID_HANDLE_VALUE) {return 1;}DWORD fileSize = GetFileSize(hFile, NULL);if (fileSize == 0) {CloseHandle(hFile);return 1;}char* buffer = new char[fileSize + 1];DWORD bytesRead;ReadFile(hFile, buffer, fileSize, &bytesRead, NULL);buffer[bytesRead] = '\0';string fileContent = buffer;size_t pos = 0;while ((pos = fileContent.find('\n')) != string::npos) {string line = fileContent.substr(0, pos);if (!line.empty() && line.back() == '\r') {line.pop_back();}if (line == name) {delete[] buffer;CloseHandle(hFile);return 0;}fileContent.erase(0, pos + 1);}delete[] buffer;CloseHandle(hFile);return 1;}29 行未改动return -1 ;int x = 1 ;long long ans = 0 ;if(sum[0] == '-')x = -1 , sum.erase(sum.begin()) ;for(auto i : vl){if(i.name == name)return -2 ;33 行未改动ans += (sum.at(i) - '0') ;if(ans < 0)return -1 ;}for(int i = 0 ; i < vl.size() ; i ++){if(vl[i].name == name){vl[i].sum = ans * x ;return 0 ;}}return -3 ;}if(lx == 's' || lx == 'n')212 行未改动全部展开i ++ ;for(; i < zj.size() ; i ++)name += zj[i] ;int fh = cr_var(name , "0" , x) ;switch(fh){case 0 :{73 行未改动break;}case -3 :{rt = "未找到变量" ;break;}case -4 :{50 行未改动case -1 :{rt = "未找到变量" ;break;}case -3 :{rt = "不是我都防过了,怎么还有奇怪的变量类型" ;break;37 行未改动wait() ;rt = "正确" ;return rt ;}else if(kt == "inv"){string lx = "" ;int i ;31 行未改动break;}case -5 :{rt = "未找到变量" ;break;}case -4 :{11 行未改动else if(kt == "exit"){rt = "exit" ;return kt ;}else if(kt == "mth"){string n1 = "" , n2 = n1 , n3 = n2 , x = n3 ;char lx , fh2 ;127 行未改动全部展开c++解释与代码示例中()包裹的为前置条件&表示同步执行的条件(类似c++中的逗号表达式,但只可在代码示例中可用)cv 创建变量用法:cv [类型] [变量名]例:cv int a要注意,有一些关键词不可作为变量名类型只能为mvs 将变量值修改为常量值用法:mvs (类型,默认为自动选择(优先选择int类型)) [变量名] [常量值]例:(cv int a) mvs int a 10也可写成 mvs int a 10上面一行的写法要注意int类型和string类型变量名重名时只会修改int类型的值mvv 将变量值修改为另外的变量值用法:mvv [两个变量的类型 类型必须相同] [需赋值变量名] [给前者赋值的变量名]例:(cv int a & cv int b)mvv int a b上面一行的代码用c++解释为(long long a , b ;)a = b ;ptv 打印(输出)变量用法:ptv (类型,默认为自动选择(优先选择int类型)) [变量名] [是(1)否(0)换行]例:(cv int a & mvs int a 10)ptv int a 1上面一行的写法要注意int类型和string类型变量名重名时只会输出int类型的值pts 打印(输出)字符串用法:pts [是(1)否(0)换行] [字符串]例:pts 1 hello world!cls 清屏用法:cls无示例45 行未改动