1. Задан массив D. Определить следующие суммы: D[1] + D[2] + D[3]; D[3] +D[4] +D[5]; D[4] + D[5] + D[6], используя подпрограмму для вычисления суммы трех последовательно расположенных элементов массива.
Answers & Comments
DmitryCpp#include <iostream> #include <sstream> #include <fstream> #include <string> #include <vector> #include <deque> #include <queue> #include <stack> #include <set> #include <map> #include <algorithm> #include <functional> #include <cstring> #include <utility> #include <bitset> #include <cmath> #include <cstdlib> #include <ctime> #include <cstdio> #include <climits>typedef unsigned long long ulol; typedef long long lol; typedef long int li;#define mp make_pair #define F first #define S second #define sqr(a) ( (a) * (a) ) #define pb push_back #define INF 999999999 #define ret(a) cout << endl; system("pause"); return(a) //#define ret(a) return(a)using namespace std;int main() { lol n; cin >> n; vector<lol> ar(n); for(int i = 0 ; i < n ; i ++) cin >> ar[i]; for(int i = 0 ; i < n ; i += 3) cout << i+1 << '-' << i+3 << ": " << ar[i]+ar[i+1]+ar[i+2] << endl; ret(0); }
Answers & Comments
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cstring>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <climits>typedef unsigned long long ulol;
typedef long long lol;
typedef long int li;#define mp make_pair
#define F first
#define S second
#define sqr(a) ( (a) * (a) )
#define pb push_back
#define INF 999999999
#define ret(a) cout << endl; system("pause"); return(a)
//#define ret(a) return(a)using namespace std;int main()
{
lol n;
cin >> n;
vector<lol> ar(n);
for(int i = 0 ; i < n ; i ++)
cin >> ar[i];
for(int i = 0 ; i < n ; i += 3)
cout << i+1 << '-' << i+3 << ": " << ar[i]+ar[i+1]+ar[i+2] << endl;
ret(0);
}