classSolution{public:vector<string>splitWordsBySeparator(vector<string>&words,charseparator){vector<string>ans;// Line 11: Char 44: error: no member named 'sub_str' in 'std::basic_string<char>'
// It is `substr(start, start+cnt)`
for(auto&word:words){intpre_i=-1;intword_size=word.size();for(inti=0;i<word_size;i++){if(word[i]==separator){if(i-1>pre_i){ans.push_back(word.substr(pre_i+1,i-1-pre_i));}pre_i=i;}}if(pre_i!=word_size-1){ans.push_back(word.substr(pre_i+1,word_size-1-pre_i));}}returnans;}};
typedefstruct{char**data;intsize;intcapacity;}vector;voidappend(vector*v,char*sub){if(v->capacity==v->size){if(v->capacity==0){v->capacity=4;}else{v->capacity*=2;}char**data1=(char**)malloc(sizeof(char*)*v->capacity);if(v->data!=NULL){memcpy(data1,v->data,sizeof(char*)*v->size);}free(v->data);v->data=data1;}char*p=(char*)malloc(sizeof(char)*(strlen(sub)+1));strcpy(p,sub);v->data[v->size++]=p;}char**splitWordsBySeparator(char**words,intwordsSize,charseparator,int*returnSize){constcharsep[2]={separator};vectorv;memset(&v,0,sizeof(vector));for(inti=0;i<wordsSize;i++){// man strtok to learn more.
for(constchar*sub=strtok(words[i],sep);sub!=NULL;sub=strtok(NULL,sep)){if(strlen(sub)!=0){append(&v,sub);}}}*returnSize=v.size;returnv.data;}// 链接:https://leetcode.cn/problems/split-strings-by-separator/solutions/2595926/an-fen-ge-fu-chai-fen-zi-fu-chuan-by-lee-bti9/
Review
Solana Whitepaper Explained
In this vedio, I learn that solana used CP model which sacrifices some availability.
Tips
如何压缩与解压.tar.gz格式的文件
压缩命令:
tar -zcvf 压缩文件名.tar.gz 被压缩文件名...[多个则空格分隔]
可先切换到当前目录下,压缩文件名和被压缩文件名都可加入路径。
解压缩命令:
tar -zxvf 压缩文件名.tar.gz [-C 指定目录]
解压缩后的文件只能放在当前的目录 [-C 指定目录]。
个人加深理解
tar --help 得到常用的一些选项的释义。
z 是处理 tar.gz 而不是单独 tar
-z, –gzip, –gunzip, –ungzip filter the archive through gzip
c 创建 tar 压缩
-c, –create create a new archive
v 输出打印
-v, –verbose verbosely list files processed
f 使用文件
-f, –file=ARCHIVE use archive file or device ARCHIVE
x 提出文件
-x, –extract, –get extract files from an archive
C 提到制定目录, –directory=DIR change to directory DIR
CACHEDIR.TAG, except for the tag file itself
importgrpcfromconcurrentimportfuturesfromecho_pb2importEchoRequest,EchoResponsefromecho_pb2_grpcimportEchoServiceServicer,add_EchoServiceServicer_to_serverclassEchoServiceHandler(EchoServiceServicer):defEchoMessage(self,request,context):echoed_message=request.messagereturnEchoResponse(echoed_message=echoed_message)defserve():server=grpc.server(futures.ThreadPoolExecutor(max_workers=10))add_EchoServiceServicer_to_server(EchoServiceHandler(),server)server.add_insecure_port('[::]:50051')print("Server listening on port 50051...")server.start()server.wait_for_termination()if__name__=='__main__':serve()