nassss

Untitled

Nov 24th, 2019
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. using System;
  2.  
  3. namespace HeaviestWord
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. //The Academy needs you! We have this list of words and we have to find the heaviest one, but we haven't a clue how to approach the problem.
  10.  
  11. //Word heaviness is determined by summing all the letters in it.The letter value corresponds to the position in the English
  12. //alphabet - where a is 1 and z is 26. For example, the word alpha has a weight of 1 + 12 + 16 + 8 + 1 = 38.
  13. //Treat lower- and uppercase letters the same, so a and A both have the value 1.
  14.  
  15. //Your task is to create a program that finds the heaviest word and prints its weight and the word itself to the standart output.
  16.  
  17. //Input
  18. //On the first line, N - the number of words to follow.
  19. //On the next N lines - a single word.
  20. //Output
  21. //The heaviest weight and the heaviest word, separated by a space.
  22. //Constraints
  23. //5 <= N <= 500
  24. //3 <= letters in a word <= 20
  25. //Sample tests
  26. //Input
  27. //5
  28. //telerik
  29. //alpha
  30. //java
  31. //Spring
  32. //nodeJS
  33. //Output
  34. //83 Spring
  35. //Input
  36. //7
  37. //gosho
  38. //Pesho
  39. //staMAT
  40. //apostol
  41. //spiridon
  42. //PAUN
  43. //StrAHiL
  44. //Output
  45. //104 spiridon
  46.  
  47. int count = int.Parse(Console.ReadLine());
  48. int inputAsAint = 0;
  49. string biggestWord = string.Empty;
  50. int largestSum = 0;
  51. string input = string.Empty;
  52.  
  53. for (int i = 0; i < count; i++)
  54. {
  55. input = Console.ReadLine().ToLower();
  56.  
  57. for (int j = 0; j < input.Length; j++)
  58. {
  59.  
  60. inputAsAint += input[j] - '`';
  61. //inputAsAint -= 98;
  62. }
  63. if (inputAsAint >= largestSum)
  64. {
  65. largestSum = inputAsAint;
  66. biggestWord = input;
  67. }
  68. inputAsAint = 0;
  69.  
  70.  
  71. }
  72. Console.WriteLine($"{largestSum} {biggestWord}");
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment