Advertisement
Guest User

C# Character Multiplier

a guest
Nov 19th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. namespace Task2
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11.  
  12.  
  13.  
  14. string[] input = Console.ReadLine().Split(' ').ToArray();
  15.  
  16.  
  17. string str1 = input[0];
  18.  
  19. string str2 = input[1];
  20.  
  21. int Sum = 0;
  22. if (str1.Length < str2.Length)
  23. {
  24. for (int i = 0; i < str1.Length; i++)
  25. {
  26. int str1Value = str1[i];
  27. int str2Value = str2[i];
  28.  
  29. Sum += str1Value * str2Value;
  30. if (i == str1.Length - 1)
  31. {
  32. string difference = str2.Substring(str1.Length);
  33. int differenceValue = str2.IndexOf(difference);
  34. Sum += differenceValue;
  35.  
  36. }
  37. }
  38.  
  39. }
  40. if (str1.Length > str2.Length)
  41. {
  42. int str1Value = 0;
  43. int str2Value = 0;
  44. for (int i = 0; i < str2.Length; i++)
  45. {
  46. str1Value = str1[i];
  47. str2Value = str2[i];
  48.  
  49. Sum += str1Value * str2Value;
  50. if (i == str2.Length - 1)
  51. {
  52. string difference = str1.Substring(str2.Length);
  53. int differenceValue = str1.IndexOf(difference);
  54. Sum += differenceValue;
  55.  
  56. }
  57. }
  58.  
  59.  
  60.  
  61. }
  62. if(str1.Length == str2.Length)
  63. {
  64. for (int i = 0; i < str2.Length; i++)
  65. {
  66. int str1Value = str1[i];
  67. int str2Value = str2[i];
  68.  
  69. Sum += str1Value * str2Value;
  70.  
  71.  
  72.  
  73. }
  74. }
  75.  
  76. Console.WriteLine(Sum);
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement