fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CA00003
  8. {
  9. class Program
  10. {
  11. const string inputPath = @"C:\Users\Joseph\Desktop\InputFile.txt";
  12. const string outputPath = @"C:\Users\Joseph\Desktop\OutputFile.txt";
  13. const string parametersStartAfter = "\r\n";
  14.  
  15. static void Main(string[] args)
  16. {
  17.  
  18. string outputString = "";
  19.  
  20. // Read the input parameters, split on any spaces
  21. string inputString = readFile(inputPath);
  22. inputString = inputString.Substring(inputString.IndexOf(parametersStartAfter) + parametersStartAfter.Length);
  23. string[] pairDelimiters = { "\r\n" };
  24. string[] paramDelimiters = { " " };
  25. string[] pairs = inputString.Split(pairDelimiters, StringSplitOptions.RemoveEmptyEntries);
  26.  
  27. // Loop through pairs
  28. foreach (string pair in pairs)
  29. {
  30.  
  31. // Holds the total of the processed parameters
  32. int total = 0;
  33.  
  34. // Loop through parameters in pairs
  35. string[] parameters = pair.Split(paramDelimiters, StringSplitOptions.RemoveEmptyEntries);
  36. foreach (string param in parameters)
  37. {
  38. total += Convert.ToInt32(param);
  39. }
  40.  
  41. outputString += total.ToString();
  42. outputString += " ";
  43.  
  44. }
  45.  
  46. // Write total to file
  47. writeFile(outputPath, outputString.TrimEnd(new char[] {' '}));
  48. }
  49.  
  50.  
  51. static string readFile(string filePath)
  52. {
  53. // filePath should be of the form @"C:\Users\Joseph\Desktop\InputFile.txt"
  54. return System.IO.File.ReadAllText(filePath);
  55. }
  56.  
  57. static void writeFile(string filePath, string textToWrite)
  58. {
  59. System.IO.File.WriteAllText(filePath, textToWrite);
  60. }
  61. }
  62. }
Runtime error #stdin #stdout #stderr 0.04s 27024KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Unhandled Exception:
System.IO.FileNotFoundException: Could not find file "/home/BYdsRO/C:\Users\Joseph\Desktop\InputFile.txt".
File name: '/home/BYdsRO/C:\Users\Joseph\Desktop\InputFile.txt'
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in <filename unknown>:0 
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
  at System.IO.File.OpenRead (System.String path) [0x00000] in <filename unknown>:0 
  at System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize) [0x00000] in <filename unknown>:0 
  at System.IO.StreamReader..ctor (System.String path) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.IO.StreamReader:.ctor (string)
  at System.IO.File.ReadAllText (System.String path) [0x00000] in <filename unknown>:0 
  at CA00003.Program.readFile (System.String filePath) [0x00000] in <filename unknown>:0 
  at CA00003.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not find file "/home/BYdsRO/C:\Users\Joseph\Desktop\InputFile.txt".
File name: '/home/BYdsRO/C:\Users\Joseph\Desktop\InputFile.txt'
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in <filename unknown>:0 
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
  at System.IO.File.OpenRead (System.String path) [0x00000] in <filename unknown>:0 
  at System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize) [0x00000] in <filename unknown>:0 
  at System.IO.StreamReader..ctor (System.String path) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.IO.StreamReader:.ctor (string)
  at System.IO.File.ReadAllText (System.String path) [0x00000] in <filename unknown>:0 
  at CA00003.Program.readFile (System.String filePath) [0x00000] in <filename unknown>:0 
  at CA00003.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0