Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 01. Encrypt, Sort and Print Array
- Write a program that reads a sequence of strings from the console. Encrypt every string by summing:
- • The code of each vowel multiplied by the string length
- • The code of each consonant divided by the string length
- Sort the number sequence in ascending order and print it on the console.
- On first line, you will always receive the number of strings you have to read.
- Examples
- Input Output Comments
- 4 1071 Peter = 1071
- Peter 1168 Maria = 1532
- Maria 1532 Katya = 1613
- Katya 1613 Todor = 1168
- Todor
- 3
- Sofia 1396 Sofia = 1601
- London 1601 London = 1396
- Washington 3202 Washington = 3202
- using System;
- using System.Linq;
- namespace _01EncryptSortAndPrintArray
- {
- class Program
- {
- static void Main(string[] args)
- {
- var number = int.Parse(Console.ReadLine());
- int sumWord = 0;
- string sumAllWord = "";
- for (int a = 0; a < number; a++)
- {
- string word = Console.ReadLine();
- int sumVowel = 0;
- int sumConsonant = 0;
- int counter = 0;
- foreach (char item in word)
- {
- if (item == 'A' || item == 'a' || item == 'E' || item == 'e' || item == 'I' || item == 'i' || item == 'O' || item == 'o' || item == 'U' || item == 'u' || item == 'Y' || item == 'y')
- { // "Y" e в 97.5% от случаите гласна и само 2.5% съгласна!)
- int position = word[counter];
- int vowelMultiplied = position * word.Length;
- sumVowel += vowelMultiplied;
- counter++;
- }
- else
- {
- int position = word[counter];
- int consonantDivided = position / word.Length;
- sumConsonant += consonantDivided;
- counter++;
- }
- }
- sumWord = sumVowel + sumConsonant;
- sumAllWord += sumWord + " ";
- }
- int[] sumAll = sumAllWord.Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- using System;
- using System.Linq;
- namespace _01EncryptSortAndPrintArray
- {
- class Program
- {
- static void Main(string[] args)
- {
- var number = int.Parse(Console.ReadLine());
- int sumWord = 0;
- string sumAllWord = "";
- for (int a = 0; a < number; a++)
- {
- string word = Console.ReadLine();
- int sumVowel = 0;
- int sumConsonant = 0;
- int counter = 0;
- foreach (char item in word)
- {
- if (item == 'a' || item == 'e' || item == 'i' || item == 'o' || item == 'u' || item == 'y')
- { // "Y" e в 97.5% от случаите гласна и само 2.5% съгласна!)
- int position = word[counter];
- int vowelMultiplied = position * word.Length;
- sumVowel += vowelMultiplied;
- counter++;
- }
- else
- {
- int position = word[counter];
- int consonantDivided = position / word.Length;
- sumConsonant += consonantDivided;
- counter++;
- }
- }
- sumWord = sumVowel + sumConsonant;
- sumAllWord += sumWord + " ";
- }
- int[] sumAll = sumAllWord.Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- bool swapped = false;
- do //Сортира от най-малкото към най-голямото число! За обратния ефект трябва да се разменят[i-1]с[i]!
- {
- swapped = false;
- for (int i = 1; i < sumAll.Length; i++)
- {
- int leftElement = sumAll[i - 1];
- int rightElement = sumAll[i];
- if (leftElement > rightElement)
- {
- sumAll[i - 1] = rightElement;
- sumAll[i] = leftElement;
- swapped = true;
- }
- }
- } while (swapped);
- Console.WriteLine(string.Join("\n", sumAll));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement