banner



How To Draw Map In C++

Code to generate the map of Republic of india (with explanation)

Given an obfuscated lawmaking that generates the map of India, explain its working.
The following code when executed generates the map of India –

          

The above code is a typical example of obfuscated lawmaking i.due east. code that is difficult for humans to understand.
How does it work?
Basically, the cord is a run-length encoding of the map of India. Alternate characters in the string store how many times to describe space, and how many times to draw an exclamation mark consecutively.
Here is an analysis of the different elements of this plan –
The encoded string

"Hello!Welcome to GeeksForGeeks." "TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBL" "OFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|South~Pn SPm SOn TNn ULo0ULo#ULo-WHq!WFs XDt!";

Notice [b+++21] at the end of the encoded cord. As b+++21 is equivalent to (b++ + 21) which volition evaluate to 31 (ten + 21), the first 31 characters of this string are ignored and do non contribute to anything. The remaining encoded string contains instructions for drawing the map. The individual characters determine how many spaces or exclamation marks to describe consecutively.
Outer for loop
This loop goes over the characters in the string. Each iteration increases the value of b past i and assigns the next graphic symbol in the cord to a.
Inner for loop
This loop draws individual characters, and a new line whenever it reaches the terminate of the line. Consider this putchar statement

putchar(++c=='Z' ? c = c/nine : 33^b&i);

Equally 'Z' represents number 90 in ASCII, 90/9 volition give usa 10 which is a newline character. Decimal 33 is ASCII for '!'. Toggling the low-order scrap of 33 gives you 32, which is ASCII for a space. This causes! to be printed if b is odd, and a blank infinite to be printed if b is fifty-fifty.
Below is a less obfuscated version of the above code –

C++

#include <iostream>

using namespace std;

int primary()

{

int a = x, b = 0, c = x;

char * str = "TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq "

"TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBL"

"OFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm "

"SOn TNn ULo0ULo#ULo-WHq!WFs XDt!" ;

while (a != 0)

{

a = str[b++];

while (a-- > 64)

{

if (++c == 90)

{

c = 10;

putchar ( '\n' );

}

else

{

if (b % 2 == 0)

putchar ( '!' );

else

putchar ( ' ' );

}

}

}

return 0;

}

C

#include <stdio.h>

int chief()

{

int a = 10, b = 0, c = 10;

char * str = "TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq "

"TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBL"

"OFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm "

"SOn TNn ULo0ULo#ULo-WHq!WFs XDt!" ;

while (a != 0)

{

a = str[b++];

while (a-- > 64)

{

if (++c == 90)

{

c = 10;

putchar ( '\north' );

}

else

{

if (b % 2 == 0)

putchar ( '!' );

else

putchar ( ' ' );

}

}

}

return 0;

}

Java

class GFG

{

public static void main(String[] args)

{

int a = 10 , b = 0 , c = ten ;

String s1= "TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq TNn*RPn/QP,\northward"

+ "bEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBLOFAkHFOuFETpHCStHAUFAgcEAelc,\n"

+ "lcn^r^r\\tZvYxXyT|South~Pn SPm SOn TNn ULo0ULo#ULo-WHq!WFs XDt!" ;

a=s1.charAt(b);

while (a != 0 )

{

if (b < 170 )

{

a = s1.charAt(b);

b++;

while (a-- > 64 )

{

if (++c== 'Z' )

{

c/= ix ;

System.out.impress(( char )(c));

}

else

System.out.impress(( char )( 33 ^ (b & 0x01 )));

}

}

else

pause ;

}

}

}

Python3

a = x

b = 0

c = x

s = ( "TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs"

" UJq TNn*RPn/QPbEWS_JSWQAIJO^NBELPe"

"HBFHT}TnALVlBLOFAkHFOuFETpHCStHAUFA"

"gcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm S"

"On TNn ULo0ULo#ULo-WHq!WFs XDt!" )

a = ord (due south[b])

while a ! = 0 :

if b < 170 :

a = ord (s[b])

b + = ane

while a > 64 :

a - = 1

c + = 1

if c = = 90 :

c = c / / 9

print (end = chr (c))

else :

impress ( chr ( 33 ^ (b & 0X01 )), end = '')

else :

break

C#

using System;

grade GFG

{

public static void Main()

{

int a = x, b = 0, c = x;

string s1 = "TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq TNn*RPn/QP,\n"

+ "bEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBLOFAkHFOuFETpHCStHAUFAgcEAelc,\n"

+ "lcn^r^r\\tZvYxXyT|S~Pn SPm SOn TNn ULo0ULo#ULo-WHq!WFs XDt!" ;

a = s1[b];

while (a != 0)

{

if (b < 170)

{

a = s1[b];

b++;

while (a-- > 64)

{

if (++c == 'Z' )

{

c/=9;

Panel.Write(( char )(c));

}

else

Console.Write(( char )(33 ^ (b & 0x01)));

}

}

else

break ;

}

}

}

PHP

<?php

$a = 10;

$b = 0;

$c = 10;

$s1 = "TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq " .

"TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBL" .

"OFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm " .

"SOn TNn ULo0ULo#ULo-WHq!WFs XDt!" ;

$a =ord( $s1 [ $b ]);

while ( $a != 0)

{

if ( $b < 170)

{

$a = ord( $s1 [ $b ]);

$b ++;

while ( $a -- > 64)

{

if (++ $c ==90)

{

$c = floor ( $c /9);

repeat chr ( $c );

}

else

printf( chr (33 ^ ( $b & 0x01)));

}

}

else

break ;

}

?>

Output:

Console printing India's Map

Reference: http://stackoverflow.com/questions/3533348/how-does-this-code-generate-the-map-of-india
This commodity is contributed by Aditya Goel. If y'all like GeeksforGeeks and would like to contribute, you lot can also write an article using write.geeksforgeeks.org or mail your commodity to review-team@geeksforgeeks.org. Run across your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if yous detect annihilation incorrect, or you lot desire to share more data about the topic discussed in a higher place.


Source: https://www.geeksforgeeks.org/code-to-generate-the-map-of-india-with-explanation/

Posted by: fleckthervin.blogspot.com

0 Response to "How To Draw Map In C++"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel