-
-
Save pereslavtsev/8028362 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include <iostream> | |
#include <fstream> | |
#include <iomanip> | |
#include <conio.h> | |
#include <Windows.h> | |
using namespace std; | |
const int n =4; | |
const int stb= n; | |
const int stl = n; | |
enum ConsoleColor | |
{ | |
Black = 0, | |
Blue = 1, | |
Green = 2, | |
Cyan = 3, | |
Red = 4, | |
Magenta = 5, | |
Brown = 6, | |
LightGray = 7, | |
DarkGray = 8, | |
LightBlue = 9, | |
LightGreen = 10, | |
LightCyan = 11, | |
LightRed = 12, | |
LightMagenta = 13, | |
Yellow = 14, | |
White = 15 | |
}; | |
void set_color(ConsoleColor text, ConsoleColor background) | |
{ | |
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); | |
SetConsoleTextAttribute(hStdOut, (WORD)((background << 4) | text)); | |
} | |
void print_matrix(int **matrix, const int stl, const int stb, const int n_col) | |
{ | |
for (int i = 0; i < n; i++) | |
{ | |
for (int j = 0; j < n; j++) | |
{ | |
cout << setw(5); | |
if (j == n_col) { | |
set_color(Yellow, Black); | |
cout << matrix[i][j]; | |
set_color(LightGray, Black); | |
} | |
else { | |
cout << matrix[i][j]; | |
} | |
} | |
cout << endl; | |
} | |
} | |
void change_m(int **matrix, const int stl, const int stb) | |
{ | |
for (int i = 0, save; i < stl; i++) | |
{ | |
save = matrix[i][stb - 1]; | |
for (int j = stb - 1; j > 0; j--) | |
matrix[i][j] = matrix[i][j - 1]; | |
matrix[i][0] = save; | |
} | |
} | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
setlocale(LC_ALL, "Rus"); | |
int** matrix = new int*[stl]; | |
for (int i = 0; i < stl; i++) | |
matrix[i] = new int[stb]; | |
int k; | |
ifstream F("2013.txt", ios::out); | |
if (F == NULL) { | |
cout << "Такого файла не существует"; | |
} else { | |
int i = 0, k = 0; | |
while ( !F.eof()) | |
{ | |
F >> matrix[i][k]; | |
k++; | |
if (k == n) | |
{ | |
k = 0; | |
i++; | |
} | |
} | |
F.close(); | |
int s; | |
cout << "Введите номер столбца: "; | |
cin >> s; | |
s--; | |
cout << "Матрица:\n"; | |
print_matrix(matrix, stl, stb, s); | |
cout << "Сортированная матрица: " << endl; | |
change_m(matrix, stl, stb); | |
if (s == stb - 1) | |
{ | |
print_matrix(matrix, stl, stb, 0); | |
} | |
else | |
{ | |
print_matrix(matrix, stl, stb, s + 1); | |
} | |
} | |
_getch(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment