ответ: Только не точь в точь, а то за это бан)
#include <iostream>
#include <vector>
#include <cstdint>
using namespace std; template <class T>
istream& operator>>(istream &in, vector<T> &vec) { for (auto &it : vec) in >> it; return in;
}
template <class T>
ostream& operator<<(ostream &out, vector<T> &vec) { for (auto &it : vec) out << it << ' '; return out;
}
template <class T, class U>
istream& operator>>(istream &in, pair<T, U> &pair){
in >> pair.first >> pair.second; return in;
}
template <class T, class U>
ostream& operator<<(ostream &out, pair<T, U> &pair) { out << pair.first << ' ' << pair.second; return out;
}
signed main(void) { int32_t n; cin >> n; vector<vector<int64_t>> a(n, vector<int64_t>(n,-1));
int64_t x = 0, y = n/2;
a[x][y] = 1;
for(int32_t i = 2; i <= n*n; ++i) {
int _x = x, _y = y;
if(!x) {
x = n-1;
}else {
x-=1;
}
if(y == n-1){
y = 0;
}else {
y++;
}
if(a[x][y] != -1){
x= _x, y = _y;
while(a[x][y] != -1){
if(x == n-1){
x = 0;
}else{
x++;
}
}
}
a[x][y] = i;
}
for(int32_t i = 0; i < n; ++i){
cout << a[i] << '\n';
}
return 0;
}
У вас есть 4-ая? Я щас создам вопрос!
Если , оцени)
Поделитесь своими знаниями, ответьте на вопрос:
В MS EXCEL Вычислить значение функции y=cos(x -1)/| x│ для всех x на интервале [-16 ; 16] с шагом 0, 5. Построить график
function gcd(a,b:integer):integer;
// Нахождение НОД
begin
while b<>0 do
begin
a:=a mod b;
var i:=b; b:=a; a:=i
end;
Result:=a
end;
procedure Shorter(var a,b:integer);
// "сокращатель" дроби
begin
var k:=gcd(a,b);
a:=a div k;
b:=b div k
end;
begin
var a,b:integer;
Writeln('Введите числитель и знаменатель дроби: ');
Read(a,b);
Write(a,'/',b,'='); Shorter(a,b); Writeln(a,'/',b)
end.
Тестовое решение:
Введите числитель и знаменатель дроби:
25 15
25/15=5/3