//Program to create a map of India. Created On 27th August 2021 by Arthit Sen
import java.util.*;
class MapOfIndia
{
public static void main(String[] args) throws Exception
{
String ob="TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBLOFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm SOn TNn ULo0ULo#ULo-WHq!WFs XDt!";
int x = 10, y = 0, z = 10;
x = ob.charAt(y);
while (x != 0)
{
if (y < 170)
{
x = ob.charAt(y);
y++;
while(x > 64)
{
x--;
if(++z == 'Z')
{
z /= 9;
System.out.print((char)(z));
}
else
System.out.print((char)(33 ^ (y & 0x01)));
}
}
else
{
break;
}
}
System.out.println("\n");
}
}
Let me know how the map looks and afterward, I'll make a program to show the map and region of the states by taking the name of the state from the user.
let me explain to you how to do this
Explanation:
Basically, the string is a run-length encoding of the map of India. Alternating characters in the string stores how many times to draw space and how many times to draw an exclamation mark consecutively. Here’s an analysis of the different elements of this program –
The encoded string:
TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJ
q TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBLOFAkHFOuFETpHCStHAUFAgcE
Aelclcn^r^r\\tZvYxXyT|S~Pn SPm SOn TNn ULo0ULo#ULo-WHq!WFs XDt!"
Notice [b+++21]
at the end of the encoded string. As b+++21
is equivalent to (b++ + 21)
which will evaluate to 31 (10 + 21)
, the first 31
characters of this string are ignored and does not contribute to anything. The remaining encoded string contains instructions for drawing the map. The individual characters determine how many spaces or exclamation marks to draw consecutively.
Outer for-loop:
This loop goes over the characters in the string. Each iteration increases the value of b
by one and assigns the next character in the string to a.
Inner for-loop:
This loop draws individual characters and a newline whenever it reaches the end of the line. Consider the following sysout statement.
System.out.print((char)(++c == 'Z' ? c = c / 9 : 33 ^ b & 1))
As ‘Z’ represents number 90 in ASCII, 90/9 will give us 10, a newline character. Decimal 33 is ASCII for ‘!’. Toggling the low-order bit of 33 gives you 32, which is ASCII for space. This causes !
to be printed if b
is odd and a blank space to be printed if b
is even.