Last active
May 30, 2017 17:39
-
-
Save AbdallaZaki/dfa5a52e1de57ef9a92e06909ab4372e to your computer and use it in GitHub Desktop.
Present from Lena
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://codeforces.com/problemset/problem/118/B | |
function addSpace(str,time) { | |
var space=""; | |
for(var i = 0; i < time; i++)space+=" "; | |
return space+str+"\n"; | |
} | |
function createPalindromic(n){ | |
var line="",count=n-1; | |
for(var i = 0; i < n; i++){ | |
line+=(i).toString(); | |
if(i<=count)line+=" "; | |
} | |
return line+(n).toString()+line.split("").reverse().join(""); | |
} | |
function printPresent(n){ | |
var palindromicArray=[],textToPrint="",counter=n*2; | |
for (var i = 0; i < n; i++) { | |
var line=addSpace(createPalindromic(i),counter); | |
palindromicArray.push(line); | |
textToPrint+=line; | |
counter-=2; | |
} | |
textToPrint+=addSpace(createPalindromic(n),0); | |
for (var i = n-1; i >= 0; i--)textToPrint+=palindromicArray[i]; | |
return textToPrint.replace(/\n$/,""); | |
} | |
//console.log(printPresent(process.argv[2])); | |
print(printPresent(readline())); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment