Я не понимаю почему элементы мапы и вектора не возводятся в квадрат. #include
#include
#include
#include
using namespace std;
template
T Sqr(T a) {
a *= a;
return a;
}
template
pair Sqr(pair p) {
return {Sqr(p.first), Sqr(p.second)};
}
template
map Sqr(map m) {
for (pair i : m) {
i.second = Sqr(i.second);
}
return m;
}
template
vector operator*(vector lhs, const vector & rhs) {
for (T i : lhs) {
i = Sqr(i);
}
return lhs;
}
int main() {
// Пример вызова функции
vector v = {1, 2, 3};
cout << "vector:";
for (int x : (v * v)) {
cout << ' ' << x;
}
cout << endl;
map > map_of_pairs = {
{4, {2, 2}},
{7, {4, 3}}
};
cout << "map of pairs:" << endl;
for (const auto& x : Sqr(map_of_pairs)) {
cout << x.first << ' ' << x.second.first << ' ' << x.second.second << endl;
}
int a = 2;
cout << Sqr(a);
}
144
233
Ответы на вопрос:
Uses crt; var a,b,c,d: real; beginwriteln('введите 4 число'); readln(a,b,c,d); write('среднее арифметическое=',(a+b+c+d)/4); end.
Популярно: Информатика
-
Анна66611116.12.2021 11:54
-
oleg183630.05.2022 16:40
-
анна226426.01.2023 04:38
-
ishimovaalbina21.02.2020 00:06
-
Marattadjibov7317.05.2022 05:41
-
Oho913.11.2020 10:39
-
Alinalime1012.09.2020 20:49
-
богдан25412.06.2023 15:16
-
para65616.01.2021 00:51
-
школа555308.12.2021 13:37