65,211
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <stddef.h>
#include <stdlib.h>
#include <string>
#include <iterator>
#include <algorithm>
#include <vector>
using namespace std;
template <typename InputIterator1, typename InputIterator2, typename OutputIterator>
OutputIterator delete_intersection(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2, OutputIterator dest)
{
while (first1 != last1 && first2 != last2) {
if (*first1 > *first2) {
*dest = *first2;
++first2;
++dest;
} else if (*first1 < *first2) {
*dest = *first1;
++first1;
++dest;
} else {
++first1;
++first2;
}
}
// for (;first1 != last1; ++first1) *dest = *first1;
for (;first2 != last2; ++first2) *dest = *first2;
return dest;
}
int main() {
int a[] = {1,1,2,2,5,6,9,9};
int b[] = {1,2,3,4,4,6,7,8,9,9,9,10};
vector<int> vc;
delete_intersection(a, a + sizeof(a)/sizeof(a[0]), b, b + sizeof(b)/sizeof(b[0]), back_inserter(vc));
std::copy(a, a + sizeof(a)/sizeof(a[0]), ostream_iterator<int>(cout, ",")); cout << endl;
std::copy(b, b + sizeof(b)/sizeof(b[0]), ostream_iterator<int>(cout, ",")); cout << endl;
std::copy(vc.begin(), vc.end(), ostream_iterator<int>(cout, ",")); cout << endl;
::system("PAUSE");
return EXIT_SUCCESS;
}
#include <iostream>
using namespace std;
class strout
{
public:
strout(string s1)
{
cout <<s1<<endl;
}
void show()
{
}
};
int main()
{
string s = "代码请用插入工具!";
strout so(s);
int a[] = {1,1,2,2,5,6,9,9};
int b[] = {1,2,3,4,4,6,7,8,9,9,9,10};
int c[20] = {0};
int x = sizeof(a)/sizeof(a[0]);
int y = sizeof(b)/sizeof(b[0]);
int i = x - y;
if(i>=0)
{
strout so("a>=b");
// 省略看下面
}
else
{
strout so("a<b");
// 求交集
for(int i = 0;i<x;i++)
for(int j=0;j<y;j++)
{
if (a[i] == b[j])
{
c[i] = a[i];
}
}
}
// 交集中 去掉重复项,这里 置‘0’
for (int i=0;i< 19;i++)
{
for(int j =i+1;j<19;j++)
{
if (c[i]==c[j])
{
c[j]=0;
}
}
}
// 无关紧要
for (int i=0;i<20;i++)
{
cout<<c[i]<< "";
}
cout <<endl;
// 判断交集元素的个数,对个数多的数组置‘0’;
for (int i=0;i<20;i++)
{
// 过滤 C数组中的零
if(c[i]==0)
continue;
int ai = 0;
int bi = 0;
cout<<"c[i]="<<c[i]<<endl;
for (int j =0;j<x;j++)
{
if ((c[i]==a[j])&&(c[i]!=0))
{
ai ++;
}
}
cout<<"ai="<<ai<<endl;
for (int j =0;j<y;j++)
{
if ((c[i]==b[j])&&(c[i]!=0))
{
bi++;
}
}
cout<<"bi="<<bi<<endl;
if (ai>bi)
{
for (int j =0;j<x;j++)
{
if ((c[i]==a[j])&&(c[i]!=0))
{
a[j]=0;
}
}
}
if((ai<bi)&&(c[i]!=0))
{
for (int j =0;j<y;j++)
{
if ((c[i]==b[j])&&(c[i]!=0))
{
b[j]=0;
}
}
}
}
for (int i=0;i<x;i++)
{
cout<<a[i]<< "";
}
cout <<endl;
for (int i=0;i<y;i++)
{
cout<<b[i]<< "";
}
return 0;
}
#include <iostream>
using namespace std;
class strout
{
public:
strout(string s1)
{
cout <<s1<<endl;
}
};
int main()
{
string s = "发布代码请使用代码插入工具!\n 谢谢!";
strout so(s);
return 0;
}
#include <iostream>
#include <stddef.h>
#include <stdlib.h>
#include <string>
#include <iterator>
#include <algorithm>
#include <vector>
using namespace std;
template <typename InputIterator1, typename InputIterator2, typename OutputIterator>
OutputIterator delete_intersection(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2, OutputIterator dest)
{
int count = 0;
while (first1 != last1 && first2 != last2) {
if (*first1 > *first2) {
*dest = *first2;
++first2;
++dest;
} else if (*first1 < *first2) {
*dest = *first1;
++first1;
++dest;
} else {
++first1;
++first2;
}
}
for (;first1 != last1; ++first1) *dest = *first1;
for (;first2 != last2; ++first2) *dest = *first2;
return dest;
}
int main() {
int a[] = {1,1,2,2,5,6,9,9};
int b[] = {1,2,3,4,4,6,7,8,9,9,9,10};
vector<int> vc;
delete_intersection(a, a + sizeof(a)/sizeof(a[0]), b, b + sizeof(b)/sizeof(b[0]), back_inserter(vc));
std::copy(a, a + sizeof(a)/sizeof(a[0]), ostream_iterator<int>(cout, ",")); cout << endl;
std::copy(b, b + sizeof(b)/sizeof(b[0]), ostream_iterator<int>(cout, ",")); cout << endl;
std::copy(vc.begin(), vc.end(), ostream_iterator<int>(cout, ",")); cout << endl;
::system("PAUSE");
return EXIT_SUCCESS;
}