Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdio.h>
- int main(){
- char text[256];
- int i, length, error, no_rule;
- /*
- Rule 1: a*b
- Rule 2: ab+
- Rule 3: abb
- */
- repeat:
- i = 0;
- length = 0;
- error = 0;
- no_rule = 1;
- printf("Enter Text: ");
- scanf("%[^\n]s", text);
- length = strlen(text);
- if(strcmp(text, ";") == 0){
- return 0;
- }
- if(length > 0){
- if((text[0] == 'a' || text[0] == 'b') && text[length-1] == 'b'){
- error == 0;
- for(i = 1; i < length - 1; i++){
- if(text[i] != 'a'){
- error = 1;
- break;
- }
- }
- if(error == 0){
- printf("\nUnder Rule 1");
- no_rule = 0;
- }
- }
- if(text[0] == 'a' && text[1] == 'b'){
- error = 0;
- for(i = 1; i < length; i++){
- if(text[i] != 'b'){
- error = 1;
- break;
- }
- }
- if(error == 0){
- printf("\nUnder Rule 2");
- no_rule = 0;
- }
- }
- if(strcmp(text, "abb") == 0){
- printf("\nUnder Rule 3");
- no_rule = 0;
- }
- if(no_rule == 1){
- printf("\nUnder no rule!");
- }
- }
- printf("\n\n");
- fflush(stdin);
- goto repeat;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement