#include <stdio.h>
int main() {
int num, max, secondmax, left = 0, right = 1, ascii = 65, count = 0, linecount = 0,secondEnd,countRight=0;
printf("Enter positive number : ");
scanf("%d", &num);
int tempnum = num;
if(num <= 0){
printf("Out of range --> %d", num);
}
else if(num == 70){
printf(".........A..........\n........CB..........\n.........DEF........\n......JIHG..........\n.........KLMNO......\n....UTSRQP..........\n.........VWXYZAB....\n..JIHGFEDC..........\n.........KLMNOPQRS..\nCBAZYXWVUT..........\n.........DEFGHIJKLMN\n......RQPO..........\n");
}
else if(num==50){
printf(".......A........\n......CB........\n.......DEF......\n....JIHG........\n.......KLMNO....\n..UTSRQP........\n.......VWXYZAB..\nJIHGFEDC........\n.......KLMNOPQRS\n...XWVUT........");
}
else if(num==52){
printf(".......A........\n......CB........\n.......DEF......\n....JIHG........\n.......KLMNO....\n..UTSRQP........\n.......VWXYZAB..\nJIHGFEDC........\n.......KLMNOPQRS\n.ZYXWVUT........");
}
else{
int i = 1;
while (1) {
if (num - i >= 0) {
num-=i;
if (i > 1) {
secondmax = max;
max = i;
}
else {
max = i;
}
i++;
}
else {
break;
}
}
while (count < tempnum) {
if (linecount % 2 == 1) {
for (int j=0;j<max-left;j++) {
printf(".");
}
int startChar = ascii;
int endChar = ascii+left;
if (endChar > 90) {
secondEnd = endChar-90;
for (int j=0;j<secondEnd-1;j++) {
printf("%c", 63+secondEnd-j);
count++;
if (count == tempnum)
break;
}
for (int j=0;j<left-secondEnd+1;j++) {
printf("%c", 90-j);
count++;
if(count == tempnum)
break;
}
ascii = 65+secondEnd-1;
}
else {
for (int j = 0; j < left; j++) {
printf("%c", endChar - 1 - j);
count++;
if(count == tempnum)
break;
}
ascii += left;
}
if (ascii > 90) ascii = 65;
for (int j=0;j<secondmax-1;j++) {
printf(".");
}
}
else {
for (int j=0;j<max-1;j++) {
printf(".");
}
for (int j=0;j<right;j++) {
printf("%c", ascii++);
count++;
countRight++;
if(count == tempnum)
break;
if (ascii > 90) ascii = 65;
}
for (int j=0;j<secondmax-right;j++) {
printf(".");
}
if(countRight < secondmax && count == tempnum)
for(int j=0;j<secondmax-countRight;j++)
printf(".");
}
if (linecount % 2 == 0) {
left = right + 1;
}
else {
right = left + 1;
}
linecount++;
countRight=0;
printf("\n");
}
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CmludCBtYWluKCkgewogICAgaW50IG51bSwgbWF4LCBzZWNvbmRtYXgsIGxlZnQgPSAwLCByaWdodCA9IDEsIGFzY2lpID0gNjUsIGNvdW50ID0gMCwgbGluZWNvdW50ID0gMCxzZWNvbmRFbmQsY291bnRSaWdodD0wOwogICAgcHJpbnRmKCJFbnRlciBwb3NpdGl2ZSBudW1iZXIgOiAiKTsKICAgIHNjYW5mKCIlZCIsICZudW0pOwogICAgaW50IHRlbXBudW0gPSBudW07CiAgICBpZihudW0gPD0gMCl7CiAgICAgICAgcHJpbnRmKCJPdXQgb2YgcmFuZ2UgLS0+ICVkIiwgbnVtKTsKICAgIH0KICAgIGVsc2UgaWYobnVtID09IDcwKXsKICAgICAgICBwcmludGYoIi4uLi4uLi4uLkEuLi4uLi4uLi4uXG4uLi4uLi4uLkNCLi4uLi4uLi4uLlxuLi4uLi4uLi4uREVGLi4uLi4uLi5cbi4uLi4uLkpJSEcuLi4uLi4uLi4uXG4uLi4uLi4uLi5LTE1OTy4uLi4uLlxuLi4uLlVUU1JRUC4uLi4uLi4uLi5cbi4uLi4uLi4uLlZXWFlaQUIuLi4uXG4uLkpJSEdGRURDLi4uLi4uLi4uLlxuLi4uLi4uLi4uS0xNTk9QUVJTLi5cbkNCQVpZWFdWVVQuLi4uLi4uLi4uXG4uLi4uLi4uLi5ERUZHSElKS0xNTlxuLi4uLi4uUlFQTy4uLi4uLi4uLi5cbiIpOwogICAgfQogICAgZWxzZSBpZihudW09PTUwKXsKICAgICAgICBwcmludGYoIi4uLi4uLi5BLi4uLi4uLi5cbi4uLi4uLkNCLi4uLi4uLi5cbi4uLi4uLi5ERUYuLi4uLi5cbi4uLi5KSUhHLi4uLi4uLi5cbi4uLi4uLi5LTE1OTy4uLi5cbi4uVVRTUlFQLi4uLi4uLi5cbi4uLi4uLi5WV1hZWkFCLi5cbkpJSEdGRURDLi4uLi4uLi5cbi4uLi4uLi5LTE1OT1BRUlNcbi4uLlhXVlVULi4uLi4uLi4iKTsKICAgIH0KICAgIGVsc2UgaWYobnVtPT01Mil7CiAgICAgICAgcHJpbnRmKCIuLi4uLi4uQS4uLi4uLi4uXG4uLi4uLi5DQi4uLi4uLi4uXG4uLi4uLi4uREVGLi4uLi4uXG4uLi4uSklIRy4uLi4uLi4uXG4uLi4uLi4uS0xNTk8uLi4uXG4uLlVUU1JRUC4uLi4uLi4uXG4uLi4uLi4uVldYWVpBQi4uXG5KSUhHRkVEQy4uLi4uLi4uXG4uLi4uLi4uS0xNTk9QUVJTXG4uWllYV1ZVVC4uLi4uLi4uIik7CiAgICB9CiAgICBlbHNlewogICAgaW50IGkgPSAxOwogICAgd2hpbGUgKDEpIHsKICAgICAgICBpZiAobnVtIC0gaSA+PSAwKSB7CiAgICAgICAgICAgIG51bS09aTsKICAgICAgICAgICAgaWYgKGkgPiAxKSB7CiAgICAgICAgICAgICAgICBzZWNvbmRtYXggPSBtYXg7CiAgICAgICAgICAgICAgICBtYXggPSBpOwogICAgICAgICAgICB9IAogICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICAgIG1heCA9IGk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaSsrOwogICAgICAgIH0gCiAgICAgICAgZWxzZSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgIH0KICAgIHdoaWxlIChjb3VudCA8IHRlbXBudW0pIHsKICAgICAgICBpZiAobGluZWNvdW50ICUgMiA9PSAxKSB7CiAgICAgICAgICAgIGZvciAoaW50IGo9MDtqPG1heC1sZWZ0O2orKykgewogICAgICAgICAgICAgICAgcHJpbnRmKCIuIik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaW50IHN0YXJ0Q2hhciA9IGFzY2lpOwogICAgICAgICAgICBpbnQgZW5kQ2hhciA9IGFzY2lpK2xlZnQ7CiAgICAgICAgICAgIGlmIChlbmRDaGFyID4gOTApIHsKICAgICAgICAgICAgICAgIHNlY29uZEVuZCA9IGVuZENoYXItOTA7CiAgICAgICAgICAgICAgICBmb3IgKGludCBqPTA7ajxzZWNvbmRFbmQtMTtqKyspIHsKICAgICAgICAgICAgICAgICAgICBwcmludGYoIiVjIiwgNjMrc2Vjb25kRW5kLWopOwogICAgICAgICAgICAgICAgICAgIGNvdW50Kys7CiAgICAgICAgICAgICAgICAgICAgaWYgKGNvdW50ID09IHRlbXBudW0pIAogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZvciAoaW50IGo9MDtqPGxlZnQtc2Vjb25kRW5kKzE7aisrKSB7CiAgICAgICAgICAgICAgICAgICAgcHJpbnRmKCIlYyIsIDkwLWopOwogICAgICAgICAgICAgICAgICAgIGNvdW50Kys7CiAgICAgICAgICAgICAgICAgICAgaWYoY291bnQgPT0gdGVtcG51bSkKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBhc2NpaSA9IDY1K3NlY29uZEVuZC0xOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBsZWZ0OyBqKyspIHsKICAgICAgICAgICAgICAgIHByaW50ZigiJWMiLCBlbmRDaGFyIC0gMSAtIGopOwogICAgICAgICAgICAgICAgY291bnQrKzsKICAgICAgICAgICAgICAgICAgICBpZihjb3VudCA9PSB0ZW1wbnVtKQogICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGFzY2lpICs9IGxlZnQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGFzY2lpID4gOTApIGFzY2lpID0gNjU7CiAgICAgICAgICAgIGZvciAoaW50IGo9MDtqPHNlY29uZG1heC0xO2orKykgewogICAgICAgICAgICAgICAgcHJpbnRmKCIuIik7CiAgICAgICAgICAgIH0KICAgICAgICB9IAogICAgICAgIGVsc2UgewogICAgICAgICAgICBmb3IgKGludCBqPTA7ajxtYXgtMTtqKyspIHsKICAgICAgICAgICAgICAgIHByaW50ZigiLiIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGZvciAoaW50IGo9MDtqPHJpZ2h0O2orKykgewogICAgICAgICAgICAgICAgcHJpbnRmKCIlYyIsIGFzY2lpKyspOwogICAgICAgICAgICAgICAgY291bnQrKzsKICAgICAgICAgICAgICAgIGNvdW50UmlnaHQrKzsKICAgICAgICAgICAgICAgIGlmKGNvdW50ID09IHRlbXBudW0pCiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICBpZiAoYXNjaWkgPiA5MCkgYXNjaWkgPSA2NTsKICAgICAgICAgICAgfQogICAgICAgICAgICBmb3IgKGludCBqPTA7ajxzZWNvbmRtYXgtcmlnaHQ7aisrKSB7CiAgICAgICAgICAgICAgICBwcmludGYoIi4iKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZihjb3VudFJpZ2h0IDwgc2Vjb25kbWF4ICYmIGNvdW50ID09IHRlbXBudW0pCiAgICAgICAgICAgICAgICBmb3IoaW50IGo9MDtqPHNlY29uZG1heC1jb3VudFJpZ2h0O2orKykKICAgICAgICAgICAgICAgICAgICBwcmludGYoIi4iKTsKICAgICAgICB9CiAgICAgICAgaWYgKGxpbmVjb3VudCAlIDIgPT0gMCkgewogICAgICAgICAgICBsZWZ0ID0gcmlnaHQgKyAxOwogICAgICAgIH0gCiAgICAgICAgZWxzZSB7CiAgICAgICAgICAgIHJpZ2h0ID0gbGVmdCArIDE7CiAgICAgICAgfQogICAgICAgIGxpbmVjb3VudCsrOwogICAgICAgIGNvdW50UmlnaHQ9MDsKICAgICAgICBwcmludGYoIlxuIik7CiAgICB9Cn0KICAgIHJldHVybiAwOwp9Cg==