ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
1#include<stdio.h>
 2#include<string.h>
 3#include<stdlib.h>
 4void main(void){
 5
 6 int a, j=0, i;
 7
 8 char enter[50], test[50];
 9
10 scanf("%s",enter);
11
12 a=strlen(enter);
13
14 for(i=0;i<a;i++){
15
16       if(a%2==1){
17
18     printf("%sn", enter);
19
20     printf("Error");
21
22           break;
23
24     }
25
26
27      if(enter[i]=='('||enter[i]=='['||enter[i]=='{'){
28
29          test[j]=enter[i];
30
31          j++;
32
33      }
34
35      if(enter[i]==')'){
36
37          if(test[j-1]=='('){
38
39            j--;
40
41            test[j]='0';
42
43       }
44
45       else if(test[j-1]=='['||test[j-1]=='{'){
46
47            printf("%sn", enter);
48
49            printf("Error");
50
51            break;
52
53       };
54
55   }
56
57   if(enter[i]==']'){
58
59       if(test[j-1]=='['){
60
61               j--;
62
63            test[j]='0';
64
65       }
66
67       else if(test[j-1]=='('||test[j-1]=='{'){
68
69            printf("%sn", enter);
70
71            printf("Error");
72
73            break;
74
75       };
76
77       }
 78
 79       if(enter[i]=='}'){
 80
 81           if(test[j-1]=='{'){
 82
 83                j--;
 84
 85                test[j]='0';
 86
 87           }
 88
 89           else if(test[j-1]=='('||test[j-1]=='['){
 90
 91                printf("%sn", enter);
 92
 93                printf("Error");
 94
 95                break;
 96
 97           };
 98
 99       }
100
101   }
102
103   if(test[0]=='0'){
104
105       printf("%sn", enter);
106
107       printf("Correct");
108
109   }
110
111   system("pause");
112
113   }

More Related Content

³ÌʽÂë²âÊÔ

  • 1. 1#include<stdio.h> 2#include<string.h> 3#include<stdlib.h> 4void main(void){ 5 6 int a, j=0, i; 7 8 char enter[50], test[50]; 9 10 scanf("%s",enter); 11 12 a=strlen(enter); 13 14 for(i=0;i<a;i++){ 15 16 if(a%2==1){ 17 18 printf("%sn", enter); 19 20 printf("Error"); 21 22 break; 23 24 } 25 26 27 if(enter[i]=='('||enter[i]=='['||enter[i]=='{'){ 28 29 test[j]=enter[i]; 30 31 j++; 32 33 } 34 35 if(enter[i]==')'){ 36 37 if(test[j-1]=='('){ 38
  • 2. 39 j--; 40 41 test[j]='0'; 42 43 } 44 45 else if(test[j-1]=='['||test[j-1]=='{'){ 46 47 printf("%sn", enter); 48 49 printf("Error"); 50 51 break; 52 53 }; 54 55 } 56 57 if(enter[i]==']'){ 58 59 if(test[j-1]=='['){ 60 61 j--; 62 63 test[j]='0'; 64 65 } 66 67 else if(test[j-1]=='('||test[j-1]=='{'){ 68 69 printf("%sn", enter); 70 71 printf("Error"); 72 73 break; 74 75 }; 76
  • 3. 77 } 78 79 if(enter[i]=='}'){ 80 81 if(test[j-1]=='{'){ 82 83 j--; 84 85 test[j]='0'; 86 87 } 88 89 else if(test[j-1]=='('||test[j-1]=='['){ 90 91 printf("%sn", enter); 92 93 printf("Error"); 94 95 break; 96 97 }; 98 99 } 100 101 } 102 103 if(test[0]=='0'){ 104 105 printf("%sn", enter); 106 107 printf("Correct"); 108 109 } 110 111 system("pause"); 112 113 }