fork(3) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6. int check(char c, char che[]);
  7. int is_enum(char* c, int beg, int end);
  8. int is_log(char* c, int beg, int end);
  9.  
  10.  
  11. int main()
  12. {
  13. char* c = "nota";
  14. int l = strlen(c);
  15. if (is_log(c, 0, l - 1)) printf("Logical expression was arranged correctly");
  16. else printf("Logical expression wasn't arranged correctly");
  17. return 0;
  18. }
  19.  
  20.  
  21. int check(char c, char che[]) {
  22. int l = strlen(che);
  23. int n = 0;
  24. for (int i = 0; i < l; i++) {
  25. if (c == che[i]) {
  26. n++;
  27. break;
  28. }
  29. }
  30. return n;
  31. } /*проверка вхождения символа в массив*/
  32.  
  33.  
  34. int is_enum(char* c, int beg, int end) {
  35. int n, p, j, k , nbeg;
  36. char op[] = "+-*/";
  37. if ((beg == end) && isalnum(c[beg])) return 1;
  38. if ((isalnum(c[beg]) != 0) && (check(c[beg + 1], op) != 0)) return is_enum(c, beg + 2, end);
  39. if (c[beg] == '(') {
  40. p = 0;
  41. for (int i = 0; i <= end; i++) {
  42. if (c[i] == '(') p++;
  43. if (c[i] == ')') p--;
  44. if (p == 0) {
  45. k = i + 1;
  46. nbeg = i + 2;
  47. break;
  48. }
  49. }
  50. if (c != 0) return 0;
  51. if (k < end) {
  52. if (check(c[k], op)) return is_enum(c, beg + 1, k - 2) * is_enum(c, nbeg, end);
  53. }
  54. else {
  55. return is_enum(c, beg + 1, k - 2);
  56. }
  57. }
  58. return 0;
  59. } /*проверка выражений*/
  60.  
  61. int is_log(char* c, int beg, int end) {
  62. if (check(c[beg], "TtFf")) return 1;
  63. if (check(c[beg], "Aa") && check(c[beg + 1], "Nn") && check(c[beg + 2], "Dd")) return is_enum(c, beg + 3, end);
  64. if (check(c[beg], "Nn") && check(c[beg + 1], "Oo") && check(c[beg + 2], "Tt")) return is_enum(c, beg + 3, end);
  65. if (check(c[beg], "Oo") && check(c[beg + 1], "Rr")) return is_enum(c, beg + 2, end);
  66. return 0;
  67. }
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
Logical expression was arranged correctly