Advertisement
dimipan80

Gandalf`s Stash

May 16th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. namespace Gandalfs_Stash
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.     using System.Text.RegularExpressions;
  7.  
  8.     class GandalfsStash
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Dictionary<string, int> foodTypes = new Dictionary<string, int>();
  13.             foodTypes["apple"] = 1;
  14.             foodTypes["cram"] = 2;
  15.             foodTypes["honeycake"] = 5;
  16.             foodTypes["lembas"] = 3;
  17.             foodTypes["melon"] = 1;
  18.             foodTypes["mushrooms"] = -10;
  19.  
  20.             int hapiness = int.Parse(Console.ReadLine());
  21.             string foodStr = Console.ReadLine().ToLower();
  22.             string pattern = @"[^A-Za-z]+";
  23.             string[] foods = Regex.Split(foodStr, pattern)
  24.                 .Where(s => !string.IsNullOrEmpty(s)).ToArray();
  25.  
  26.             foreach (string food in foods)
  27.             {
  28.                 if (foodTypes.ContainsKey(food))
  29.                 {
  30.                     hapiness += foodTypes[food];
  31.                 }
  32.                 else
  33.                 {
  34.                     hapiness--;
  35.                 }
  36.             }
  37.  
  38.             Console.WriteLine(hapiness);
  39.             string mood = "Angry";
  40.             if (hapiness >= -5 && hapiness < 0)
  41.             {
  42.                 mood = "Sad";
  43.             }
  44.             else if (hapiness > 0 && hapiness <= 15)
  45.             {
  46.                 mood = "Happy";
  47.             }
  48.             else if (hapiness > 15)
  49.             {
  50.                 mood = "Special JavaScript mood";
  51.             }
  52.  
  53.             Console.WriteLine(mood);
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement