fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5.  
  6. /* Don't change anything here.
  7.  * Do not add any other imports. You need to write
  8.  * this program using only these libraries
  9.  */
  10.  
  11. namespace ProgramNamespace
  12. {
  13. /* You may add helper classes here if necessary */
  14.  
  15. public class Program
  16. {
  17. public static List<String> processData(
  18. IEnumerable<string> lines)
  19. {
  20. /*
  21.   * Do not make any changes outside this method.
  22.   *
  23.   * Modify this method to process `array` as indicated
  24.   * in the question. At the end, return a List containing
  25.   * the appropriate values
  26.   *
  27.   * Do not print anything in this method
  28.   *
  29.   * Submit this entire program (not just this function)
  30.   * as your answer
  31.   */
  32.  
  33. var parsedItems = lines.Select(x =>
  34. {
  35. var item = x.Split(',');
  36.  
  37. return new
  38. {
  39. Name = item[0],
  40. Type = item[3],
  41. Price = int.Parse(item[4].Replace("Rs", "").Trim())
  42. };
  43. });
  44.  
  45. var groupedItems = parsedItems.GroupBy(x => x.Type);
  46.  
  47. var personWhoBoughtThingsWithoutDiscount = groupedItems
  48. .Select(group => group.ToList().OrderByDescending(x => x.Price).First().Name);
  49.  
  50. var itemAlwaysBoughtInDiscount = groupedItems.SelectMany(group => group
  51. .Where(x => !personWhoBoughtThingsWithoutDiscount.Contains(x.Name)))
  52. .Select(x => x.Name).Distinct().ToList();
  53.  
  54. return itemAlwaysBoughtInDiscount;
  55. }
  56.  
  57. private static void Main(string[] args)
  58. {
  59. try
  60. {
  61. String line;
  62. var inputLines = new List<String>();
  63. while ((line = Console.ReadLine()) != null)
  64. {
  65. line = line.Trim();
  66. if (line != "")
  67. inputLines.Add(line);
  68. }
  69. var retVal = processData(inputLines);
  70. foreach (var res in retVal)
  71. Console.WriteLine(res);
  72. }
  73. catch (IOException ex)
  74. {
  75. Console.WriteLine(ex.Message);
  76. }
  77. }
  78. }
  79. }
Success #stdin #stdout 0.06s 24744KB
stdin
Rajan Patil, Aundh, 1, Phone Cover, Rs 170, Cash
Mohit Gupta, Baner, 1, Samsung Battery, Rs 900, Credit Card
Rajan Patil, Aundh, 3, Samsung Battery, Rs 1000, Cash
Nina Kothari, Baner, 4, Earphones, Rs 500, Credit Card
T Sunitha, Shivajinagar, 5, Earphones, Rs 550, Credit Card
Rohan Gade, Aundh, 10, Motorola Battery, Rs 1000, Credit Card
Rajan Patil, Shivajinagar, 21, Earphones, Rs 550, Credit Card
Rajan Patil, Aundh, 22, USB Cable, Rs 150, UPI
Meena Kothari, Baner, 23, USB Cable, Rs 100, Cash
Nina Kothari, Baner, 24, USB Cable, Rs 200, UPI
Mohit Gupta, Baner, 25, USB Cable, Rs 150, UPI
stdout
Mohit Gupta
Meena Kothari