Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P3122 Гаджиев Руфат Task-6 #584

Open
wants to merge 14 commits into
base: task-6
Choose a base branch
from
19 changes: 19 additions & 0 deletions src/main/cpp/t01_max.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@
using namespace std;

int t01_max() {
int n, m, num, col, row;
cin >> n>> m;
int arr[n][m];
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
cin >> arr[i][j];
}
}
num = arr[0][0];
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
if (arr[i][j] > num){
num = arr[i][j];
col = i;
row = j;
}
}
}
cout << col << " " << row;

return 0;
}
28 changes: 28 additions & 0 deletions src/main/cpp/t02_star.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,34 @@
using namespace std;

int t02_star() {
int n;
cin >> n;
char arr[n][n];
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
arr[i][j] = '.';
}
}
for (int i = 0; i < n;i++){
for (int j = 0; j < n; j++){
if (i == n/2 || j == n/2){
arr[i][j] = '*';
}
}
}

for (int i = 0, j = 0; i < n && j < n; i++, j++){
arr[i][j] = '*';
}
for (int i = n-1, j = 0; i > -1 && j < n; --i, j++){
arr[i][j] = '*';
}
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
cout << arr[i][j] << ' ';
}
cout << endl;
}

return 0;
}
21 changes: 20 additions & 1 deletion src/main/cpp/t03_diag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@
using namespace std;

int t03_diag() {

int n= 0, i =0;
cin >> n;
int arr[n][n];
for ( i = 0; i < n; i++){
for (int row=i, col=0;row<n && col <n; row++, col++){
arr[row][col] = i;}
for (int row = 0, col = i; row <n && col <n; row++, col++){
arr[row][col] = i;
}
}



for (int row =0; row <n; row++){
for(int col = 0; col <n; col++){
cout << arr[row][col]<< " ";
}
cout << endl;
}

return 0;
}
25 changes: 24 additions & 1 deletion src/main/cpp/t04_swap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@
using namespace std;

int t04_swap() {

int n, m, i, j;
cin >> n >> m;
int arr[n][m];
for (int a = 0; a < n; a++){
for (int b = 0; b < m; b++){
cin >> arr[a][b];
}
}
i = 0, j =0;
cin >> i >> j;
for (int h =0; h < n; h++){
int c = arr[h][i];
int b = arr[h][j];
int d = c;
arr[h][i]= b;
arr[h][j]= d;
}

for (int a = 0; a < n; a++){
for (int b = 0; b <m; b++){
cout <<arr[a][b] << " ";
}
cout << endl;
}
return 0;
}
19 changes: 18 additions & 1 deletion src/main/cpp/t05_kdiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@
using namespace std;

int t05_kdiag() {

int n, num;
cin >> n;
int arr[n][n];

for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
cin >> arr[i][j];
}
}

cin >> num;
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
if (j == i - num){
cout << arr[i][j] << " ";
}
}
}
return 0;
}
28 changes: 27 additions & 1 deletion src/main/cpp/t06_cinema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,32 @@
using namespace std;

int t06_cinema() {

int n, num, m, cou=0, row=0;
cin >> n >> m;
int arr[n][m];

for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
cin >> arr[i][j];
}
}

cin >> num;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (arr[i][j]==0) {
cou++;
} else {cou=0;}
if (cou == num) {
row= i+1;
break;
}
}
if (row>0) {
break;
}
cou=0;
}
cout << row;
return 0;
}
26 changes: 25 additions & 1 deletion src/main/cpp/t07_snake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@
using namespace std;

int t07_snake() {

int n, m, num;
cin >> n >> m;
int arr[n][m];
num = 1;
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
for (int j = 0; j < m; j++){
arr[i][j] = num;
num++;
}
}
else{
for (int j = m-1; j > -1; j--) {
arr[i][j] = num;
num++;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout.width(4);
cout << arr[i][j] << " ";
}
cout << endl;
}
return 0;
}
32 changes: 31 additions & 1 deletion src/main/cpp/t08_chess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,36 @@
using namespace std;

int t08_chess() {

int n, m, num;
cin >> n >> m;
int arr[n][m];
num = 1;
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
for (int j = 0; j < m; j+=2){
arr[i][j] = num;
num++;
}
for (int j = 1; j < m; j+=2){
arr[i][j] = 0;
}
}
else{
for (int j = 1; j < m; j+=2) {
arr[i][j] = num;
num++;
for (int j = 0; j < m; j+=2){
arr[i][j] = 0;
}
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout.width(4);
cout << arr[i][j] << " ";
}
cout << endl;
}
return 0;
}
25 changes: 23 additions & 2 deletions src/main/cpp/t09_spiral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,32 @@

#include "t09_spiral.h"
#include <iostream>

#include <iomanip>

using namespace std;

int t09_spiral() {

int num1, num2, arr[100][100] = {}, z = 0, i = 1, j = 0;
cin >> num1 >> num2;
while (z < num1 * num2) {
while (arr[i][j + 1] == 0 && j < num2){
arr[i][++j] = ++z;
}
while (arr[i + 1][j] == 0 && i < num1){
arr[++i][j] = ++z;
}
while (arr[i][j - 1] == 0 && j > 1){
arr[i][--j] = ++z;
}
while (arr[i - 1][j] == 0 && i > 1){
arr[--i][j] = ++z;
}
}
for (i = 1; i <= num1; i++) {
for (int j = 1; j <= num2; j++){
cout << setw(4) << arr[i][j];
}
cout << endl;
}
return 0;
}