#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(){
int n;
cin >> n;
vector<vector<int>> a(n, vector<int> (n));
vector<int> x(2*n);
map<int,int> m;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
cin >> a[i][j];
int cur1 = 1, cur2 = 0, elem = 0, cnt = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i == j){
x[cur1] = a[i][j];
cur1 += 2;
m[a[i][j]]++;
if(m[a[i][j]] > cnt){
cnt = m[a[i][j]];
elem = a[i][j];
}
if(i + j == n - 1){
x[cur2] = a[i][j];
cur2 += 2;
for(auto &i : x) cout << i << " ";
cout << "\nThe most popular element is : " << elem;
Відповідь:
#include<string>//для std::string,length()
#include<iomanip>//для std::setw()
struct kid{
std::string name;
bool gender;
float height;
};
int main(int argc, char** argv) {
struct kid kids[]={
"Tom",1,1.34,
"Sara",0,1.54,
"John",1,1.65,
"Kate",0,1.86,
"Emily",0,1.53,
"Lily",0,1.57,
"Oscar",1,1.76,
"James",1,1.73,
"William",1,1.71,
"George",1,1.67,
"Noah",1,1.61,
"Leo",1,1.75,
"David",1,1.71,
"Albert",1,1.68,
"Austin",1,1.84,
"Mia",0,1.65,
"Ruby",0,1.64,
"Scarlett",0,1.54,
"Isabelle",0,1.45,
"Ellie",0,1.65
double medium=0.0;
int n=sizeof(kids)/sizeof(kids[0]);
int t=0;
for(int i=0;i<n;i++){
std::cout<<kids[i].name<<std::setw(12-kids[i].name.length())<<kids[i].gender<<std::setw(7)<<kids[i].height<<std::endl;
if(kids[i].gender==true){
medium+=kids[i].height;t++;}
medium/=t;
std::cout<<"\nMedium height of boys= "<<medium<<std::endl<<std::endl;
if(kids[i].gender==1){
if(kids[i].height<medium){
system("pause");
return 0;
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(){
int n;
cin >> n;
vector<vector<int>> a(n, vector<int> (n));
vector<int> x(2*n);
map<int,int> m;
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
cin >> a[i][j];
int cur1 = 1, cur2 = 0, elem = 0, cnt = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i == j){
x[cur1] = a[i][j];
cur1 += 2;
m[a[i][j]]++;
if(m[a[i][j]] > cnt){
cnt = m[a[i][j]];
elem = a[i][j];
}
}
if(i + j == n - 1){
x[cur2] = a[i][j];
cur2 += 2;
m[a[i][j]]++;
if(m[a[i][j]] > cnt){
cnt = m[a[i][j]];
elem = a[i][j];
}
}
}
}
for(auto &i : x) cout << i << " ";
cout << "\nThe most popular element is : " << elem;
}
Відповідь:
#include <iostream>
#include<string>//для std::string,length()
#include<iomanip>//для std::setw()
struct kid{
std::string name;
bool gender;
float height;
};
int main(int argc, char** argv) {
struct kid kids[]={
"Tom",1,1.34,
"Sara",0,1.54,
"John",1,1.65,
"Kate",0,1.86,
"Emily",0,1.53,
"Lily",0,1.57,
"Oscar",1,1.76,
"James",1,1.73,
"William",1,1.71,
"George",1,1.67,
"Noah",1,1.61,
"Leo",1,1.75,
"David",1,1.71,
"Albert",1,1.68,
"Austin",1,1.84,
"Mia",0,1.65,
"Ruby",0,1.64,
"Scarlett",0,1.54,
"Isabelle",0,1.45,
"Ellie",0,1.65
};
double medium=0.0;
int n=sizeof(kids)/sizeof(kids[0]);
int t=0;
for(int i=0;i<n;i++){
std::cout<<kids[i].name<<std::setw(12-kids[i].name.length())<<kids[i].gender<<std::setw(7)<<kids[i].height<<std::endl;
if(kids[i].gender==true){
medium+=kids[i].height;t++;}
}
medium/=t;
std::cout<<"\nMedium height of boys= "<<medium<<std::endl<<std::endl;
for(int i=0;i<n;i++){
if(kids[i].gender==1){
if(kids[i].height<medium){
std::cout<<kids[i].name<<std::setw(12-kids[i].name.length())<<kids[i].gender<<std::setw(7)<<kids[i].height<<std::endl;
}
}
}
system("pause");
return 0;
}