Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #define NULL ((void*)0)
  6.  
  7. char changeArr() {
  8.     char STR[400];
  9.     char STR1[400];
  10.     char *st;
  11.     int a;
  12.     printf("Введите 1 или 2, где\n1 - проверка с помощью тестирующей программы\n2 - проверка данных, введённых вручную\n");
  13.     if (scanf("%d",&a)==0 || (a!=1 && a!=2)) {
  14.         printf("Ошибочный ввод! Закрытие программы.");
  15.         exit(1);
  16.     }
  17.     if (a==1) {
  18.         printf("Выберите одно из предложенных выражений:\n");
  19.         printf("1: ab2cde3 fg  hi4j5k .\n");
  20.         printf("2: a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a .\n");
  21.         printf("3: abcdefghij a33daadad .\n");
  22.         printf("4: a6o a6o a6o\n");
  23.         printf("5: ugu g3uhu huhuhu4h 3454345 fh 2dd121212 .\n");
  24.         printf("6: 123 123 123 123 123 123 .\n");
  25.         printf("7: asd asDs asdSaDd aDd aSd asdsAs asAd .\n");
  26.         printf("8: __grustno .\n");
  27.         printf("9:                                                                                    .\n");
  28.         printf("0: 4ro7ad0 fo567od c267od592e h246908u3nt56e77r0971 .\n");
  29.         char A;
  30.         A=getchar();
  31.         A=getchar();
  32.         switch(A) {
  33.             case '1':
  34.                 st = "ab2cde3 fg  hi4j5k .";
  35.                break;
  36.             case '2':
  37.                 st ="a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a .";
  38.                break;
  39.             case '3':
  40.                 st ="abcdefghij a33daadad .";
  41.                break;
  42.             case '4':
  43.                 st ="a6o a6o a6o";
  44.                break;
  45.             case '5':
  46.                 st ="ugu g3uhu huhuhu4h 3454345 fh 2dd121212 .";
  47.                break;
  48.             case '6':
  49.                 st ="123 123 123 123 123 123 .";
  50.                break;
  51.             case '7':
  52.                 st ="asd asDs asdSaDd aDd aSd asdsAs asAd .";
  53.                break;
  54.             case '8':
  55.                 st ="__grustno .";
  56.                break;
  57.             case '9':
  58.                 st ="                                                                       .";
  59.                break;
  60.             case '0':
  61.                 st ="4ro7ad0 fo567od c267od592e h246908u3nt56e77r0971.";
  62.                break;
  63.         }
  64.         printf("Исходная строка: \n");
  65.         printf("%s\n",st);
  66.         int p;
  67.         for (p=0; st[p]!='\0'; p++) {
  68.             STR[p]=st[p];
  69.         }
  70.         STR[p]='\0';
  71.     }
  72.     if (a==2) {
  73.         printf("Введите от 1 до 30 слов (длина каждого не более 10),\n при этом строка должна заканчиваться символом \".\", расположенным через пробел от последнего слова, \nа суммарное количество пробелов в строке не более 99\n");
  74.         gets(STR);
  75.         gets(STR);
  76.     int p;
  77.     for (p=0; STR[p]!='\0'; p++) {
  78.         STR1[p]=STR[p];
  79.     }
  80.     STR1[p]='\0';
  81.     printf("Исходная строка: \n");
  82.     printf("%s\n",STR1);
  83.     }
  84.     char *str[10];
  85.     char *istr;
  86.     char sep[]=" ";
  87.     int l,h,c,S=0;
  88.     h=strlen(STR);
  89.     if (STR[h-1]!='.') {
  90.         printf("Ошибочный ввод! Закрытие программы. ");
  91.         exit(2);
  92.     }
  93.     istr=strtok(STR,sep);
  94.     h=strlen(istr);
  95.     if (h>10 || istr[0]=='.') {
  96.         printf("Ошибочный ввод! Закрытие программы. ");
  97.         exit(3);
  98.     }
  99.     for (int i=0; istr[i]!='\0';i++) {
  100.         if (isdigit(istr[i])==0 && isalpha(istr[i])==0 && istr[i]!='.') {
  101.             printf("Ошибочный ввод! Закрытие программы. ");
  102.             exit(5);
  103.         }
  104.         if (isdigit(istr[i])!=0) {
  105.             for (c=i; istr[c]!='\0';c++) {
  106.                istr[c]=istr[c+1];
  107.             }
  108.             i--;
  109.         }
  110.         if (istr[i]=='.') {
  111.             S++;
  112.             if (S>1) {
  113.                 printf("Ошибочный ввод! Закрытие программы. ");
  114.                 exit(6);
  115.             }
  116.         }
  117.     }
  118.     int k,H;
  119.     h=strlen(istr);
  120.     if ((h%2!=0 && istr[h-1]=='.') || (h%2==0 && istr[h-1]!='.')) {
  121.         str[0]=istr;
  122.         if (h%2==0 && istr[h-1]!='.') {
  123.             l=1;
  124.         }
  125.         if (h%2!=0 && istr[h-1]=='.') {
  126.             printf("Новая строка: \n");
  127.             printf("%s\n",istr);
  128.             exit(0);
  129.         }
  130.         if (h%2==0 && istr[h-1]=='.') {
  131.           printf("Строка не подходит под условие. \n");
  132.           exit(0);
  133.         }
  134.     }
  135.     else {
  136.         l=0;
  137.     }
  138.     int u=0;
  139.     int j=0;
  140.     while (istr!=NULL) {
  141.         if (*istr=='.') {
  142.             u++;
  143.         }
  144.         istr=strtok(NULL,sep);
  145.         if (istr==NULL) {
  146.             break;
  147.         }
  148.         if (istr!=NULL && u!=0) {
  149.             printf("Ошибочный ввод! Закрытие программы. ");
  150.             exit(10);
  151.         }
  152.         H=strlen(istr);
  153.         if ((H>11 && istr[H-1]=='.') || (H>10 && istr[H-1]!='.')) {
  154.             printf("Ошибочный ввод! Закрытие программы. ");
  155.             exit(4);
  156.         }
  157.         j++;
  158.         H=strlen(istr);
  159.         for (int i=0; istr[i]!='\0';i++) {
  160.             if (isdigit(istr[i])==0 && isalpha(istr[i])==0 && istr[i]!='.') {
  161.                 printf("Ошибочный ввод! Закрытие программы. ");
  162.                 exit(5);
  163.             }
  164.             if (*istr=='.' || istr[i]=='.') {
  165.                 S++;
  166.             }
  167.             if (isdigit(istr[i])!=0) {
  168.                 for (k=i;istr[k]!='\0';k++) {
  169.                     istr[k]=istr[k+1];
  170.                 }
  171.                 i--;
  172.             }
  173.         }
  174.         H=strlen(istr);
  175.         if ((H%2!=0 && istr[H-1]=='.') || (H%2==0 && istr[H-1]!='.')) {
  176.             istr[H]='\0';
  177.             str[l]=istr;
  178.             l++;
  179.         }
  180.         if (S>1) {
  181.             printf("Ошибочный ввод! Закрытие программы. ");
  182.             exit(6);
  183.         }
  184.     }
  185.     if (j>30) {
  186.         printf("Ошибочный ввод! Закрытие программы. ");
  187.         exit(7);
  188.     }
  189.     if ((l==1 && H==1) || (l==1 && istr[H-1]=='.' && H%2==0) || l==0) {
  190.         printf("Нет ни одного слова, подходящего под условия\n");
  191.         exit(8);
  192.     }
  193.     printf("Новая строка: \n");
  194.     int i;
  195.     int s;
  196.     for (i=0; i<l-1; i++) {
  197.         printf("%s ",str[i]);
  198.     }
  199.     printf("%s",str[l-1]);
  200.     return 0;
  201. }
  202.  
  203. int main() {
  204.     changeArr();
  205.     return 0;
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement