rendered paste body#include <stdio.h>#include <iostream>#include <fstream>using namespace std;class Cmap{ char m[10][10]; public: int puudu; // Puuduvaid laevu char get (int x=0, int y=0){ return((((x<0)||(x>9))||((y<0)||(y>9)))?'X':m[x][y]); } void set (int x=0, int y=0, char q='#'){ if (((x>=0)&&(x<=9))&&((y>=0)&&(y<=9))) m[x][y]=q; } bool safe (int x=0, int y=0){ if (get(x,y)!='.') return(0); if (get(x+1,y)=='#') return(0); if (get(x-1,y)=='#') return(0); if (get(x,y+1)=='#') return(0); if (get(x,y-1)=='#') return(0); if (get(x+1,y+1)=='#') return(0); if (get(x-1,y+1)=='#') return(0); if (get(x-1,y-1)=='#') return(0); if (get(x+1,y-1)=='#') return(0); return (1); } Cmap(int i=0){ puudu=20; for(int o=0;o<10;o++) for(int u=0;u<10;u++) m[o][u]='.'; }; Cmap(ifstream& is, int i=0){ puudu=20; for(int o=0;o<10;o++){ for(int u=0;u<10;u++){ is.get(m[u][o]); if (m[u][o]=='#') puudu--; } is.get(); } }; ostream& trk(ostream& os, int b=0){ os << "Puudu on " << puudu << " masti." << endl; for(int o=0-b;o<10+b;o++){ for(int u=0-b;u<10+b;u++) os << get(u,o); os << endl; } return os; } void read(ifstream& is){ for(int o=0;o<10;o++){ for(int u=0;u<10;u++){ is.get(m[u][o]); if (m[u][o]=='#') puudu--; } is.get(); } }};typedef class Cmap Cmap;ostream& operator << (ostream& os, Cmap& m){ for(int o=0;o<10;o++){ for(int u=0;u<10;u++) os << m.get(u,o); os << endl; } return os;}int main (void){ ifstream sf; ofstream vf; sf.open("laev.sis"); vf.open("laev.val"); Cmap a; if( !sf ) { cerr << "Error opening input stream" << endl; return 1; } else{ int x,y; x=5; y=0; a.read(sf); a.set(x,y,'S'); cout << "SAFE: " << a.safe(x,y) << endl; } a.trk(cout,1); vf << a;}