As in topic I got WA in ADDREV.
This is my first submission in SPOJ.
I do not know is anything wrong with my solution or something or with a way I handle input and output.
As I understand a problem. Input for my algorithm is a string that can look like that:
123
999 1
1010 1
1010 9
1010 90
1010 99
111 9
0 0
1 0
0 1
1 1
My approach looks like this.
I ignore first line, then for each line I:
separate ‘words’ using white space
revers reach word in line
convert each reversed word to uint32 and add it to result variable (initial value is zero)
then I convert result to char revers and convert back to uint32 and display
For given number I get following result:
1
201
11
11
2
21
0
1
1
2
Do I miss some specific case or just handle input and output in the wrong way?
This is my code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace SPOJ_ADDREV
{
class Program
{
private static void Main(string[] args)
{
if (args.Length == 0)
{
System.Console.WriteLine("Please provide an input.");
}
else
{
//string textInput = System.IO.File.ReadAllText(args[0]);
string textInput = args[0];
string aLine;
StringReader strLineReader = new StringReader(textInput);
int countLines = 0;
while (true)
{
aLine = strLineReader.ReadLine();
uint resultNumeric = 0;
if (aLine != null)
{
if (countLines >= 0)
{
string[] words = aLine.Split((string[])null, StringSplitOptions.RemoveEmptyEntries);
int countWords = 0;
foreach (string word in words)
{
char[] tmpWord = word.ToCharArray();
Array.Reverse(tmpWord);
resultNumeric = resultNumeric + UInt32.Parse(new string(tmpWord));
countWords++;
}
char[] tmpRes = resultNumeric.ToString().ToCharArray();
Array.Reverse(tmpRes);
Console.WriteLine(UInt32.Parse(new string(tmpRes)));
}
}
else
{
break;
}
countLines++;
}
}
}
}
}