Guest User

Smallest Weight

a guest
Apr 10th, 2020
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace SmallestWeight
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. ushort n = ushort.Parse(Console.ReadLine());
  11. Dictionary<char, byte> alphabeth = new Dictionary<char, byte>()
  12. {
  13. { 'a', 1 }, { 'b', 2 }, { 'c', 3 }, { 'd', 4}, { 'e', 5}, { 'f', 6},
  14. { 'g', 7}, { 'h', 8}, { 'i', 9}, { 'j', 10}, { 'k', 11}, { 'l', 12},
  15. { 'm', 13}, { 'n', 14}, { 'o', 15}, { 'p', 16}, { 'q', 17}, { 'r', 18},
  16. { 's', 19}, { 't', 20}, { 'u', 21}, { 'v', 22}, { 'w', 23}, { 'x', 24},
  17. { 'y', 25}, { 'z', 26}
  18. };
  19.  
  20. int smallestWeight = 0;
  21. string wordWithSmallestWeight = "";
  22.  
  23. for (int i = 0; i < n; i++)
  24. {
  25. string word = Console.ReadLine();
  26. int weight = 0;
  27.  
  28. for (int j = 0; j < word.Length; j++)
  29. {
  30. weight += alphabeth[char.Parse(word[j].ToString().ToLower())];
  31. }
  32.  
  33. if (i == 0 || weight <= smallestWeight)
  34. {
  35. smallestWeight = weight;
  36. wordWithSmallestWeight = word;
  37. }
  38. }
  39.  
  40. Console.WriteLine($"{smallestWeight} {wordWithSmallestWeight}");
  41. }
  42. }
  43. }
Add Comment
Please, Sign In to add comment