Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.00 KB | None | 0 0
  1. #include <ctype.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. void delete (char str[128], int n)
  6. {
  7.     for (int i = n; i < strlen(str); i++) {
  8.         str[i] = str[i + 1];
  9.     }
  10. }
  11.  
  12. int main()
  13. {
  14.     char figure[64] = "circle";
  15.     char input[128], name[64];
  16.     fgets(input, 128, stdin);
  17.     input[strlen(input) - 1] = '\0';
  18.  
  19.     int test = 1;
  20.     // Удаление лишних пробелов
  21.     for (int j = 0, i = 0; i < strlen(input); i++) {
  22.         if (input[i] == ' ') {
  23.             if (!(((input[i - 1] == ',') && isdigit(input[i + 1])) ||
  24.                   (isdigit(input[i - 1]) && isdigit(input[i + 1])))) {
  25.                 delete (input, i--);
  26.             }
  27.         }
  28.         else if (isalpha(input[i]) && test) {
  29.             name[j++] = input[i];
  30.             name[j] = '\0';
  31.         }
  32.         else {
  33.             test = 0;
  34.         }
  35.  
  36.         j = 0;
  37.         while (name[j] != '\0') {
  38.             if (name[j] == '.') {
  39.                 if (name[j + 1] == ' ') {
  40.                     if ((name[j + 2] >= 97) && (name[j + 2] <= 122)) {
  41.                         name[j + 2] = toupper(name[j + 2]);
  42.                         j++;
  43.                     }
  44.                     else
  45.                         j++;
  46.                 }
  47.                 if ((name[j + 1] >= 97) && (name[j + 1] <= 122)) {
  48.                     name[j + 1] = toupper(name[j + 1]);
  49.                     j++;
  50.                 }
  51.                 else
  52.                     j++;
  53.             }
  54.             else
  55.                 j++;
  56.         }
  57.     }
  58.  
  59.     // Проверка названия фигуры
  60.     if (strcmp(name, figure)) {
  61.         printf("Error: такой фигуры не существует");
  62.     }
  63.     else {
  64.         if ((input[strlen(name)] != '(') || (input[strlen(input) - 1] != ')')) {
  65.             printf("Error: ошибка в синтаксисе");
  66.             return 0;
  67.         }
  68.  
  69.         int comma = 0, space = 0;
  70.         for (int i = 0; i < strlen(input); i++) {
  71.             if ((input[i] == '.') && (!isdigit(input[i - 1]) || !isdigit(input[i + 1]))) {
  72.                 printf("Error: ошибка в синтаксисе");
  73.                 return 0;
  74.             }
  75.             if (input[i] == ',') {
  76.                 comma++;
  77.             }
  78.             if (input[i] == ' ') {
  79.                 space++;
  80.             }
  81.         }
  82.         if ((comma != 1) || (space != 2)) {
  83.             printf("Error: invalid circle");
  84.             return 0;
  85.         }
  86.  
  87.         int arg = 0;
  88.         // Проверка на правильность аргументов
  89.         for (int i = strlen(name) + 1; i < strlen(input) - 1; i++) {
  90.             if (isdigit(input[i])) {
  91.                 arg++;
  92.                 for (int j = i; isdigit(input[j]); j++, i++)
  93.                     ;
  94.                 if ((arg == 1) && (input[i] != ' ')) {
  95.                     printf("Error: invalid circle");
  96.                     return 0;
  97.                 }
  98.             }
  99.         }
  100.         puts(input);
  101.     }
  102.  
  103.     return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement