Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <windows.h>
  5.  
  6. using namespace std;
  7. void task1(int n, char str[][81], char str1[][81], int *n1, int num[]) {
  8. char *s, *s1; //s - на текущий символ, s1 - на начало строки
  9. *n1 = 0; //кол-во подстрок
  10. for (int i = 0; i < n; i++) {
  11. s = str[i];
  12. s1 = s;
  13. while (*s)
  14. if ((*s >= 'а' && *s <= 'я') || (*s >= 'А' && *s <= 'Я')) {
  15. if (s != s1) { //копирование подстроки
  16. num[*n1] = i;
  17. strncpy(str1[*n1], s1, s-s1);
  18. str1[*n1][s-s1] = '\0';
  19. (*n1)++;
  20. }
  21. while (*s && ((*s >= 'а' && *s <= 'я') || (*s >= 'А' && *s <= 'Я'))) s++;
  22. s1 = s;
  23. }
  24. else s++;
  25. if (s != s1) {
  26. num[*n1] = i;
  27. strncpy(str1[*n1], s1, s-s1);
  28. str1[*n1][s-s1] = '\0';
  29. (*n1)++;
  30. }
  31. }
  32. }
  33. int task2(char str1[][81], int n1) {
  34. char *s;
  35. int max_count = 0;
  36. int ind = 0;
  37. for (int i = 0; i < n1; i++) {
  38. int count1 = 0;
  39. s = str1[i] + strlen(str1[i]) - 1;
  40. for (;*s == '.';s--) count1++;
  41. if (count1 >= max_count) {
  42. max_count = count1;
  43. ind = i;
  44. }
  45. }
  46. if (max_count == 0) return -1;
  47. else return ind;
  48. }
  49.  
  50. void task3(char st[]) {
  51. int len = strlen(st);
  52. int i = 0;
  53. while (i < len) {
  54. while (st[i] != '/' && st[i] != '*') i++;
  55. if ((st[i] == '/' && st[i + 1] == '*') || (st[i] == '*' && st[i + 1] == '/')) {
  56. for (int j = i; j < len - 1; j++) {
  57. st[j] = st[j + 2];
  58.  
  59. }
  60. len = len - 2;
  61. }
  62. else i++;
  63. }
  64. }
  65.  
  66. int main()
  67.  
  68. {
  69. setlocale(LC_ALL, "RUS");
  70. SetConsoleCP(1251);
  71. SetConsoleOutputCP(1251);
  72. char str[10][81], str1[30][81];
  73. int n = 0, i1, n1, num[30];
  74. puts("Лабораторная работа №3");
  75. puts("Введите строки:");
  76. while (*gets(str[n]) && *str[n] && n < 10) n++;
  77. task1(n, str, str1, &n1, num);
  78. if (n1 == 0) puts("Нет подстрок");
  79. else {
  80. puts("Подстроки:");
  81. for (int i = 0; i < n1; i++) puts(str1[i]);
  82. i1 = task2(str1, n1);
  83. if (i1 == -1) puts("Нет подходящих подстрок");
  84. else {
  85. puts("Последняя строка с наибольшим количеством точек на конце:");
  86. puts(str1[i1]);
  87. puts("Измененная строка, содержащая предыдущую подстроку:");
  88. task3(str[num[i1]]);
  89. puts(str[num[i1]]);
  90. }
  91. }
  92. return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement