输入两个字符串,输出第二个字符串在第一个字符串中的连接次序
来源:互联网 发布:c语言for循环嵌套例子 编辑:程序博客网 时间:2024/05/16 00:33
#include <iostream>
using namespace std;
void printArray(char *pcParent, char *pcSon, int *orderArray, const int npLen, int npStartNum, const int nsLen, int nsCurrentNum)
{
if (nsCurrentNum == nsLen)
{
for (int i = 0; i < nsLen; i++)
{
cout << orderArray[i] << " ";
}
cout << endl;
return;
}
else
{
for (int j = npStartNum; j < npLen; j++)
{
if (pcParent[j] == pcSon[nsCurrentNum])
{
orderArray[nsCurrentNum] = j + 1;
printArray(pcParent, pcSon, orderArray, npLen, j + 1, nsLen, nsCurrentNum + 1);
}
}
}
}
void conncetSequence(char *pcParent, char *pcSon)
{
const int npLen = strlen(pcParent);
const int nsLen = strlen(pcSon);
if (nsLen == 0 || npLen == 0)
{
cout << "The string can not be empty!" << endl;
return;
}
else
{
int *pnArray = new int[nsLen];
if (pnArray == NULL)
{
cout << "Allocate memory failed!" << endl;
return;
}
else
{
printArray(pcParent, pcSon, pnArray, npLen, 0, nsLen, 0);
}
delete pnArray;
pnArray = NULL;
}
}
int main()
{
char *pcParent = "acbdbcadbccbabc";
char *pcSon = "abc";
conncetSequence(pcParent, pcSon);
return 0;
}
using namespace std;
void printArray(char *pcParent, char *pcSon, int *orderArray, const int npLen, int npStartNum, const int nsLen, int nsCurrentNum)
{
if (nsCurrentNum == nsLen)
{
for (int i = 0; i < nsLen; i++)
{
cout << orderArray[i] << " ";
}
cout << endl;
return;
}
else
{
for (int j = npStartNum; j < npLen; j++)
{
if (pcParent[j] == pcSon[nsCurrentNum])
{
orderArray[nsCurrentNum] = j + 1;
printArray(pcParent, pcSon, orderArray, npLen, j + 1, nsLen, nsCurrentNum + 1);
}
}
}
}
void conncetSequence(char *pcParent, char *pcSon)
{
const int npLen = strlen(pcParent);
const int nsLen = strlen(pcSon);
if (nsLen == 0 || npLen == 0)
{
cout << "The string can not be empty!" << endl;
return;
}
else
{
int *pnArray = new int[nsLen];
if (pnArray == NULL)
{
cout << "Allocate memory failed!" << endl;
return;
}
else
{
printArray(pcParent, pcSon, pnArray, npLen, 0, nsLen, 0);
}
delete pnArray;
pnArray = NULL;
}
}
int main()
{
char *pcParent = "acbdbcadbccbabc";
char *pcSon = "abc";
conncetSequence(pcParent, pcSon);
return 0;
}
- 输入两个字符串,输出第二个字符串在第一个字符串中的连接次序
- 输入两个字符串,比如abdcc和abc,输出第二个字符串在第一个字符串中的连接次序
- 输入两个字符串,比如abdbcc和abc,输出第二个字符串在第一个字符串中的连接次序
- 《程序员面试宝典》:输入两个字符串,比如abdbcc和abc,输出第二个字符串在第一个字符串中的连接次序,即输出125,126,145,146
- 输出第二个字符串在第一个字符串中的次序
- 输入两个字符串,比如abdbcc和abc,输出第二个字符串在第一个字符串中的连接次序(递归方法)
- 输入两个字符串,比如abdbcc和abc,输出第二个字符串在第一个字符串中的连接次序(递归方法)
- 输入两个字符串,比如abdbcc和abc,输出第二个字符串在第一个字符串中的连接次序(递归方法)
- 输入两个字符串,比如abdbcc和abc,输出第二个字符串在第一个字符串中的连接次序(递归方法)
- 字符串问题:输出第二个字符串在第一个字符串中的连接次序
- 输出第二个字符串在第一个字符串中的连接次序(递归算法)
- 程序员面试宝典 8.2 典型递归问题: 面试例题1: 输入两个字符串,比如 abdbcc 和 abc, 输出第二个字符串在第一个字符串中的连接次序。即输出 125, 126, 145, 146.
- 输出第二个字符串在第一个字符串中的链接次序
- 《程序员面试宝典》求取第二个字符串在第一个字符串中的连接次序---递归算法
- C语言:从键盘输入两个字符串,输出第一个字符串在第二个字符串中的位置
- js 输入两个字符串,从第一个字符串中删除第二个字符串中的所有字符串
- 输入两个字符串,比如abdbcc和abc,把abc在abdbcc中的连接次序输出
- 输入两个字符串,从第一个字符串中,删除第二字字符串中的所有字符。
- javac和java指令理解
- 正则表达式匹配字符串中的数值部分并将其返回
- JS删除数组元素
- 25个让人惊叹的 HTML5 应用实验
- Fikker防盗链原理与实现 - 不改动任何网站程序
- 输入两个字符串,输出第二个字符串在第一个字符串中的连接次序
- js获取url参数
- ksh中包含变量的命令调用
- (转载)算法复杂度分析
- Linux下静态库和动态库(共享库)的制作与使用
- Java学习笔记6:输出九九乘法口诀
- 在一个程序启动另一个程序的Activity
- JTree
- VMware中打造最小Linux系统(一)——构建内核&文件系统