Advertisement
Grisha1549

Untitled

Jan 20th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.31 KB | None | 0 0
  1. //#include <stdio.h>
  2. //#include <malloc.h>
  3. //#include <time.h>
  4. //#include <stdlib.h>
  5. //#include <conio.h>
  6. //using namespace std;
  7. //int main()
  8. //{
  9. //  int *a,**b;
  10. //  int i, n, m,r,j;
  11. //  srand(50);
  12. //  //r = rand();
  13. //  //a = (int*)malloc(r* sizeof(int));
  14. ////    for (i = 0; i < r; i++)
  15. ////        a[i] = rand();
  16. //  //n = rand();
  17. //  n = 5;
  18. //  m = 5;
  19. //  b = (int**)malloc(n*sizeof(int*));
  20. //  for (i = 0; i < n; i++)
  21. //  {
  22. //      b[i] = (int*)malloc(m * sizeof(int));
  23. //      for (j = 0; j < m; j++)
  24. //          b[i][j] = rand();
  25. //      printf_s("%x \n", &b[i][j]);
  26. //  }
  27. //  for (i = 0; i < n; i++)
  28. //  {
  29. //      for (j = 0; j < m; j++)
  30. //          printf_s("%d ", b[i][j]);
  31. //      printf_s("\n");
  32. //      free(b[i]);
  33. //  }
  34. //  free(b);
  35. //  _getch();
  36. //  return 0;
  37. //}
  38.  
  39. //#include <stdio.h>
  40. //#include <malloc.h>
  41. //#include <time.h>
  42. //#include <stdlib.h>
  43. //#include <conio.h>
  44. //using namespace std;
  45. //struct data
  46. //{
  47. //  int a;
  48. //};
  49. //struct list
  50. //{
  51. //  struct data value;
  52. //  struct list *next;
  53. //  struct list *prev;
  54. //
  55. //};
  56. //int main()
  57. //{
  58. //  srand(time(NULL));
  59. //  int i;
  60. //  struct list *head,*last,*p1,*p2;
  61. //  head = (struct list*)malloc(sizeof(struct list));
  62. //  head->value.a = rand();
  63. //  head->next = NULL;
  64. //  head->prev = NULL;
  65. //  p1 = head;
  66. //  for (i = 1; i < 5; i++)
  67. //  {
  68. //      p1->next=(struct list*)malloc(sizeof(struct list));//выделяю память для следующего элемента
  69. //      p2 = p1->next;
  70. //      p2->prev = p1;
  71. //      p2->value.a = rand();
  72. //      p2->next = NULL;
  73. //      p1 = p2;
  74. //
  75. //  }
  76. //  last=p1;
  77. //  p1 = head;
  78. //  for (;p1!=NULL;)
  79. //  {
  80. //
  81. //      printf_s("%d ", p1->value.a);
  82. //      p1 = p1->next;
  83. //  }
  84. //  printf_s("\n");
  85. //  p1 = last;
  86. //  for (; p1 != NULL;)
  87. //  {
  88. //
  89. //      printf_s("%d", p1->value.a);
  90. //      p1 = p1->prev;
  91. //  }
  92. //      _getch();
  93. //  return 0;
  94. //}
  95.  
  96. //#include <stdio.h>
  97. //#include <malloc.h>
  98. //#include <time.h>
  99. //#include <stdlib.h>
  100. //#include <conio.h>
  101. //using namespace std;
  102. //
  103. //int main()
  104. //{
  105. //  int nstr1,nstr2,istr1,istr2, i, j,k;
  106. //  char *str1,*str12, *str2;
  107. //  str1 = new char[256];
  108. //  str2 = new char[256];
  109. //  str12 = new char[256];
  110. //  char c='a';
  111. //  for (nstr1=0; c != '\n';nstr1++)
  112. //  {
  113. //      scanf_s("%c", &c);
  114. //      str1[nstr1] = c;
  115. //  }
  116. //  c = 'a';
  117. //  for (nstr2 = 0; c != '\n'; nstr2++)
  118. //  {
  119. //      scanf_s("%c", &c);
  120. //      str2[nstr2] = c;
  121. //  }
  122. //  nstr2--;
  123. //  for (istr1=nstr1-1; istr1 >= 0; istr1--)
  124. //  {
  125. //      if (str1[istr1] == str2[nstr2-1])
  126. //      {
  127. //          i = istr1;
  128. //          k = 0;
  129. //          for (j = nstr2 - 2; j>= 0; j--)
  130. //          {
  131. //              i--;
  132. //              if (str2[j] == str1[i])k++;
  133. //             
  134. //          }
  135. //          if (k == nstr2 - 1)
  136. //          {
  137. //              k = istr1+1;
  138. //              for (istr1-=nstr2; istr1 >= 0; istr1--)
  139. //                  str12[istr1] = str1[istr1];
  140. //              istr2 = k - nstr2;
  141. //              for (istr1=k; istr1<nstr1; istr1++)
  142. //              {
  143. //                  str12[istr2] = str1[istr1];
  144. //                  istr2++;
  145. //              }
  146. //              k = -1;
  147. //              istr1 = -1;
  148. //          }
  149. //      }
  150. //  }
  151. //  if(k==-1)
  152. //      for (i = 0; i<istr2; i++)
  153. //          printf_s("%c", str12[i]);
  154. //  else
  155. //      for (istr1 = 0; istr1<nstr1; istr1++)
  156. //          printf_s("%c", str1[istr1]);
  157. //
  158. //      _getch();
  159. //  return 0;
  160. //}
  161.  
  162. //#include <conio.h>
  163. //#include <stdio.h>
  164. //#include <stdlib.h>
  165. //#include <time.h>
  166. //
  167. //struct date
  168. //{
  169. //  int a;
  170. //};
  171. //struct list
  172. //{
  173. //  struct date value;
  174. //  struct list *next;
  175. //  struct list *prev;
  176. //};
  177. //int main()
  178. //{
  179. //  srand(time(NULL));
  180. //  int i,n,m;
  181. //  struct list *head, *last, *p1, *p2;
  182. //  scanf_s("%d %d", &n,&m);
  183. //  head = new struct list;
  184. //  head->value.a = rand();
  185. //  head->prev = NULL;
  186. //  head->next = NULL;
  187. //  p1 = head;
  188. //  for (i = 2; i <= n; i++)
  189. //  {
  190. //      p1->next = new struct list;
  191. //      p2 = p1->next;
  192. //      p2->next = NULL;
  193. //      p2->prev = p1;
  194. //      p2->value.a = rand();
  195. //      p1 = p2;
  196. //
  197. //  }
  198. //  last = p1;
  199. //  for (p1 = head; p1->next != NULL;p1=p1->next)
  200. //  {
  201. //      printf_s("%d ", p1->value.a);
  202. //  }
  203. //  printf_s("%d ", p1->value.a);
  204. //  printf_s("\n");
  205. //  p1 = head;
  206. //  for (i = 1; i < m ; i++)
  207. //      p1 = p1->next;
  208. //  p1->prev->next = p1->next;
  209. //  p1->next->prev = p1->prev;
  210. //  if (p1 == head)
  211. //  {
  212. //      head = p1->next;
  213. //      head->prev = NULL;
  214. //  }
  215. //
  216. //  else if (p1 == last)
  217. //  {
  218. //      last = p1->prev;
  219. //      last->next = NULL;
  220. //  }
  221. //  printf_s("%x %x \n", *p1->next, p1->prev);
  222. //  free(p1);
  223. //  for (p1 = head; p1->next != NULL; p1 = p1->next)
  224. //  {
  225. //      printf_s("%d ", p1->value.a);
  226. //  }
  227. //  printf_s("%d ", p1->value.a);
  228. //  _getch();
  229. //  return 0;
  230. //}
  231.  
  232. #include <stdio.h>
  233. #include <conio.h>
  234. #include <stdlib.h>
  235.  
  236. void f1 (char **s,int m[4])
  237. {
  238.     char *s1;
  239.     for (int j = 0; j < 4; j++)
  240.     {
  241.         for (int i = 0; i < m[j]; i++)
  242.         {
  243.             printf_s("%c", s[j][i]);
  244.         }
  245.         printf_s("\n");
  246.     }
  247.  
  248. }
  249. char* f3(char **s,int s11, int s22,int m[4])
  250. {
  251.     char *strr;
  252.     int j = 0;
  253.     strr = new char[256];
  254.     for (int i = 0; i < m[s11]; i++)
  255.     {
  256.         strr[j] = s[s11][i];
  257.         j++;
  258.     }
  259.     for (int i = 0; i < m[s22]; i++)
  260.     {
  261.         strr[j] = s[s22][i];
  262.         j++;
  263.     }
  264.     for (int i = 0; i < m[s11]+m[s22]; i++)
  265.     {
  266.         printf_s("%c", strr);
  267.     }
  268.     printf_s("\n");
  269.     return strr;
  270. }
  271.  
  272. int main()
  273. {
  274.     system("chcp 1251");
  275.     system("cls");
  276.     int n[4], k;
  277.     n[0] = 3;
  278.     n[1] = 3;
  279.     n[2] = 3;
  280.     n[3] = 3;
  281.     char *str[4];
  282.     str[0] = new char[256];
  283.     str[1] = new char[256];
  284.     str[2] = new char[256];
  285.     str[3] = new char[256];
  286.     str[0] = "abc";
  287.     str[1] = "def";
  288.     str[2] = "ghi";
  289.     str[3] = "klm";
  290.     k = -1;
  291.     for (; k != 0;)
  292.     {
  293.         printf_s("Если хотите выести строки на экран, нажмите 1 \n Если хотите удалить строку, нажмите 2 \n Если хотите соеденить 2 строки нажмите 3 \n Если хотете закончить работу нажмите 0 \n");
  294.         scanf_s("%d", &k);
  295.         if(k==1) f1(str, n);
  296.         else if(k==2)
  297.                 {
  298.                     printf_s("Напишите номер строки которую хотите удалить:");
  299.                     for (int i = 0; i < 4; i++)
  300.                         if (n[i] != -1) printf_s("%d ", i);
  301.                     printf_s("\n");
  302.                     scanf_s("%d", &k);
  303.                     n[k] = -1;
  304.                     //free(str[k]);
  305.                 }
  306.            
  307.         else if (k == 3)
  308.         {
  309.             int s1, s2;
  310.             printf_s("Введите номера строк которые хотите объеденить:");
  311.             for (int i = 0; i < 4; i++)
  312.                 if (n[i] != -1) printf_s("%d ", i);
  313.             printf_s("\n");
  314.             scanf_s("%d %d",&s1,&s2);
  315.             str[s1]=f3(str,s1,s2,n);
  316.             //free(str[s2]);
  317.             n[s2] = -1;
  318.         }
  319.                
  320.  
  321.     }
  322.     _getch();
  323.     return 0;
  324. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement