Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class ScrabbleScorer
- {
- public static void Main(string[] args)
- {
- if(args.Length != 1)
- {
- Console.WriteLine("Use it like this:");
- Console.WriteLine(" ScrabbleScorer.exe <word>");
- Console.WriteLine("\n<word>: The word to calculate the score for.");
- return;
- }
- Console.WriteLine("'{0}' scores {1} points.", args[0], CalculateWordValue(args[0]));
- }
- public static Dictionary<char, int> wordValues = new Dictionary<char, int>()
- {
- { 'a', 1 }, { 'b', 3 }, { 'c', 3 }, { 'd', 2 }, { 'e', 1 }, { 'f', 4 }, { 'g', 2 }, { 'h', 4 }, { 'i', 1 },
- { 'j', 8 }, { 'k', 5 }, { 'l', 1 }, { 'm', 3 }, { 'n', 1 }, { 'o', 1 }, { 'p', 3 }, { 'q', 10 },{ 'r', 1 },
- { 's', 1 }, { 't', 1 }, { 'u', 1 }, { 'v', 4 }, { 'w', 4 }, { 'x', 8 }, { 'y', 4 }, { 'z', 10 }
- };
- public static int CalculateWordValue(string word)
- {
- word = word.ToLower();
- int totalScore = 0;
- foreach(char ch in word)
- {
- int chScore = 0;
- if(wordValues.TryGetValue(ch, out chScore))
- {
- totalScore += chScore;
- }
- }
- return totalScore;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement