Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class CookieStore {
- public List<string> customers = new List<string>();
- public List<int> days = new List<int>();
- public bool similarCustomer(string customer1, string customer2) {
- int cnt = 0;
- for (int i = 0; i < 6; i++) {
- if (customer1[i] != customer2[i]) {
- cnt++;
- }
- }
- return cnt <= 1;
- }
- public void startNewDay() {
- customers.Clear();
- days.Add(0);
- return;
- }
- public bool processCustomer(string customerIdentifier) {
- foreach (string s in customers) {
- if (similarCustomer(s, customerIdentifier)) return false;
- }
- customers.Add(customerIdentifier);
- days[days.Count - 1]++;
- return true;
- }
- public int countCookiesGiven(int dayCount) {
- int total = 0;
- for (int i = 0; i < dayCount; i++) {
- total += days[days.Count - 1 - i];
- }
- return total;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- CookieStore cookieStore = new CookieStore();
- Console.WriteLine("Your output:");
- cookieStore.startNewDay();
- Console.WriteLine(cookieStore.processCustomer("joelgb"));
- Console.WriteLine(cookieStore.processCustomer("joelab"));
- Console.WriteLine(cookieStore.countCookiesGiven(1));
- cookieStore.startNewDay();
- Console.WriteLine(cookieStore.processCustomer("joelab"));
- Console.WriteLine(cookieStore.countCookiesGiven(1));
- Console.WriteLine(cookieStore.countCookiesGiven(2));
- cookieStore.startNewDay();
- Console.WriteLine(cookieStore.countCookiesGiven(2));
- Console.WriteLine("Expected output:");
- Console.WriteLine(true);
- Console.WriteLine(false);
- Console.WriteLine(1);
- Console.WriteLine(true);
- Console.WriteLine(1);
- Console.WriteLine(2);
- Console.WriteLine(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement