diff --git a/code_segment/huawei.cpp b/code_segment/huawei.cpp new file mode 100644 index 00000000..f6f82ecc --- /dev/null +++ b/code_segment/huawei.cpp @@ -0,0 +1,51 @@ +#include +#include +using namespace std; + + + +vector> gameOfLife(vector> board) { + vector> res(board.size(),vector(board[0].size(),0)); + for(int i=0;i=0 && x=0 && y3){ + res[i][j]=0; + } + else if(count==3){ + res[i][j]=1; + } + else if(count==2 && board[i][j]==1){ + res[i][j]=1; + } + } + } + return res; +} + +int main(){ + vector> vec = { + {0,1,0}, + {0,0,1}, + {1,1,1}, + {0,0,0} + }; + vector> res= gameOfLife(vec); + for(auto a:res){ + for(auto b:a){ + cout< +#include +#include +using namespace std; + + +string get(string s,vector dictionary){ + vector vec(dictionary.size(),0); + for(int i=0;imax_length){ + index=i; + max_length=dictionary[i].size(); + } + } + if(max_length==0){ + return ""; + } + return dictionary[index]; +} +int main(){ + string s = "abpcplea"; + vector dictionary = {"ale","apple","monkey","plea"}; + // vector dictionary = {"a","b","c"}; + + sort(dictionary.begin(), dictionary.end()); + string res = get(s,dictionary); + cout< dictionary) { + + } +} diff --git a/code_segment/image/2021-09-26-10-33-16.png b/code_segment/image/2021-09-26-10-33-16.png new file mode 100644 index 00000000..e8392303 Binary files /dev/null and b/code_segment/image/2021-09-26-10-33-16.png differ diff --git a/code_segment/wangyi.cpp b/code_segment/wangyi.cpp new file mode 100644 index 00000000..e69de29b diff --git a/code_segment/xiaohongshu1.cpp b/code_segment/xiaohongshu1.cpp index 3c83ed70..b47633d4 100644 --- a/code_segment/xiaohongshu1.cpp +++ b/code_segment/xiaohongshu1.cpp @@ -1,9 +1,5 @@ #include using namespace std; -/** - * 交换任意两数的本质是改变了元素位置, - * 故建立元素与其目标状态应放置位置的映射关系 - */ int getMinSwaps(vector v) { vector v1(v); //将A内元素复制到B。 @@ -42,6 +38,6 @@ int main() v.push_back(k); } int num = getMinSwaps(v); - cout<<"交换次数:"< +#include +#include +using namespace std; + + +int main(){ + + int n,m; + cin>>n>>m; + vector> vec(n,vector(m,0)); + int x,y,d=0; + for(int i=0;i>num; + cin.ignore(); + int ox=x,oy=y; + while(num--){ + string line; + getline(cin,line); + if(line=="Turn right"){ + d=(d+1)%4; + } + else if(line=="Turn left"){ + d=((d-1)+4)%4; + } + else if(line[0]=='F'){ + istringstream is(line); + string temp; + is>>temp; + int step; + is>>step; + + while(step--){ + if(d==0){ + if(x-1>=0 && vec[x-1][y]==0){ + x=x-1; + } + else{ + break; + } + } + else if(d==1){ + if(y+10 && vec[x][y-1]==0){ + y=y-1; + } + else{ + break; + } + } + + } + } + } + cout<