对于我写的一个有趣的程序(为你找到最高的公共因子和最低的公共倍数);我遇到了一些困难。
我有两个包含14个数字的数组。为了找到所有数字的最小公倍数,我需要比较每个数组中的每个元素。到目前为止,我已经得到了这个测试:
for(int i = 0; i < C_I_14; i++)
{
for(int j = 0; j < C_I_14; j++)
{
if(array[i] == arr[j])
{
tesst[i] = array[i];
}
}
}
(其中C_I_14 = 14)
问题是,有无数的东西可能会出错: tessti = arrayi
那么,有人能帮我整理一下我的小算法吗?
发布于 2011-11-30 20:05:19
对每个输入数组进行排序,然后使用std::set_intersection获取交集。
发布于 2011-11-30 20:12:19
- [`std::mismatch`](http://www.sgi.com/tech/stl/mismatch.html)
- [`std::lexicographical_compare`](http://www.sgi.com/tech/stl/lexicographical_compare.html)
非常有用
- [`std::sort`](http://www.sgi.com/tech/stl/sort.html) (!! important) followed by
- [`std::set_intersection`](http://www.sgi.com/tech/stl/set_intersection.html)
https://stackoverflow.com/questions/8332167
复制相似问题