大数组:int ArrayB[] = {99, 88,1, 2, 3, 4, 5, 99,88 6, 7, 8, 9, 0, 99,97} ;
小数组:int ArrayL[] = {99, 88} ;
如何
得到: int ArrayT[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 99,97} ;
11 个解决方案
#1
不知道有什么好的算法,最普通的吧,两个for循环嵌套好了
#2
对速度要求很高,应用到过滤一个大语音文件中包含的某些语音。
#3
只做一次还是要频繁重复呀?
如果是后者,需要生成新数组。
如果是后者,需要生成新数组。
#4
只做一次还是要频繁重复呀?
如果是后者,需要生成新数组。
如果是后者,需要生成新数组。
#5
这个不知道能不能满足你要求
//
// set_s_di.cpp
//
#include<algorithm>
#include<set>
#include <istream.h>
using namespace std;
int main()
{
//Initialize some sets
int a1[] = {1,3,5,7,9,11};
int a3[] = {3,5,7,8};
set<int, less<int> > odd(a1+0,a1+6), result,
small(a3+0,a3+4);
//Create an insert_iterator for result
insert_iterator<set<int, less<int> > >
res_ins(result, result.begin());
//Demonstrate set_symmetric_difference
cout << "The symmetric difference of:" << endl << "{";
copy(small.begin(),small.end(),
ostream_iterator<int,char>(cout," "));
cout << "} with {";
copy(odd.begin(),odd.end(),
ostream_iterator<int,char>(cout," "));
cout << "} =" << endl << "{";
set_symmetric_difference(small.begin(), small.end(),
odd.begin(), odd.end(), res_ins);
copy(result.begin(),result.end(),
ostream_iterator<int,char>(cout," "));
cout << "}" << endl << endl;
return 0;
}
Program Output
The symmetric difference of:
{3 5 7 8 } with {1 3 5 7 9 11 } =
{1 8 9 11 }
//
// set_s_di.cpp
//
#include<algorithm>
#include<set>
#include <istream.h>
using namespace std;
int main()
{
//Initialize some sets
int a1[] = {1,3,5,7,9,11};
int a3[] = {3,5,7,8};
set<int, less<int> > odd(a1+0,a1+6), result,
small(a3+0,a3+4);
//Create an insert_iterator for result
insert_iterator<set<int, less<int> > >
res_ins(result, result.begin());
//Demonstrate set_symmetric_difference
cout << "The symmetric difference of:" << endl << "{";
copy(small.begin(),small.end(),
ostream_iterator<int,char>(cout," "));
cout << "} with {";
copy(odd.begin(),odd.end(),
ostream_iterator<int,char>(cout," "));
cout << "} =" << endl << "{";
set_symmetric_difference(small.begin(), small.end(),
odd.begin(), odd.end(), res_ins);
copy(result.begin(),result.end(),
ostream_iterator<int,char>(cout," "));
cout << "}" << endl << endl;
return 0;
}
Program Output
The symmetric difference of:
{3 5 7 8 } with {1 3 5 7 9 11 } =
{1 8 9 11 }
#6
//我程序中的定义如下,主要是想找到一个更为快速的方法
//类似Replace("你好中国你好", "你好", "")
//但并非Replace那样简单,不是替换字符串
//已知大vector 包含语音数据----"你好中国你好"
vector <UCHAR> vecDemoData ;
//已知小vector 包含语音数据----"你好"
vector <UCHAR> vecMakeData ;
//求vector 需要生成包含语音数据----"中国"
vector <UCHAR> vecTempData ;
//类似Replace("你好中国你好", "你好", "")
//但并非Replace那样简单,不是替换字符串
//已知大vector 包含语音数据----"你好中国你好"
vector <UCHAR> vecDemoData ;
//已知小vector 包含语音数据----"你好"
vector <UCHAR> vecMakeData ;
//求vector 需要生成包含语音数据----"中国"
vector <UCHAR> vecTempData ;
#7
//下面是我在C#中的实现,但现在我想用C++实现
//------------------------------------------------------------------------
// 语音合成处理函数
public static string TextToSpeech(string VocText)
{
//初始化
...
//变量
string strDemo = "你好" ;
string strMake = "你好中国你好" ;
string wavDemo = Application.StartupPath + "\\Demo.wav" ;
string wavMake = Application.StartupPath + "\\Make.wav" ;
string wavFinal = Application.StartupPath + "\\Final.wav" ;
//删除临时文件
...
//生成演示语音
TxtToWav(strDemo, wavDemo) ;
//生成合成语音
TxtToWav(strMake, wavMake) ;
//演示语音
FileStream fsDemo = new FileStream(wavDemo, FileMode.Open) ;
BinaryReader brDemo = new BinaryReader(fsDemo) ;
byte[] ByteArrayTitle = new byte[44] ;
fsDemo.Seek(0, SeekOrigin.Current) ;
ByteArrayTitle = brDemo.ReadBytes(44) ;
int LengthDemo = (int)fsDemo.Length - 44 ;
byte[] ByteArrayDemo = new byte[LengthDemo] ;
fsDemo.Seek(44, SeekOrigin.Current) ;
ByteArrayDemo = brDemo.ReadBytes((int)fsDemo.Length - 44) ;
fsDemo.Close() ;
//生成语音
FileStream fsMake = new FileStream(wavMake, FileMode.Open) ;
BinaryReader brMake = new BinaryReader(fsMake) ;
int LengthMake = (int)fsMake.Length - 44 ;
byte[] ByteArrayMake = new byte[LengthMake] ;
fsMake.Seek(44, SeekOrigin.Current) ;
ByteArrayMake = brMake.ReadBytes((int)fsMake.Length - 44) ;
fsMake.Close() ;
//以字符串形式替换生成语音中的部分语音
string tmpDemo = Encoding.Unicode.GetString(ByteArrayDemo) ;
string tmpMake = Encoding.Unicode.GetString(ByteArrayMake) ;
string strFinal = tmpMake.Replace(tmpDemo, "") ;
//最终语音
FileStream fsFinal = new FileStream(wavFinal, FileMode.Create) ;
BinaryWriter bwValue = new BinaryWriter(fsFinal) ;
//00-03
fsFinal.Write(ByteArrayTitle, 0, 4) ;
//04-07
bwValue.Write(strFinal.Length * 2 + 36) ; //08-39
fsFinal.Write(ByteArrayTitle, 8, 32) ; //40-43
bwValue.Write(strFinal.Length * 2) ;
//Vioce Data
byte[] ByteArrayFinal = Encoding.Unicode.GetBytes(strFinal) ;
//44-->
fsFinal.Write(ByteArrayFinal, 0, ByteArrayFinal.Length) ; fsFinal.Close() ;
//结束
...
return wavFinal ;
}
//------------------------------------------------------------------------
// 语音合成处理函数
public static string TextToSpeech(string VocText)
{
//初始化
...
//变量
string strDemo = "你好" ;
string strMake = "你好中国你好" ;
string wavDemo = Application.StartupPath + "\\Demo.wav" ;
string wavMake = Application.StartupPath + "\\Make.wav" ;
string wavFinal = Application.StartupPath + "\\Final.wav" ;
//删除临时文件
...
//生成演示语音
TxtToWav(strDemo, wavDemo) ;
//生成合成语音
TxtToWav(strMake, wavMake) ;
//演示语音
FileStream fsDemo = new FileStream(wavDemo, FileMode.Open) ;
BinaryReader brDemo = new BinaryReader(fsDemo) ;
byte[] ByteArrayTitle = new byte[44] ;
fsDemo.Seek(0, SeekOrigin.Current) ;
ByteArrayTitle = brDemo.ReadBytes(44) ;
int LengthDemo = (int)fsDemo.Length - 44 ;
byte[] ByteArrayDemo = new byte[LengthDemo] ;
fsDemo.Seek(44, SeekOrigin.Current) ;
ByteArrayDemo = brDemo.ReadBytes((int)fsDemo.Length - 44) ;
fsDemo.Close() ;
//生成语音
FileStream fsMake = new FileStream(wavMake, FileMode.Open) ;
BinaryReader brMake = new BinaryReader(fsMake) ;
int LengthMake = (int)fsMake.Length - 44 ;
byte[] ByteArrayMake = new byte[LengthMake] ;
fsMake.Seek(44, SeekOrigin.Current) ;
ByteArrayMake = brMake.ReadBytes((int)fsMake.Length - 44) ;
fsMake.Close() ;
//以字符串形式替换生成语音中的部分语音
string tmpDemo = Encoding.Unicode.GetString(ByteArrayDemo) ;
string tmpMake = Encoding.Unicode.GetString(ByteArrayMake) ;
string strFinal = tmpMake.Replace(tmpDemo, "") ;
//最终语音
FileStream fsFinal = new FileStream(wavFinal, FileMode.Create) ;
BinaryWriter bwValue = new BinaryWriter(fsFinal) ;
//00-03
fsFinal.Write(ByteArrayTitle, 0, 4) ;
//04-07
bwValue.Write(strFinal.Length * 2 + 36) ; //08-39
fsFinal.Write(ByteArrayTitle, 8, 32) ; //40-43
bwValue.Write(strFinal.Length * 2) ;
//Vioce Data
byte[] ByteArrayFinal = Encoding.Unicode.GetBytes(strFinal) ;
//44-->
fsFinal.Write(ByteArrayFinal, 0, ByteArrayFinal.Length) ; fsFinal.Close() ;
//结束
...
return wavFinal ;
}
#8
用集合最好,在STL有中有集合及集合的相关操作算法!
#9
集合是不错,不过速度就不知道了
#10
对于这个问题,首先将小数组的数据作自相关,得到时差为0是的自相关值,以你的例子为例,小数组的0时差自相关值为(99×99+88×88) = 17545,再把小数组和大数组作互相关,得到一系列的数值,相关值为17545的对应位置就是和小数组一样的了,这就是一个比较简单的模式识别问题。
#11
copy(ArrayB,ArrayB+sizeof(ArrayB)/sizeof(int),ArrayA+sizeof(ArrayA)/sizeof(int));
unique_copy(ArrayA,ArrayA+sizeof(ArrayA)/sizeof(int),ArrayT);
unique_copy(ArrayA,ArrayA+sizeof(ArrayA)/sizeof(int),ArrayT);
#1
不知道有什么好的算法,最普通的吧,两个for循环嵌套好了
#2
对速度要求很高,应用到过滤一个大语音文件中包含的某些语音。
#3
只做一次还是要频繁重复呀?
如果是后者,需要生成新数组。
如果是后者,需要生成新数组。
#4
只做一次还是要频繁重复呀?
如果是后者,需要生成新数组。
如果是后者,需要生成新数组。
#5
这个不知道能不能满足你要求
//
// set_s_di.cpp
//
#include<algorithm>
#include<set>
#include <istream.h>
using namespace std;
int main()
{
//Initialize some sets
int a1[] = {1,3,5,7,9,11};
int a3[] = {3,5,7,8};
set<int, less<int> > odd(a1+0,a1+6), result,
small(a3+0,a3+4);
//Create an insert_iterator for result
insert_iterator<set<int, less<int> > >
res_ins(result, result.begin());
//Demonstrate set_symmetric_difference
cout << "The symmetric difference of:" << endl << "{";
copy(small.begin(),small.end(),
ostream_iterator<int,char>(cout," "));
cout << "} with {";
copy(odd.begin(),odd.end(),
ostream_iterator<int,char>(cout," "));
cout << "} =" << endl << "{";
set_symmetric_difference(small.begin(), small.end(),
odd.begin(), odd.end(), res_ins);
copy(result.begin(),result.end(),
ostream_iterator<int,char>(cout," "));
cout << "}" << endl << endl;
return 0;
}
Program Output
The symmetric difference of:
{3 5 7 8 } with {1 3 5 7 9 11 } =
{1 8 9 11 }
//
// set_s_di.cpp
//
#include<algorithm>
#include<set>
#include <istream.h>
using namespace std;
int main()
{
//Initialize some sets
int a1[] = {1,3,5,7,9,11};
int a3[] = {3,5,7,8};
set<int, less<int> > odd(a1+0,a1+6), result,
small(a3+0,a3+4);
//Create an insert_iterator for result
insert_iterator<set<int, less<int> > >
res_ins(result, result.begin());
//Demonstrate set_symmetric_difference
cout << "The symmetric difference of:" << endl << "{";
copy(small.begin(),small.end(),
ostream_iterator<int,char>(cout," "));
cout << "} with {";
copy(odd.begin(),odd.end(),
ostream_iterator<int,char>(cout," "));
cout << "} =" << endl << "{";
set_symmetric_difference(small.begin(), small.end(),
odd.begin(), odd.end(), res_ins);
copy(result.begin(),result.end(),
ostream_iterator<int,char>(cout," "));
cout << "}" << endl << endl;
return 0;
}
Program Output
The symmetric difference of:
{3 5 7 8 } with {1 3 5 7 9 11 } =
{1 8 9 11 }
#6
//我程序中的定义如下,主要是想找到一个更为快速的方法
//类似Replace("你好中国你好", "你好", "")
//但并非Replace那样简单,不是替换字符串
//已知大vector 包含语音数据----"你好中国你好"
vector <UCHAR> vecDemoData ;
//已知小vector 包含语音数据----"你好"
vector <UCHAR> vecMakeData ;
//求vector 需要生成包含语音数据----"中国"
vector <UCHAR> vecTempData ;
//类似Replace("你好中国你好", "你好", "")
//但并非Replace那样简单,不是替换字符串
//已知大vector 包含语音数据----"你好中国你好"
vector <UCHAR> vecDemoData ;
//已知小vector 包含语音数据----"你好"
vector <UCHAR> vecMakeData ;
//求vector 需要生成包含语音数据----"中国"
vector <UCHAR> vecTempData ;
#7
//下面是我在C#中的实现,但现在我想用C++实现
//------------------------------------------------------------------------
// 语音合成处理函数
public static string TextToSpeech(string VocText)
{
//初始化
...
//变量
string strDemo = "你好" ;
string strMake = "你好中国你好" ;
string wavDemo = Application.StartupPath + "\\Demo.wav" ;
string wavMake = Application.StartupPath + "\\Make.wav" ;
string wavFinal = Application.StartupPath + "\\Final.wav" ;
//删除临时文件
...
//生成演示语音
TxtToWav(strDemo, wavDemo) ;
//生成合成语音
TxtToWav(strMake, wavMake) ;
//演示语音
FileStream fsDemo = new FileStream(wavDemo, FileMode.Open) ;
BinaryReader brDemo = new BinaryReader(fsDemo) ;
byte[] ByteArrayTitle = new byte[44] ;
fsDemo.Seek(0, SeekOrigin.Current) ;
ByteArrayTitle = brDemo.ReadBytes(44) ;
int LengthDemo = (int)fsDemo.Length - 44 ;
byte[] ByteArrayDemo = new byte[LengthDemo] ;
fsDemo.Seek(44, SeekOrigin.Current) ;
ByteArrayDemo = brDemo.ReadBytes((int)fsDemo.Length - 44) ;
fsDemo.Close() ;
//生成语音
FileStream fsMake = new FileStream(wavMake, FileMode.Open) ;
BinaryReader brMake = new BinaryReader(fsMake) ;
int LengthMake = (int)fsMake.Length - 44 ;
byte[] ByteArrayMake = new byte[LengthMake] ;
fsMake.Seek(44, SeekOrigin.Current) ;
ByteArrayMake = brMake.ReadBytes((int)fsMake.Length - 44) ;
fsMake.Close() ;
//以字符串形式替换生成语音中的部分语音
string tmpDemo = Encoding.Unicode.GetString(ByteArrayDemo) ;
string tmpMake = Encoding.Unicode.GetString(ByteArrayMake) ;
string strFinal = tmpMake.Replace(tmpDemo, "") ;
//最终语音
FileStream fsFinal = new FileStream(wavFinal, FileMode.Create) ;
BinaryWriter bwValue = new BinaryWriter(fsFinal) ;
//00-03
fsFinal.Write(ByteArrayTitle, 0, 4) ;
//04-07
bwValue.Write(strFinal.Length * 2 + 36) ; //08-39
fsFinal.Write(ByteArrayTitle, 8, 32) ; //40-43
bwValue.Write(strFinal.Length * 2) ;
//Vioce Data
byte[] ByteArrayFinal = Encoding.Unicode.GetBytes(strFinal) ;
//44-->
fsFinal.Write(ByteArrayFinal, 0, ByteArrayFinal.Length) ; fsFinal.Close() ;
//结束
...
return wavFinal ;
}
//------------------------------------------------------------------------
// 语音合成处理函数
public static string TextToSpeech(string VocText)
{
//初始化
...
//变量
string strDemo = "你好" ;
string strMake = "你好中国你好" ;
string wavDemo = Application.StartupPath + "\\Demo.wav" ;
string wavMake = Application.StartupPath + "\\Make.wav" ;
string wavFinal = Application.StartupPath + "\\Final.wav" ;
//删除临时文件
...
//生成演示语音
TxtToWav(strDemo, wavDemo) ;
//生成合成语音
TxtToWav(strMake, wavMake) ;
//演示语音
FileStream fsDemo = new FileStream(wavDemo, FileMode.Open) ;
BinaryReader brDemo = new BinaryReader(fsDemo) ;
byte[] ByteArrayTitle = new byte[44] ;
fsDemo.Seek(0, SeekOrigin.Current) ;
ByteArrayTitle = brDemo.ReadBytes(44) ;
int LengthDemo = (int)fsDemo.Length - 44 ;
byte[] ByteArrayDemo = new byte[LengthDemo] ;
fsDemo.Seek(44, SeekOrigin.Current) ;
ByteArrayDemo = brDemo.ReadBytes((int)fsDemo.Length - 44) ;
fsDemo.Close() ;
//生成语音
FileStream fsMake = new FileStream(wavMake, FileMode.Open) ;
BinaryReader brMake = new BinaryReader(fsMake) ;
int LengthMake = (int)fsMake.Length - 44 ;
byte[] ByteArrayMake = new byte[LengthMake] ;
fsMake.Seek(44, SeekOrigin.Current) ;
ByteArrayMake = brMake.ReadBytes((int)fsMake.Length - 44) ;
fsMake.Close() ;
//以字符串形式替换生成语音中的部分语音
string tmpDemo = Encoding.Unicode.GetString(ByteArrayDemo) ;
string tmpMake = Encoding.Unicode.GetString(ByteArrayMake) ;
string strFinal = tmpMake.Replace(tmpDemo, "") ;
//最终语音
FileStream fsFinal = new FileStream(wavFinal, FileMode.Create) ;
BinaryWriter bwValue = new BinaryWriter(fsFinal) ;
//00-03
fsFinal.Write(ByteArrayTitle, 0, 4) ;
//04-07
bwValue.Write(strFinal.Length * 2 + 36) ; //08-39
fsFinal.Write(ByteArrayTitle, 8, 32) ; //40-43
bwValue.Write(strFinal.Length * 2) ;
//Vioce Data
byte[] ByteArrayFinal = Encoding.Unicode.GetBytes(strFinal) ;
//44-->
fsFinal.Write(ByteArrayFinal, 0, ByteArrayFinal.Length) ; fsFinal.Close() ;
//结束
...
return wavFinal ;
}
#8
用集合最好,在STL有中有集合及集合的相关操作算法!
#9
集合是不错,不过速度就不知道了
#10
对于这个问题,首先将小数组的数据作自相关,得到时差为0是的自相关值,以你的例子为例,小数组的0时差自相关值为(99×99+88×88) = 17545,再把小数组和大数组作互相关,得到一系列的数值,相关值为17545的对应位置就是和小数组一样的了,这就是一个比较简单的模式识别问题。
#11
copy(ArrayB,ArrayB+sizeof(ArrayB)/sizeof(int),ArrayA+sizeof(ArrayA)/sizeof(int));
unique_copy(ArrayA,ArrayA+sizeof(ArrayA)/sizeof(int),ArrayT);
unique_copy(ArrayA,ArrayA+sizeof(ArrayA)/sizeof(int),ArrayT);