Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.20 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 Node
  8. {
  9. class Program
  10. {
  11. public static int NameCounter(Node<string> head, string name)
  12. {
  13. int counter = 0;
  14. int counter1 = 0;
  15. int counter2 = 0;
  16. Node<string> cheak = head;
  17. int length = name.Length;
  18. while (cheak.HasNext() != false)
  19. {
  20. counter = counter + 1;
  21. }
  22. counter = counter + 1;
  23. cheak = head;
  24. for (int i = 0; i < counter; i++)
  25. {
  26. for (int j = 0; j < length; j++)
  27. {
  28. if (cheak.GetValue()[j] == name[j])
  29. {
  30. counter1 = counter1++;
  31. }
  32. if (counter1 == length)
  33. {
  34. counter2 = counter2++;
  35. }
  36. }
  37. cheak = cheak.GetNext();
  38. }
  39. return counter2;
  40. }
  41.  
  42. public static Node<String> Targil19()
  43. {
  44. Node<string> head = null;
  45. Console.WriteLine("enter name ");
  46. string n = Console.ReadLine();
  47. Node<string> head1 = new Node<string>(n);
  48. head = head1;
  49. while (head1.GetValue() != "end")
  50. {
  51. head1.SetNext(head);
  52. head = head1;
  53. string n1 = Console.ReadLine();
  54. head1 = new Node<string>(n1);
  55. }
  56. return head;
  57. }
  58.  
  59. public static Node<string> Targil20(Node<string> head)
  60. {
  61. Node<string> p = head;
  62. head = reserve(head);
  63. p.SetNext(null);
  64. return head;
  65. }
  66.  
  67. public static Node<string> reserve(Node<string> head)
  68. {
  69. Node<string> p = head, q, w;
  70. if (!p.HasNext())
  71. {
  72. return (head);
  73. }
  74. q = p.GetNext();
  75. while (q.HasNext())
  76. {
  77. w = q.GetNext();
  78. q.SetNext(p);
  79. p = q;
  80. q = w;
  81. }
  82. q.SetNext(p);
  83. return q;
  84. }
  85.  
  86. public static Node<int> SumNode(int num)
  87. {
  88. int mod = num % 10;
  89. int newNum = num / 10;
  90. Node<int> head = new Node<int>(0);
  91. Node<int> s2 = new Node<int>(mod);
  92. head.SetNext(s2);
  93. int sum = mod;
  94. while (newNum != 0)
  95. {
  96. mod = newNum % 10;
  97. sum = sum + mod;
  98. Node<int> s1 = new Node<int>(sum);
  99. Node<int> cheak = head;
  100. while (cheak.HasNext())
  101. {
  102. cheak = cheak.GetNext();
  103. }
  104. cheak.SetNext(s1);
  105. newNum = newNum / 10;
  106. }
  107. return head;
  108. }
  109.  
  110. public static bool IFISMecahlek(Node<int> head, int n)
  111. {
  112. if (n < 10)
  113. {
  114. if (head.GetValue() % n == 0)
  115. {
  116. return true;
  117. }
  118. else
  119. {
  120. return false;
  121. }
  122. }
  123. else
  124. {
  125. Node<int> cheak = head;
  126. Node<int> before = head;
  127. int counter10 = 10;
  128. if (cheak.HasNext())
  129. {
  130. cheak = cheak.GetNext();
  131. }
  132. else
  133. {
  134. return false;
  135. }
  136. int num = before.GetValue();
  137. num = num + ((cheak.GetValue() - before.GetValue()) * counter10);
  138. if (cheak.HasNext())
  139. {
  140. cheak = cheak.GetNext();
  141. before = before.GetNext();
  142. }
  143. counter10 = counter10 * 10;
  144. while (cheak.HasNext())
  145. {
  146. num = num + ((cheak.GetValue() - before.GetValue()) * counter10);
  147. cheak = cheak.GetNext();
  148. before = before.GetNext();
  149. counter10 = counter10 * 10;
  150. }
  151. num = num + ((cheak.GetValue() - before.GetValue()) * counter10);
  152. if (num % n == 0)
  153. {
  154. return true;
  155. }
  156. else
  157. {
  158. return false;
  159. }
  160. }
  161. }
  162.  
  163. public static int sum(Node<int> head, int counter10, int n)
  164. {
  165. Node<int> cheak = head;
  166. Node<int> p = head;
  167. if (cheak.HasNext())
  168. {
  169. cheak = cheak.GetNext();
  170. n = (cheak.GetValue() - p.GetValue()) * counter10 + n;
  171. }
  172. else
  173. {
  174. n = (cheak.GetValue() - p.GetValue()) * counter10 + n;
  175. return n;
  176. }
  177. return sum(cheak, counter10 * 10, n);
  178.  
  179. }
  180.  
  181. static void Main(string[] args)
  182. {
  183. Console.WriteLine("adar good luck!");
  184. Node<string> headNames = new Node<string>("popo Gamliel");
  185. Node<string> head1 = new Node<string>("lolo Yatskan");
  186. Node<string> head2 = new Node<string>("polo Club");
  187. Node<string> head3 = new Node<string>("lopo Teranovsky");
  188. headNames.SetNext(head1);
  189. head1.SetNext(head2);
  190. head2.SetNext(head3);
  191. Console.WriteLine(headNames);
  192. //int targil18 = NameCounter(headNames, "popo");
  193. Console.WriteLine("5");
  194. //Console.WriteLine(targil18);
  195. headNames = Targil20(headNames);
  196. Console.WriteLine(headNames);
  197. Console.WriteLine(SumNode(123456));
  198. Console.WriteLine(IFISMecahlek(SumNode(123456), 123456));
  199. Console.WriteLine(sum(SumNode(123456), 1, 0));
  200. Console.ReadKey();
  201. }
  202. }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement