Created
March 29, 2017 17:58
-
-
Save VisualMelon/1a8cbb79c52a156657fe214544f29f97 to your computer and use it in GitHub Desktop.
Solver and Testcases for AsciiArcLength
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
using System; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
if (args[0] == "gen") | |
GenerateRandom(); | |
else if (args[0] == "len") | |
Console.WriteLine(Measure().ToString("0.00")); | |
} | |
static void GenerateRandom() | |
{ | |
Random rnd = new Random(); | |
int len = rnd.Next(2, 101); // [2, 100] | |
string blank = new string(' ', 10); | |
char[] ls = blank.ToCharArray(); | |
int ln = -1; | |
for (int i = 0; i < len; i++) | |
{ | |
char[] s = blank.ToCharArray(); | |
int n = rnd.Next(0, 10); // [0, 9] | |
s[n] = '#'; | |
for (int j = n; ln != -1 && j != ln && ls[j] == ' '; j += Math.Sign(ln - n)) | |
{ | |
s[j] = '#'; | |
} | |
ln = n; | |
ls = s; | |
Console.WriteLine(s); | |
} | |
} | |
static double Measure() | |
{ | |
string[] lines = Console.In.ReadToEnd().Split('\n'); | |
string ls = lines[0]; | |
int ln = lines[0].IndexOf('#'); | |
double acc = 0; | |
for (int i = 1; i < lines.Length; i++) | |
{ | |
string s = lines[i]; | |
if (string.IsNullOrEmpty(s)) | |
break; | |
int n = -1; | |
for (int j = 0; j < 10; j++) | |
{ | |
if (s[j] == '#') | |
{ | |
if (n < 0 || j > ln) | |
n = j; | |
} | |
} | |
int d = ln - n; | |
acc += Math.Round(Math.Sqrt(d * d + 1), 2); | |
ls = s; | |
ln = n; | |
} | |
return Math.Round(acc, 2); | |
} | |
} |
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
Expected Output: 143.53 | |
# | |
## | |
# | |
#### | |
###### | |
# | |
# | |
#### | |
# | |
# | |
###### | |
# | |
## | |
###### | |
# | |
##### | |
# | |
###### | |
### | |
# | |
### | |
## | |
# | |
####### | |
## | |
# | |
###### | |
# | |
#### | |
##### | |
## | |
# | |
# | |
###### | |
## | |
#### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment