@ForEveR
В астрале
7989 / 4748 / 321
Регистрация: 24.06.2010
Сообщений: 10,547
|
04.01.2011, 17:31
|
|
В порядке общего бреда...
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
| #include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <functional>
template<class Iter, class Comp>
Iter find_min_pos(Iter first, Iter last, Comp cmp)
{
Iter found=first;
if(first != last)
{
while(++first != last)
{
if(*found < 0)
found=first;
if(cmp(*first, *found))
{
found=first;
}
}
}
return found;
}
int main()
{
std::vector<int> Vec((std::istream_iterator<int>(std::cin)),
std::istream_iterator<int>());
int cnt=0;
std::vector<int>::iterator min=find_min_pos(Vec.begin(), Vec.end(), [&cnt](int x, int y) -> bool
{
if (x > 0 && y > 0)
{
++cnt;
return x < y;
}
return false;
});
if(cnt)
{
std::cout<<"Minimum is: "<<*min<<'\n';
std::sort(min+1, Vec.end(), std::greater<int>());
std::copy(Vec.begin(), Vec.end(), std::ostream_iterator<int>(std::cout, " "));
}
else
{
std::cout<<"All elements are negative\n";
system("pause");
return 1;
}
system("pause");
return 0;
} |
|
0
|