#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
const double percent = 5.023;
long double fn(const long double &one,const long double &two)
{
return ((one + two) / 100) * percent;
}
int main()
{
vector<long double> v;
for(int i=0;i<=10000;++i)
{
v.push_back(i);
}
sort(v.begin(),v.end());
partial_sum(v.begin(), v.end(), v.begin(),fn);
long double sum = std::accumulate(v.begin(), v.end(), 0);
cout<<sum<<endl; //2.63956e+06
return 0;
}
#include <iostream>
#include <numeric>
#include <set>
#include <algorithm>
#include <iterator>
using namespace std;
const double percent = 5.023;
typedef long double ddouble;
typedef multiset<ddouble> DblSet;
int main() {
int size = 10;
ddouble *d = new ddouble[size];
for(int i=0;i<size;++i)
{
d[i]=i;
}
DblSet myset(d,d+size);
ostream_iterator<ddouble> output( cout, " ");
while(myset.size()!=1)
{
ddouble a = *myset.begin();
myset.erase(myset.begin());
ddouble b = *myset.begin();
myset.erase(myset.begin());
myset.insert(myset.begin(),((a+b)/100)*percent);
}
copy(myset.begin(),myset.end(),output);
delete d;
return 0;
}
C++ жестче округляет значения
#include <iostream>
void printArray(const int * array, size_t len)
{
std::cout << "[ ";
for(size_t i = 0; i < len; ++i)
std::cout << array[i] << (i == len - 1 ? "" : ", ");
std::cout << " ]" << std::endl;
}
void _reverseArray(int * first, int *last)
{
int tmp = *first;
*first = *last;
*last = tmp;
if(first < last)
_reverseArray(first + 1, last - 1);
}
void reverseArray(int * ptr, size_t len)
{
_reverseArray(ptr, ptr + len - 1);
}
int main() {
int array[] = { 1, 2, 3, 4, 5, 6 };
size_t len = sizeof(array) / sizeof(int);
printArray(array, len);
reverseArray(array, len);
printArray(array, len);
return 0;
}
def subsets(seq):
for k in range(len(seq) + 1):
yield from subsets_k(seq, k)
def subsets_k(seq, k):
if k == 0:
yield []
else:
for i in range(len(seq) - k + 1):
for subset in subsets_k(seq[i+1:], k-1):
yield [seq[i]] + subset
print(list(subsets([1, 2, 3, 4, 5])))
class figura():
def __init__(self, x, y, colour):
self.x = x
self.y = y
self.colour = colour
class pewka(figura):
def __init__(self, x, y, colour):
super().__init__(x, y, colour)
self.type = "pewka"
class ladja(figura):
def __init__(self, x, y, colour):
super().__init__(x, y, colour)
self.type = "ladja"
fig1 = pewka('a', 1, 'red')
fig2 = ladja('a', 1, 'red')
if any_fig.colour = 'red':
...
CELL_WIDTH = CELL_HEIGHT = 75
for p in [(x, y) for x in range(CELL_WIDTH, 610, CELL_WIDTH) for y in range(CELL_HEIGHT, 610, CELL_HEIGHT)]:
if (p[0] + p[1] ) % 2 == 0:
pygame.draw.rect(DISPLAY, WHITE_CELL, [X, Y, CELL_WIDTH, CELL_HEIGHT])
else:
pygame.draw.rect(DISPLAY, BLACK_CELL, [X, Y, CELL_WIDTH, CELL_HEIGHT])
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
if (X+75,Y) > event.pos > (X, Y):
print(X,Y)
while True:
str = input()
if str:
a.append(int(str))
else:
break