Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- //You will receive an array of strings as input. Your task is to find the average character within every string in the array. As in, //take every character’s ASCII code, sum it and divide the result by the sum of the count of all the letters in the array.
- //Example:
- //a b ab abc abc a, b, a, b a, b, c, a, b, c sum: 978 Divide it by 10: 97.8 97
- //After you find the average sum, convert it to its ASCII character representation, convert it to uppercase and print the original //array, delimited by that character.
- namespace char_delimiter
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] arr = Console.ReadLine().Split(' ').ToArray();
- int sumAllElements = 0;
- int countAllElements = 0;
- var delimiter = string.Empty;
- for (int i = 0; i < arr.Length; i++)
- {
- string currentElement = arr[i];
- for (int j = 0; j < currentElement.Length; j++)
- {
- int letter = currentElement[j];
- countAllElements ++;
- sumAllElements += letter;
- }
- }
- int avgSum = sumAllElements / countAllElements;
- if (avgSum >= 97 && avgSum <= 122)
- {
- avgSum -= 32;
- }
- char avgChar = (char)avgSum;
- delimiter += avgChar;
- Console.WriteLine(string.Join(delimiter, arr));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement