We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
publicstaticvoiddecentNumber(intn){intmax5=0;intmax3=0;// Any number with less than 3 digits// isn't Descent if(n<3){Console.WriteLine("-1");return;}// If the number can be modded by 3, then// we can fill it with fives which will give// us the highest value numberif(n%3==0){Console.WriteLine(newstring('5',n));return;}//Check how many groups of 5's we can put inmax5=(n/3)-1;// Check the number of 3's we can put after themmax3=n-(max5*3);// If the number of 3's doesn't mod by 5 then// start removing groups of 5if(max3%5!=0){// set max3 to zero incase there isn't a number// of 5's and 3's that will workmax3=0;// While we still have groups of 5's, keep // removing themwhile(max5>0){// Remove a group of 5'smax5--;// Get the number of remaining spacesmax3=n-(max5*3);// If those can be modded by 5, then// we found a good group combo and can// exit the loopif(max3%5==0)break;// Else set max3 back to 0max3=0;}}// If we ended up with no groups of 5's and // no groups 3's, then no good combination was foundif(max5<=0&&max3<=0){Console.WriteLine("-1");return;}// Print out the group combinationsConsole.Write(newstring('5',max5*3));Console.WriteLine(newstring('3',max3));}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and The Beast
You are viewing a single comment's thread. Return to all comments →
In C#