日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[笔试面试][code_by_hand]输出第二个字符串在第一个字符串中的连接次序

發布時間:2025/5/22 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [笔试面试][code_by_hand]输出第二个字符串在第一个字符串中的连接次序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1
#include <iostream> 2 #include <string> 3 #include <vector> 4 using namespace std; 5 6 //摘自程序員面試寶典 7 //輸入兩個字符串,比如abdbcc和abc,輸出第二個字符串在第一個字符串中的連接次序 8 //即輸出125,126,145,146 9 template <class T> 10 void print(vector<T> v) 11 { 12 for (typename vector<T>::iterator it = v.begin(); it != v.end(); it++) 13 { 14 cout<<*it<<" "; 15 } 16 cout<<endl; 17 } 18 19 void print(char str1[], char str2[], int index1, int index2, vector<int> &v) 20 { 21 if (str1==NULL || str2==NULL) 22 { 23 return; 24 } 25 if (str1[index1]=='\0' || str2[index2]=='\0') 26 { 27 if (!(str1[index1]=='\0' && str2[index2]!='\0') ) 28 { 29 print(v); 30 } 31 return; 32 } 33 if (str1[index1]==str2[index2]) 34 { 35 v.push_back(index1); 36 print(str1, str2, index1+1, index2+1, v); 37 v.pop_back(); 38 } 39 print(str1, str2, index1+1, index2, v); 40 } 41 42 int main() 43 { 44 char * str1 = "abdbcc"; 45 char * str2 = "abcd"; 46 int index1 = 0, index2 = 0; 47 vector<int> v; 48 print(str1, str2, index1, index2, v); 49 return 0; 50 }

?

轉載于:https://www.cnblogs.com/wendelhuang/archive/2013/05/09/3068487.html

總結

以上是生活随笔為你收集整理的[笔试面试][code_by_hand]输出第二个字符串在第一个字符串中的连接次序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。