Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace HeaviestWord
- {
- class Program
- {
- static void Main(string[] args)
- {
- //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.
- //Word heaviness is determined by summing all the letters in it.The letter value corresponds to the position in the English
- //alphabet - where a is 1 and z is 26. For example, the word alpha has a weight of 1 + 12 + 16 + 8 + 1 = 38.
- //Treat lower- and uppercase letters the same, so a and A both have the value 1.
- //Your task is to create a program that finds the heaviest word and prints its weight and the word itself to the standart output.
- //Input
- //On the first line, N - the number of words to follow.
- //On the next N lines - a single word.
- //Output
- //The heaviest weight and the heaviest word, separated by a space.
- //Constraints
- //5 <= N <= 500
- //3 <= letters in a word <= 20
- //Sample tests
- //Input
- //5
- //telerik
- //alpha
- //java
- //Spring
- //nodeJS
- //Output
- //83 Spring
- //Input
- //7
- //gosho
- //Pesho
- //staMAT
- //apostol
- //spiridon
- //PAUN
- //StrAHiL
- //Output
- //104 spiridon
- int count = int.Parse(Console.ReadLine());
- int inputAsAint = 0;
- string biggestWord = string.Empty;
- int largestSum = 0;
- string input = string.Empty;
- for (int i = 0; i < count; i++)
- {
- input = Console.ReadLine().ToLower();
- for (int j = 0; j < input.Length; j++)
- {
- inputAsAint += input[j] - '`';
- //inputAsAint -= 98;
- }
- if (inputAsAint >= largestSum)
- {
- largestSum = inputAsAint;
- biggestWord = input;
- }
- inputAsAint = 0;
- }
- Console.WriteLine($"{largestSum} {biggestWord}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment