/* CLB.cpp 2011.1.18 本程序實現了一種最簡單的基於命令的語言 該語言有以下4種命令 PrintString "..." PrintStringLoop "..." number NewLine WaitForKeyPress 該程序通過讀取磁盤上,用該命令寫成的腳本,分析該語言,輸出對應的結果 //是遊戲腳本高級編程的第三章的第一個程序,我用c++將其重寫 //運行環境 vs2005 通過 運行結果: "This is a command-based language." "Therefore,this is a command-based script." "...and it's really quite boring." "this string has been repeated four times." "this string has been repeated four times." "this string has been repeated four times." "this string has been repeated four times." "Okay,press a key already and put us both out of our misery." "The new demo is cooler,I swear." 請按任意鍵繼續. . . */ #include<fstream> #include<iostream> #include<string> #include<vector> #include<cassert> #include"conio.h" using namespace std; #define COMMAND_PRINTSTRING "PrintString" #define COMMAND_PRINTSTRINGLOOP "PrintStringLoop" #define COMMAND_NEWLINE "NewLine" #define COMMAND_WAITFORKEYPRESS "WaitForKeyPress" //在內存中存放腳本 vector<string> script; /* 函數名:LoadScript 功能:讀入腳本 參數: fileName:文件名 */ void LoadScript(string fileName); /* 函數名:UnloadScript 功能:註銷腳本 */ void UnloadScript(); /* 函數名:RunScript 功能:運行腳本 */ void RunScript(); /* 函數名:GetCurrentScript 功能:得到當前行的腳本 參數: line:當前行號 返回值:當前行的腳本 */ string& GetCurrentScript(size_t line); /* 函數名:GetCommand 功能:得到當前行的腳本的命令 參數: currentScript:當前行的腳本 返回值:得到當前行的腳本的命令 */ string GetCommand(const string& currentScript); /* 函數名:GetIntParam 功能:得到當前行的腳本的int參數 參數: currentScript:當前行的腳本 返回值:得到當前行的腳本的int參數 */ int GetIntParam(const string& currentScript); /* 函數名:GetStringParam 功能:得到當前行的腳本的string參數 參數: currentScript:當前行的腳本 返回值:得到當前行的腳本的string參數 */ string GetStringParam(const string& currentScript); int main() { /* 本地文件cbl.txt PrintString "This is a command-based language." PrintString "Therefore,this is a command-based script." NewLine PrintString "...and it's really quite boring." NewLine PrintStringLoop "this string has been repeated four times." 4 NewLine PrintString "Okay,press a key already and put us both out of our misery." PrintString "The new demo is cooler,I swear." WaitForKeyPress */ string textName("cbl.txt"); //加載腳本 LoadScript(textName); //運行腳本 RunScript(); //卸載腳本 UnloadScript(); return 0; } void LoadScript(string fileName) { ifstream file; //打開文件 file.open(fileName.c_str()); if(!file) { cout<<"error: unable to open the file:" <<fileName<<endl; exit(-1); } //加載到內存中 while(!file.eof()) { string line; getline(file,line); script.push_back(line); } //垃圾回收 file.clear(); file.close(); } void UnloadScript() { //清空腳本 script.erase(script.begin(),script.end()); assert(script.empty()); } void RunScript() { //腳本行數 size_t scriptSize=script.size(); //循環運行每一條腳本 for(size_t line = 0;line !=scriptSize; ++line) { //得到當前腳本 string currentScript=GetCurrentScript(line); if(currentScript.size()<=3) continue; //得到當前腳本的命令 string command=GetCommand(currentScript); //根據命令不同,執行方式也不同 if(command==COMMAND_PRINTSTRING) { //得到string參數 string param=GetStringParam(currentScript); cout<<'/t'<<param<<endl; } else if(command == COMMAND_PRINTSTRINGLOOP) { //得到string參數 string param=GetStringParam(currentScript); //得到int參數 int loopNum=GetIntParam(currentScript); for(int i=0;i<loopNum;++i) cout<<'/t'<<param<<endl; } else if(command == COMMAND_NEWLINE) { cout<<endl; } else if(command == COMMAND_WAITFORKEYPRESS) { //_kbhit returns a nonzero value if a key has been pressed. Otherwise, it returns 0. while(!kbhit()) ; } else { printf("/tError: Invalid command./n"); break; } } } string & GetCurrentScript(size_t line) { return script[line]; } string GetCommand(const string& currentScript) { string command(""); for(size_t i=0;currentScript[i]!=' ' && i!=currentScript.size();++i) command.push_back(currentScript[i]); return command; } int GetIntParam(const string& currentScript) { string loopNumString; for(size_t i=currentScript.find_last_of('"')+1;i!=currentScript.size();++i) { loopNumString.push_back(currentScript[i]); } int loopNum=atoi(loopNumString.c_str()); return loopNum; } string GetStringParam(const string& currentScript) { string param; for(size_t i=currentScript.find(' ')+1;i!=currentScript.find_last_of('"')+1;++i) { param.push_back(currentScript[i]); } return param; }
Ai technology 前言 AppBuilder上線了低代碼製作組件功能,可以通過工作流的方式構建自定義組件,完成簡單Agent無法完成的複雜功能,使得生成的文本更加定製化,
最近在刷一些問題的時候看到有下面一個問題 上面問的是當輸入的字符串爲什麼的時候返回 True 總結 在做題目的時候,第一次還做錯了。 這是因爲解答這個題目的時間只有 3 分鐘,沒有自己看題目 後來拿着程序跑了下。 p
簡介: 搶紅包是我們生活常用的社交功能, 這個功能最主要的特點就是用戶的併發請求高, 在系統設計上, 可以使用非常多的辦法來扛住用戶的高併發請求, 在本文中簡要介紹使用Redis緩存中間件來實現搶紅包算法, Redis是一個在內存中基
字符串是 Java 程序中最常用的數據結構之一。在 Java 中 String 類已經重載了"+",字符串可以直接使用"+"進行連接,也可以用StringBuilder/StringBuffer(StringBuilder是J2SE5 及以
Java 平臺提供了兩種類型的字符串操作方式:String 和 StringBuffer/StringBuilder,它們都可以儲存和操作字符串,區別如下: String 是隻讀字符串,也就意味着 String 引用的字符串內容是不能被改
1 枚舉好用嗎? 數據字典型字段,枚舉比Integer好: 限定值,只能賦值枚舉的那幾個實例,不能像Integer隨便輸,保存和查詢的時候特別有用 含義明確,使用時不需要去查數據字典 顯示值跟存儲值直接映射,不需要手動轉換,比如1在頁面上
1 概述 通道是Golang提供的一種基本類型,它可以實現在協程之間的單向通信和雙向通信、發送和接收數據、以及協程同步。 channel的本質是一個隊列,遵循先進先出原則。channel是線程安全的,在任何給定時間,一個數據被設計爲只有一
在 Kubernetes 中,您可以通過爲容器的生命週期事件設置處理函數來執行命令。Kubernetes 支持兩種生命週期事件處理函數:postStart 和 preStop。 postStart 處理函數:在容器創建後立即執行。這個處
一、文件屬性 下文中,“文件”一詞默認代指廣義的數據類型,跟“目錄”等詞對比使用時,則專指普通文件(File)這一特定數據類型。 Linux系統中,我們可以使用命令“ls -al”來查看當前目錄
要將Git中的一個文件恢復到之前的版本,你可以使用git checkout命令結合特定的提交哈希值(commit hash)或引用(如HEAD~1)來檢出該文件的特定版本。 以下是如何操作的步驟: 查看文件的歷史: 首先,你可以使用gi
curl -F "[email protected]" -F "puid=181174000" -X POST "http://pan-yz.chaoxing.com/upload" curl -F "file=@WeChat_20221
大家好,我是Python進階者。 一、前言 前幾天在Python最強王者交流羣【wen】問了一個Python處理Excel加密文件讀取問題。問題如下: 請教:讀取設置了密碼保護的exlce文件,df = pd.read_excel(file
“OpenAI 將在 2027 年實現人類水平的 AGI” “OpenAI 從 2022 年 8 月就在訓練 125 萬億參數的多模態模型,但由於推理成本過高而被取消” …… 這是最近硅谷乃至整個科技圈都在討論的熱門話題,內容均
寫這個筆記其目的還是記錄下自己之前做的細節,原以爲弄過的東西會深深的印入腦海無需囉裏囉嗦的記錄,今天回憶的時候發現我已經不記得是從何入手了想想就覺得可怕還是老老實實把以前的備份實操記錄下來把。 主從複製常見的用途:數據分佈,
一、什麼是大文件 一般,我們傳送大文件是指傳送大於100M的文件,而普通文件是指小於100M,常見的是20M、30M和50M,兩者主要的區別在於文件大小上,還有傳送速度上。 一般普通“郵件附件”只能發20M、30M,50M的文件,而幾百M的