Lamms

Encrypted Matrix

Aug 27th, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _04EncryptedMatrix
  8. {
  9. class Program
  10. {
  11. static void Main()
  12. {
  13. string input = Console.ReadLine();
  14. char[] inputChar = input.ToCharArray();
  15. char[] concat = new char[inputChar.Length];
  16. char[] concat2 = new char[concat.Length];
  17. char[] newNumber = new char[concat2.Length];
  18. // char[] newnewNumber = new char[newNumber.Length];
  19. string slash = Console.ReadLine();
  20. for (int i = 0; i < inputChar.Length; i++)
  21. {
  22. char lastDigit = Convert.ToChar(inputChar[i] % 10);
  23.  
  24. concat[i]=Convert.ToChar(lastDigit);
  25. }
  26. for (int i = 0; i < concat.Length; i++)
  27. {
  28. if ((int)concat[i] % 2 == 0)
  29. {
  30. newNumber[i] = (char)(concat[i] * concat[i]);
  31.  
  32.  
  33. }
  34. else if ((int)concat[i] % 2 != 0 && (i==0))
  35. {
  36.  
  37. newNumber[i] = (char)(Convert.ToInt32(concat[i + 1])+ Convert.ToInt32(concat[i]));
  38. }
  39. else if ((int)concat[i] % 2 != 0 && (i == concat.Length - 1))
  40. {
  41. newNumber[i] = (char)(Convert.ToInt32((concat[i - 1])+Convert.ToInt32(concat[i]) ));
  42. }
  43. else if (((int)concat[i] % 2 != 0) && (i!=0) && (i!=concat.Length-1))
  44. {
  45. newNumber[i] = (char)(Convert.ToInt32(concat[i - 1]) + Convert.ToInt32(concat[i + 1]) + Convert.ToInt32(concat[i]));
  46. }
  47.  
  48. }
  49.  
  50. char[,] matrix = new char[newNumber.Length, newNumber.Length];
  51. if (slash == "\\")
  52. {
  53. for (int i = 0; i < newNumber.Length; i++)
  54. {
  55. matrix[i, i] = newNumber[i];
  56. }
  57. }
  58. else
  59. {
  60.  
  61. for (int i = 0; i < newNumber.Length; i++)
  62. {
  63. matrix[newNumber.Length - i - 1, i] = newNumber[i];
  64. }
  65. }
  66. char[] characters = newNumber.ToString().ToCharArray();
  67.  
  68. for (int i = 0; i < newNumber.Length; i++)
  69. {
  70. for (int j = 0; j < newNumber.Length; j++)
  71. {
  72.  
  73. Console.Write((int)matrix[i,j]+ " ");
  74.  
  75. }
  76. Console.WriteLine();
  77. }
  78.  
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment