Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <string.h>
- #include <windows.h>
- using namespace std;
- void task1(int n, char str[][81], char str1[][81], int *n1, int num[]) {
- char *s, *s1; //s - на текущий символ, s1 - на начало строки
- *n1 = 0; //кол-во подстрок
- for (int i = 0; i < n; i++) {
- s = str[i];
- s1 = s;
- while (*s)
- if ((*s >= 'а' && *s <= 'я') || (*s >= 'А' && *s <= 'Я')) {
- if (s != s1) { //копирование подстроки
- num[*n1] = i;
- strncpy(str1[*n1], s1, s-s1);
- str1[*n1][s-s1] = '\0';
- (*n1)++;
- }
- while (*s && ((*s >= 'а' && *s <= 'я') || (*s >= 'А' && *s <= 'Я'))) s++;
- s1 = s;
- }
- else s++;
- if (s != s1) {
- num[*n1] = i;
- strncpy(str1[*n1], s1, s-s1);
- str1[*n1][s-s1] = '\0';
- (*n1)++;
- }
- }
- }
- int task2(char str1[][81], int n1) {
- char *s;
- int max_count = 0;
- int ind = 0;
- for (int i = 0; i < n1; i++) {
- int count1 = 0;
- s = str1[i] + strlen(str1[i]) - 1;
- for (;*s == '.';s--) count1++;
- if (count1 >= max_count) {
- max_count = count1;
- ind = i;
- }
- }
- if (max_count == 0) return -1;
- else return ind;
- }
- void task3(char st[]) {
- int len = strlen(st);
- int i = 0;
- while (i < len) {
- while (st[i] != '/' && st[i] != '*') i++;
- if ((st[i] == '/' && st[i + 1] == '*') || (st[i] == '*' && st[i + 1] == '/')) {
- for (int j = i; j < len - 1; j++) {
- st[j] = st[j + 2];
- }
- len = len - 2;
- }
- else i++;
- }
- }
- int main()
- {
- setlocale(LC_ALL, "RUS");
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- char str[10][81], str1[30][81];
- int n = 0, i1, n1, num[30];
- puts("Лабораторная работа №3");
- puts("Введите строки:");
- while (*gets(str[n]) && *str[n] && n < 10) n++;
- task1(n, str, str1, &n1, num);
- if (n1 == 0) puts("Нет подстрок");
- else {
- puts("Подстроки:");
- for (int i = 0; i < n1; i++) puts(str1[i]);
- i1 = task2(str1, n1);
- if (i1 == -1) puts("Нет подходящих подстрок");
- else {
- puts("Последняя строка с наибольшим количеством точек на конце:");
- puts(str1[i1]);
- puts("Измененная строка, содержащая предыдущую подстроку:");
- task3(str[num[i1]]);
- puts(str[num[i1]]);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement