Advertisement
Guest User

Untitled

a guest
Oct 10th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QMessageBox>
  4. #include <iostream>
  5. #include <cstring>
  6. #include <cctype>
  7. #include <QDebug>
  8.  
  9.  
  10.  
  11. MainWindow::MainWindow(QWidget *parent) :
  12. QMainWindow(parent),
  13. ui(new Ui::MainWindow)
  14. {
  15. ui->setupUi(this);
  16. }
  17.  
  18. MainWindow::~MainWindow()
  19. {
  20. delete ui;
  21. }
  22.  
  23. bool MainWindow::check_br(QString str){
  24. int count = 0;
  25. for (int i=0;i<str.size();i++) {
  26. if(str[i]=='(')
  27. count++;
  28. if(str[i]==')')
  29. count--;
  30.  
  31. if(count<0)
  32. return false;
  33. }
  34. if(count!=0)
  35. return false;
  36.  
  37. return true;
  38. }
  39.  
  40. int MainWindow::checkname(char* str, int* pos){
  41. for (int i = 0; i < 3; i++) {
  42. if (!isalpha(str[*pos]))
  43. return 0;
  44. (*pos) += 2;
  45. }
  46. (*pos)--;
  47. if (str[*pos] != '=') return 0;
  48. (*pos)++;
  49. return (*pos);
  50. }
  51.  
  52.  
  53. bool MainWindow::param(char* str, int* pos){
  54. *pos = checkname(str, pos);
  55. if(*pos == 0){
  56. return false;
  57. }
  58. if (isdigit(str[*pos])){
  59. (*pos)+=2;
  60. if(isdigit(str[*pos]) != 0){
  61. *pos = *pos + 1;
  62. return true;
  63. }
  64. else
  65. {
  66. printf("F1");
  67. return false;
  68. }
  69. }
  70. else if(str[*pos] == '('){
  71. param(str + 1, pos);
  72. *pos = *pos + 1;
  73. if(str[*pos] != ')')
  74. {
  75. return false;
  76. }
  77.  
  78. }
  79. else
  80. {
  81. printf("F2");
  82. return false;
  83. }
  84. }
  85.  
  86. void MainWindow::on_pushButton_clicked()
  87. {
  88. int* pos = new int(0);
  89. *pos=0;
  90. ui->good->clear();
  91. ui->bad->clear();
  92. QString str = ui->lineEdit->text();
  93. char* temp = new char[str.length() + 1];
  94. strncpy(temp, str.toStdString().c_str(), str.length());
  95. temp[str.length()] = '\0';
  96. bool res = param(temp, pos);
  97. int ch = ')';
  98. char *ach;
  99. ach=strrchr (temp,ch);
  100. if(res) //&& check_br(str)
  101. ui->good->setText("НЕТ ОШИБКИ");
  102. else
  103. {
  104. ui->bad->setText("ОШИБКА");
  105. ui->good->clear();
  106. }
  107. /*if(ach != NULL)
  108. {
  109. if(temp[ach-temp+1] != '\0')
  110. {
  111. ui->bad->setText("ОШИБКА");
  112. ui->good->clear();
  113. }
  114. }
  115. else
  116. {
  117. if(*pos != str.length())
  118. {
  119. ui->bad->setText("ОШИБКА");
  120. ui->good->clear();
  121. }
  122. }*/
  123. int mas[100];
  124. int j = 0;
  125. int k;
  126. for(int i = 0; i<strlen(temp) - 1;i++)
  127. {
  128. if(temp[i]==',')
  129. {
  130. k = i+2;
  131. res =param(temp,&k);
  132. if(!res)
  133. {
  134. ui->bad->setText("ОШИБКА");
  135. ui->good->clear();
  136. }
  137. }
  138. }
  139. }
  140.  
  141. void MainWindow::on_pushButton_2_clicked()
  142. {
  143. QMessageBox::about(this, "help", "Введите в поле строку, которую вы желаете проверить и нажмите кнопку проверки");
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement