给定序列数中子序列的最大值。 [英] max value of a subsequence in a given sequnce of numbers.

查看:94
本文介绍了给定序列数中子序列的最大值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个程序中,他们希望我找到

a中子序列的最大值,给定序号(序列由数组表示)

使用模板和pointers.also我必须写一个主要,以便

实例化我班级的不同对象。在这个程序中我不想要

来查找总和!!!!请有人帮帮我吗?

解决方案

begum写道:


在这个程序中,他们希望我使用模板和指针,通过

给出数字序列(序列由数组表示),找到

a中子序列的最大值。我也必须写一个主要的,以便
实例化我班级的不同对象。在这个程序中我不想要

来查找总和!!!!请任何人可以帮助我吗?



发布你到目前为止所做的事情,我们可以提供帮助。

此致,


Peter Jansson
http://www.p-jansson .com /
http://www.jansson.net/





10月7日凌晨4:45,begum < begums ... @ gmail.comwrote:


在这个程序中他们希望我找到一个子序列的最大值

a使用模板和指针给出数字的序列(序列由数组表示)

.also我必须写一个main来为

实例化我班级的不同对象。在这个程序中我不想要

来查找总和!!!!请有人帮帮我吗?



真的吗?哇。所以......你有一个阵列?让我们看看吧。

向我们展示阵列,根据需要填充它,然后将它们的元素打印到屏幕上。

不需要模板,不需要指针,不需要最大值。只需

输出数组。

让我们面对它,如果你不能这样做,你将如何操纵它的

内容以任何方式?

嗯?

http://www.parashift.com/c++-faq-lite/how-to-post.html


begum写道:


在这个程序中他们希望我找到一个子序列的最大值

a使用模板和指针给出数字的序列(序列由数组表示)

.also我必须写一个main来为

实例化我班级的不同对象。在这个程序中我不想要

来查找总和!!!!请有人帮帮我吗?



标题< algorithmprovides一个通用函数:


模板< class RandomAccessIterator>

void nth_element(RandomAccessIterator first,

RandomAccessIterator nth,

RandomAccessIterator last);


使用std :: less,但你可以还提供了你自己的比较谓词:


模板< class RandomAccessIterator,类比较>

void nth_element(RandomAccessIterator first,

RandomAccessIterator nth,

RandomAccessIterator last,

比较comp);


所以,为了找到一个范围内的最小值[从,到],你会这样做:


nth_element(from,from,to);

minimum = * from;


你可以改变它来找到最大值。


警告:此算法重新排列序列。确保你允许这样做。

最好


Kai-Uwe Bux


in this program they want me to find the max value of a subsequence in
a given sequnce of numbers(the sequence is represented by an array) by
using templates and pointers.also i must write a main in order to
instantiate differnt objects of my class. in this program i don''t want
to find the sum!!!!. please can anyone help me?

解决方案

begum wrote:

in this program they want me to find the max value of a subsequence in
a given sequnce of numbers(the sequence is represented by an array) by
using templates and pointers.also i must write a main in order to
instantiate differnt objects of my class. in this program i don''t want
to find the sum!!!!. please can anyone help me?

Post what you have done so far and we may help.
Sincerely,

Peter Jansson
http://www.p-jansson.com/
http://www.jansson.net/




On Oct 7, 4:45 am, "begum" <begums...@gmail.comwrote:

in this program they want me to find the max value of a subsequence in
a given sequnce of numbers(the sequence is represented by an array) by
using templates and pointers.also i must write a main in order to
instantiate differnt objects of my class. in this program i don''t want
to find the sum!!!!. please can anyone help me?

Really? Wow. So like... you have an array? Lets see it.
Show us the array, populate it as required and then print its elements
to the screen.
No templates needed, no pointers needed, no max value needed. Just
output the array.
Lets face it, if you can''t do that, how are you going to manipulate its
contents in any way?
hmm?

http://www.parashift.com/c++-faq-lite/how-to-post.html


begum wrote:

in this program they want me to find the max value of a subsequence in
a given sequnce of numbers(the sequence is represented by an array) by
using templates and pointers.also i must write a main in order to
instantiate differnt objects of my class. in this program i don''t want
to find the sum!!!!. please can anyone help me?

The header <algorithmprovides a generic function:

template<class RandomAccessIterator>
void nth_element(RandomAccessIterator first,
RandomAccessIterator nth,
RandomAccessIterator last);

using std::less, but you can also supply a comparison predicate of your own:

template<class RandomAccessIterator, class Compare>
void nth_element(RandomAccessIterator first,
RandomAccessIterator nth,
RandomAccessIterator last,
Compare comp);

So, in order to find the minimum in a range [from,to), you would do:

nth_element( from, from, to );
minimum = *from;

You can vary this to find the maximum instead.

Warning: this algorithm rearranges the sequence. Make sure that you are
allowed to do that.
Best

Kai-Uwe Bux


这篇关于给定序列数中子序列的最大值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆