C++ Code To Generate The Map Of India

C++ Programming is cool. Right? But have you ever tried something daring with it? Something whose results will gonna make you very proud. Maybe or maybe not, but we did![Code in C++ to generate the map of India]

Today we are going to reveal to a awesome C++ program which not only thrills you but also makes you proud, provided you not from Pakistan or any other India hater country.

WE ARE INDIAN AND WE ARE PROUD OF IT !!

Code In C++ To Generate The Map Of India

So coming to the point. As you have seen the result from our caption(featured) image already, let us give you the gift of the code here

#include<iostream>

int main(){
int a,b,c;
for (b=c=10; a="- FIGURE?, UMKC,XYZHello Folks,\TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\Hq!WFs XDt!" [b+++21]; )
for(; a-- > 64 ; ) putchar ( ++c=='Z' ? c = c/ 9:33^b&1);
return 0; 
}

This code is complicated to understand, as it is a typical example of obfuscated code. But don’t give up so early. Juggle up your head and crack the code like a real programmer. You can see the simple explanation of this code at the bottom of this article.

Code In C To Generate The Map Of India

Not a C++ programmer? Don’t worry, you can also implement this on C compiler by just replacing #include<iostream> to #include<stdio.h> or you can also use the below ready-made code:

#include<stdio.h>

int main(){
int a,b,c;
for (b=c=10; a="- FIGURE?, UMKC,XYZHello Folks,\TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\Hq!WFs XDt!" [b+++21]; )
for(; a-- > 64 ; ) putchar ( ++c=='Z' ? c = c/ 9:33^b&1);
return 0; 
}

Result Of The Pattern-Printing

When you compile the above code in your C++ or C compiler, the resulting pattern of Indian map will look like the following:

C++ Code To Generate Map Of India
C++ Code To Generate Map Of India

Simple Explanation

Basically, the string we are using is a run-length encoding of the Indian map. Alternative characters in the string stores how many times the program has to draw space, and how many times the program has to draw an exclamation(!) mark.

Here is an analysis of the different elements of this program –

Encoded String

The encoded string does all the magic. Basically, it a run-length encoding of the Indian map. Each character of the string stores the information to draw the number of spaces and exclamation mark alternatively to finally generate the map of India.

“- FIGURE?, UMKC,XYZHello Folks,\TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\NBELPeHBFHT}TnALVlBLOFAkHFOuFETp HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\Hq!WFs XDt!”

Note the [b+++21]; at the end of the string, which simply signifies to ignore the first 31 characters of the string. [b+++21] is basically b++ plus 21. which comes out to be 31 at the start as b=21.

The First for loop

This for loop runs over the character of the encoded string. After each iteration, it increases the value of b by 1. Then assign the next character.

The Second for loop

This for loop is responsible for drawing individual characters and new line if control reaches the end of a line.

Check out this putchar statement:

putchar(++c==’Z’ ? c = c/9 : 33^b&1);

As the ASCII value of ‘Z’ is 90. The c = c/9 will give you 10, which is a newline character. ‘!’ character in ASCII is represented by 33. Toggling the lower bit of 33, give you 32, that is the ASCII of space. This all results that, if b is odd, ‘!’ will be printed, and if b is even, a blank space will be printed.

Also Read: How To Download Files From Google Drive After “Download Quota Exceeded”

Leave a Comment