#include <stdio.h>;
#include <iostream>;
#include <cstdlib>;
#include <stdlib.h>
#include <fstream>;
#include <conio.h>;
using namespace std;
struct vec { int x, y; };
vec A[1000];
int B[1000];
int C[1000];
vec ez(int a, int b)
{
vec result;
result.x = 0;
result.y = 0;
for (int i = b; i >= a; i--) {
result.x = result.x + A[i].x;
result.y = result.y + A[i].y; /*под вопросом*/
}
return result;
}
vec hard(int* B, int* C, int a, int b)
{
vec result;
B[0] = 0;
C[0] = 0;
int resultx = 0;
int resulty = 0;
for (int i = 1; i <= 1000; ++i) {
B[i] = B[i - 1] + A[i - 1].x;
C[i] = C[i - 1] + A[i - 1].y;
}
for (int i = a; i <= b; ++i)
{
resultx = B[b + 1] - B[a];
resulty = C[b + 1] - C[a];
}
result.x = resultx;
result.y = resulty;
return result;
}
/*получаем массив векторов*/
int main()
{
FILE *file;
file = fopen("E:\\file.txt", "w");
for (int i = 0; i<1000; i++) {
A[i].x = rand() % 100 + 1;
A[i].y = rand() % 100 + 1;
};
for (int i = 0; i<1; i++)
{
int a = rand() % 100 + 1;
int b = rand() % 100 + 1;
if (a > b) {
int tmp_b = b;
b = a;
a = tmp_b;
}
fprintf (file,"%s %s \n", ez(a, b));
fprintf(file, "%s %s \n", hard(B, C, a, b));
}
return 0;
}