public static long solution(int N)
        {
            const int DIGIT      = 5;
            long      biggestNum = 0;
            bool      isNegative = N < 0;//remember if negative

            N = isNegative ?-N:N;

            string strNum      = N.ToString();
            int    numOfDigits = strNum.Length;

            for (int i = 0; i < numOfDigits; i++)
            {
                string tempStr     = strNum.Insert(i, DIGIT.ToString());
                long   possibleNum = Int64.Parse(tempStr);

                if (biggestNum < possibleNum)
                {
                    biggestNum = possibleNum;
                }

                else if (isNegative && biggestNum > possibleNum)
                {
                    biggestNum = possibleNum;
                }
            }

            //return the minus sign again.
            return((isNegative) ? -biggestNum : biggestNum);
        }
Exemplo n.º 2
0
        /// <summary>Fix up faction names</summary>
        public static string getPhoneticFaction(string faction, bool useICAO = false)
        {
            if (faction == null)
            {
                return(null);
            }

            // Specific fixing of names to avoid later confusion
            if (FACTION_FIXES.ContainsKey(faction))
            {
                faction = FACTION_FIXES[faction];
            }

            // Faction names can contain system names; hunt them down and change them
            foreach (var pronunciation in STAR_SYSTEM_FIXES)
            {
                if (faction.Contains(pronunciation.Key))
                {
                    return(faction.Replace(pronunciation.Key, pronunciation.Value));
                }
            }
            foreach (var pronunciation in STAR_SYSTEM_PRONUNCIATIONS)
            {
                if (faction.Contains(pronunciation.Key))
                {
                    var replacement = replaceWithPronunciation(pronunciation.Key, pronunciation.Value);
                    return(faction.Replace(pronunciation.Key, replacement));
                }
            }

            // It's possible that the name contains a constellation or catalog abbreviation, in which case translate it
            string[] pieces = faction.Split(' ');
            for (int i = 0; i < pieces.Length; i++)
            {
                if (CONSTELLATION_PRONUNCIATIONS.ContainsKey(pieces[i]))
                {
                    pieces[i] = replaceWithPronunciation(pieces[i], CONSTELLATION_PRONUNCIATIONS[pieces[i]]);
                }
                else if (ALPHA_THEN_NUMERIC.IsMatch(pieces[i]))
                {
                    pieces[i] = sayAsLettersOrNumbers(pieces[i], false, useICAO);
                }
                else if (ALPHA_DOT.IsMatch(pieces[i]))
                {
                    pieces[i] = sayAsLettersOrNumbers(pieces[i].Replace(".", ""), false, useICAO);
                }
                else if (DIGIT.IsMatch(pieces[i]))
                {
                    pieces[i] = sayAsLettersOrNumbers(pieces[i], !THREE_OR_MORE_DIGITS.IsMatch(pieces[i]), useICAO);
                }
            }
            return(string.Join(" ", pieces));
        }
Exemplo n.º 3
0
 public DIGIT(DIGIT rule)
     : base(rule.spelling, rule.rules)
 {
 }
Exemplo n.º 4
0
        /// <summary>Fix up body names</summary>
        private static string getPhoneticBody(string body, bool useICAO = false)
        {
            if (body == null)
            {
                return(null);
            }

            // Use a regex to break apart the body from the system
            var shortBody = SHORTBODY.Match(body);

            if (!shortBody.Success)
            {
                // There was no match so we pass this as-is
                return(body);
            }

            var results = new List <string>();

            // Extract and parse any leading star system name first
            var system = body.Substring(0, body.Length - shortBody.Groups[0].Value.Length).Trim();

            if (!string.IsNullOrEmpty(system))
            {
                results.Add(getPhoneticStarSystem(system, useICAO));
            }

            // Parse the short body name
            for (int i = 1; i < shortBody.Groups.Count; i++)
            {
                for (int j = 0; j < shortBody.Groups[i].Captures.Count; j++)
                {
                    var part     = shortBody.Groups[i].Captures[j].Value.Trim();
                    var lastPart = GetLastPart(shortBody, i, j);
                    var nextPart = GetNextPart(shortBody, i, j);

                    if (string.IsNullOrEmpty(part))
                    {
                        continue;
                    }
                    if (part == "Belt" || part == "Cluster" || part == "Ring")
                    {
                        // Pass as-is
                        results.Add(part);
                    }
                    else if (DIGIT.IsMatch(part) || MOON.IsMatch(part) || nextPart == "Ring" || nextPart == "Belt" || lastPart == "Cluster")
                    {
                        // The part represents a body, possibly part of the name of a moon, ring, (stellar) belt, or belt cluster;
                        // e.g. "Pru Aescs NC-M d7-192 A A Belt", "Prai Flyou JQ-F b30-3 B Belt Cluster 9", "Oopailks NV-X c17-1 AB 6 A Ring"
                        results.Add(sayAsLettersOrNumbers(part, true, useICAO));
                    }
                    else if (SUBSTARS.IsMatch(part))
                    {
                        // The part is uppercase; turn it in to ICAO if required
                        results.Add(sayAsLettersOrNumbers(part, false, useICAO));
                    }

                    else if (TEXT.IsMatch(part))
                    {
                        results.Add(sayAsLettersOrNumbers(part, true, useICAO));
                    }
                    else
                    {
                        // Pass it as-is
                        results.Add(part);
                    }
                }
            }

            return(Regex.Replace(string.Join(" ", results), @"\s+", " "));
        }
Exemplo n.º 5
0
        private DIGIT decode_DIGIT()
        {
            push("DIGIT");

            bool decoded = true;
            int s0 = index;
            var e0 = new List<Rule>();
            Rule rule;

            decoded = false;
            if (!decoded)
            {
                {
                    var e1 = new List<Rule>();
                    int s1 = index;
                    decoded = true;
                    if (decoded)
                    {
                        bool f1 = true;
                        int c1 = 0;
                        for (int i1 = 0; i1 < 1 && f1; i1++)
                        {
                            rule = decode_NumericValue("%x30-39", "[\\x30-\\x39]", 1);
                            if ((f1 = rule != null))
                            {
                                e1.Add(rule);
                                c1++;
                            }
                        }
                        decoded = c1 == 1;
                    }
                    if (decoded)
                        e0.AddRange(e1);
                    else
                        index = s1;
                }
            }

            rule = null;
            if (decoded)
                rule = new DIGIT(text.Substring(s0, index - s0), e0);
            else
                index = s0;

            pop("DIGIT", decoded, index - s0);

            return (DIGIT)rule;
        }