input code

not sure how to test my code with a string such as 010101100 or 011. not sure how to code the test.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
#define NSTATES 3
#define NCHARS 2
#define NACCEPTS 1
int L[NSTATES][NCHARS]={{0,1},{0,2},{0,2}};
int ACCEPTS[NACCEPTS]={2};

main(){
int state,ch,i;

for (state=0; (ch=getchar())!= -1&&ch!='\n';state=L[state][i])
  {i=ch-'0';}

     for(i=0;i<NACCEPTS;i++) 
     if(ACCEPTS[i]==state)
       {printf("yes\n");return(0);}

     printf("no\n");


     return(0);
}
me either.

maybe you can explain what it is supposed to do.
the code recognizes the input string (010101100 or 011) in which case it says yes, or no if it does not. I though that maybe something like:

1
2
3
4
5
6
7
8
int main() {
  unsigned short b = BOOST_BINARY (10010);
  char buf[sizeof(b)*8+1];
  printf(“bin: %16s\n", b, b, b, itoa(b, buf, 2));
  cout << setfill('0') <<
    "bin: " << bitset< 16 >(b) << endl;
  return 0;
 


but Im not sure

Topic archived. No new replies allowed.