Gyoshev

P12_CharacterMultiplier

Jun 12th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. using System;
  2.  
  3. namespace P12_CharacterMultiplier
  4. {
  5. class Program
  6. {
  7. static void Main()
  8. {
  9. string[] input = Console.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
  10. string firstWord = input[0];
  11. string secondWord = input[1];
  12. long sum = 0;
  13. if (firstWord.Length >= secondWord.Length)
  14. {
  15. int length1 = firstWord.Length - 1;
  16. for (int i = 0; i < secondWord.Length; i++)
  17. {
  18. sum += firstWord[i] * secondWord[i];
  19. length1--;
  20. }
  21. while (length1 >= 0 && firstWord.Length > secondWord.Length)
  22. {
  23. sum += firstWord[length1--];
  24. }
  25. }
  26. else
  27. {
  28. int lenght2 = secondWord.Length - 1;
  29. for (int i = 0; i < firstWord.Length; i++)
  30. {
  31. sum += firstWord[i] * secondWord[i];
  32. lenght2--;
  33. }
  34. while (lenght2 >= 0)
  35. {
  36. sum += secondWord[lenght2--];
  37. }
  38. }
  39. Console.WriteLine(sum);
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment