Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class CookieStore {
  5.  
  6.     public List<string> customers = new List<string>();
  7.     public List<int> days = new List<int>();
  8.  
  9.     public bool similarCustomer(string customer1, string customer2) {
  10.         int cnt = 0;
  11.         for (int i = 0; i < 6; i++) {
  12.             if (customer1[i] != customer2[i]) {
  13.                 cnt++;
  14.             }
  15.         }
  16.         return cnt <= 1;
  17.     }
  18.  
  19.     public void startNewDay() {
  20.         customers.Clear();
  21.         days.Add(0);
  22.         return;
  23.     }
  24.  
  25.     public bool processCustomer(string customerIdentifier) {
  26.         foreach (string s in customers) {
  27.             if (similarCustomer(s, customerIdentifier)) return false;
  28.         }
  29.         customers.Add(customerIdentifier);
  30.         days[days.Count - 1]++;
  31.         return true;
  32.     }
  33.  
  34.     public int countCookiesGiven(int dayCount) {
  35.         int total = 0;
  36.         for (int i = 0; i < dayCount; i++) {
  37.             total += days[days.Count - 1 - i];
  38.         }
  39.         return total;
  40.     }
  41. }
  42.  
  43. class Program
  44. {
  45.     static void Main(string[] args)
  46.     {
  47.         CookieStore cookieStore = new CookieStore();
  48.         Console.WriteLine("Your output:");
  49.         cookieStore.startNewDay();
  50.         Console.WriteLine(cookieStore.processCustomer("joelgb"));
  51.         Console.WriteLine(cookieStore.processCustomer("joelab"));
  52.         Console.WriteLine(cookieStore.countCookiesGiven(1));
  53.         cookieStore.startNewDay();
  54.         Console.WriteLine(cookieStore.processCustomer("joelab"));
  55.         Console.WriteLine(cookieStore.countCookiesGiven(1));
  56.         Console.WriteLine(cookieStore.countCookiesGiven(2));
  57.         cookieStore.startNewDay();
  58.         Console.WriteLine(cookieStore.countCookiesGiven(2));
  59.  
  60.         Console.WriteLine("Expected output:");
  61.         Console.WriteLine(true);
  62.         Console.WriteLine(false);
  63.         Console.WriteLine(1);
  64.         Console.WriteLine(true);
  65.         Console.WriteLine(1);
  66.         Console.WriteLine(2);
  67.         Console.WriteLine(1);
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement