Solution-Jumper Attack
#include <iostream>
#include<string>
using namespace std;
int main()
{
int m,n;
cin>>m>>n;
string tabla[9][9];
for(int i=8; i>=1; i--)
{
for(int j=1; j<=8; j++)
{
if(i==m && j==n)
{
int v=0;
for(int r=i+2; r>=i-2; r--)
{
tabla[ i ][ j ]=" 0"; //Prints 0 at the place where the position with m and n is set
if(r>i)
v++; //Moving a column for a field that is attacking a jumper
else if(r<i-1)
v--; //Moving a column for a field that is attacking a jumper
else if(r==i) //In the same row where the jumper has no attack field, there is an asterisk
{
tabla[i][j]=" *";
continue;
}
if(r<1||r>8)continue; //out of range
int k1=n+v; //column of the attacked field on the right
int k2=n-v; //column of the attacked field on the left
char kol1='a'+k1-1; //the column label of the attacked field on the right (a-h)
char kol2='a'+k2-1; //mark of the column of the attacked field on the left (a-h)
char red='0'+r; //right-clicked code marker (1-8)
string s1="";
s1+=kol1;
s1+=red;
string s2="";
s2+=kol2;
s2+=red;
if(k1<=8)
tabla[r][k1]=s1; //the number of the attacked field on the right
if(k2>=1)
tabla[r][k2]=s2; //the number of the attacked field left
}
}
else
{
if((tabla[i][j]).length()==0)
{
tabla[i][j]=" *"; //Other fields fill with an asterisk
}
}
}
}
/* Printing*/
for(int i=8; i>=1; i--)
{
for(int j=1; j<=8; j++)
{
cout<<tabla[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
#include<string>
using namespace std;
int main()
{
int m,n;
cin>>m>>n;
string tabla[9][9];
for(int i=8; i>=1; i--)
{
for(int j=1; j<=8; j++)
{
if(i==m && j==n)
{
int v=0;
for(int r=i+2; r>=i-2; r--)
{
tabla[ i ][ j ]=" 0"; //Prints 0 at the place where the position with m and n is set
if(r>i)
v++; //Moving a column for a field that is attacking a jumper
else if(r<i-1)
v--; //Moving a column for a field that is attacking a jumper
else if(r==i) //In the same row where the jumper has no attack field, there is an asterisk
{
tabla[i][j]=" *";
continue;
}
if(r<1||r>8)continue; //out of range
int k1=n+v; //column of the attacked field on the right
int k2=n-v; //column of the attacked field on the left
char kol1='a'+k1-1; //the column label of the attacked field on the right (a-h)
char kol2='a'+k2-1; //mark of the column of the attacked field on the left (a-h)
char red='0'+r; //right-clicked code marker (1-8)
string s1="";
s1+=kol1;
s1+=red;
string s2="";
s2+=kol2;
s2+=red;
if(k1<=8)
tabla[r][k1]=s1; //the number of the attacked field on the right
if(k2>=1)
tabla[r][k2]=s2; //the number of the attacked field left
}
}
else
{
if((tabla[i][j]).length()==0)
{
tabla[i][j]=" *"; //Other fields fill with an asterisk
}
}
}
}
/* Printing*/
for(int i=8; i>=1; i--)
{
for(int j=1; j<=8; j++)
{
cout<<tabla[i][j]<<" ";
}
cout<<endl;
}
return 0;
}