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 1000. A+B Problem

How to read data correctly, using C#???
Posted by Stepanko%POLYTEH% 7 Feb 2007 18:04
This is my solution:
-------------------------------------------------------
.....int a, b;
.....string s;
.....s = Console.ReadLine();
.....a = Int32.Parse(s.Substring(0, s.IndexOf(" ")));
.....b = Int32.Parse(s.Substring(s.IndexOf(" ")));
.....Console.WriteLine("{0}", a + b);
-------------------------------------------------------
Are there some easier way to read two integers without Console.ReadLine(); or somthing else, if they are stored in the same line with space:
100 200
I think that
a = Int32.Parse(s.Substring(0, s.IndexOf(" ")));
is not good solution in this case.
Re: How to read data correctly, using C#???
Posted by Sal 25 Feb 2007 17:28
String[] numbers = Console.ReadLine().Split(' ');
try {
Console.WriteLine(Int32.Parse(numbers[0]) + Int32.Parse(numbers[1]));
}
catch {}
Re: How to read data correctly, using C#???
Posted by Levdan 27 Feb 2007 23:38
politeh rulit