fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. // your code goes here
  10. try
  11. {
  12. String line;
  13. var inputLines = new List<String>();
  14. while((line = Console.ReadLine()) != null) {
  15. line = line.Trim();
  16. if (line != "")
  17. inputLines.Add(line);
  18. }
  19. var retVal = processData(inputLines);
  20. foreach(var res in retVal)
  21. Console.WriteLine(res);
  22. }
  23. catch (IOException ex)
  24. {
  25. Console.WriteLine(ex.Message);
  26. }
  27. }
  28.  
  29. public static List<String> processData(
  30. IEnumerable<string> lines)
  31. {
  32. /*
  33.   * Do not make any changes outside this method.
  34.   *
  35.   * Modify this method to process `array` as indicated
  36.   * in the question. At the end, return a List containing
  37.   * the appropriate values
  38.   *
  39.   * Do not print anything in this method
  40.   *
  41.   * Submit this entire program (not just this function)
  42.   * as your answer
  43.   */
  44. List<String> retVal = new List<String>();
  45. Dictionary<string, string> productDict = new Dictionary<string, string>();
  46. foreach(var line in lines)
  47. {
  48. string[] saleArray = line.Split(", ");
  49. if(productDict.ContainsKey(saleArray[3]))
  50. {
  51. int productPrice = int. Parse(productDict[saleArray[3]]);
  52. int price = int.Parse(saleArray[4]);
  53. if(price < productPrice)
  54. productDict[saleArray[3]] = productPrice.ToString();
  55. }
  56. else
  57. {
  58. productDict[saleArray[3]] = saleArray[4];
  59. }
  60. }
  61. List<string> discountedCustomer = new List<string>();
  62. foreach(var discountedProd in productDict.Keys)
  63. {
  64. foreach(var line in lines)
  65. {
  66. string[] saleArray = line.Split(", ");
  67. if(discountedProd == saleArray[3] && productDict[discountedProd] == saleArray[4])
  68. {
  69. discountedCustomer.Add(saleArray[0]);
  70. }
  71. }
  72. }
  73. return retVal;
  74. }
  75. }
Success #stdin #stdout 0.02s 15552KB
stdin
Standard input is empty
stdout
Standard output is empty