ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1001. Reverse Root

[C#] Looks right but it's wrong
Posted by Rensaku 19 Dec 2014 00:31
Can any one see what's the issue?

        static void Main(string[] args)
        {
            string input = Console.In.ReadToEnd();

            var valid = new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
            var sb = new StringBuilder();
            var numbers = new Stack<string>();
            for (int i = 0; i < input.Length; i++ )
            {
                if(valid.Contains(input[i]))
                {
                    sb.Append(input[i]);
                }
                else if(sb.Length > 0)
                {
                    numbers.Push(sb.ToString());
                    sb.Clear();
                }
            }

            NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo;
            foreach(var n in numbers)
            {
                double sqrt = Math.Sqrt(double.Parse(n, nfi));
                Console.WriteLine(string.Format(nfi, "{0:F4}", sqrt));
            }

        }
Re: [C#] Looks right but it's wrong
Posted by bio_kako 16 Jan 2015 20:49
.

Edited by author 16.01.2015 20:50
Re: [C#] Looks right but it's wrong
Posted by bio_kako 16 Jan 2015 21:23
If the input stream ends with a digit, your code will lose it. For debugging - replace Console.In.ReadToEnd with Console.ReadLine and try to read string with one symbol "1"