Skip to content

Instantly share code, notes, and snippets.

@pereslavtsev
Forked from anonymous/gist:9110883
Created February 20, 2014 13:39
Show Gist options
  • Save pereslavtsev/9113757 to your computer and use it in GitHub Desktop.
Save pereslavtsev/9113757 to your computer and use it in GitHub Desktop.
#include "stdafx.h"
#include <iomanip>
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <fstream>
using namespace std;
const int n=5;
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 SetColor(ConsoleColor text, ConsoleColor background)
{
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdOut, (WORD)((background << 4) | text));
}
void print_mas (int **a, int k)
{
cout<<endl;
for (int i=0; i<k; i++)
{
for (int j=0; j<k; j++)
cout<<setw(4)<<a[i][j];
cout<<endl;
}
cout<<endl;
}
void Fwrite (int ** a, int k)
{
ifstream FILE ("E:\\123.txt");
if (FILE)
{
int i=0,j=0;
while ( (!FILE.eof() ) && (i!=n))
{
FILE>>a[i][j++];
if (j==n)
{
i++;
j=0;
}
}
}
else
cout<<"error";
}
bool m (int **a,int i1, int j1,int i2, int j2)
{
if ( (i2<0) || (i2>n-1) || (j2<0) || (j2>n-1) )
return true;
if (a[i1][j1]>a[i2][j2])
return true;
else
return false;
}
int _tmain(int argc, _TCHAR* argv[])
{
srand(time(0));
int ** mas;
mas=new int *[n];
for (int i=0;i<n;i++)
{
mas[i]=new int [n];
}
Fwrite(mas,n);
print_mas(mas,n);
for (int i=0; i<n;i++)
{
for (int j=0;j<n;j++)
{
bool b[4];
b[0]=m(mas,i,j,i+1,j);
b[1]=m(mas,i,j,i-1,j);
b[2]=m(mas,i,j,i,j+1);
b[3]=m(mas,i,j,i,j-1);
if (b[0] && b[1] && b[2] && b[3])
SetColor (Yellow,Black);
else
SetColor(LightGray,Black);
cout<<setw(4)<<mas[i][j];
}
cout<<endl;
}
_getch();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment