Advertisement
urksiful

AFN to AFD v0.02

Dec 14th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.98 KB | None | 0 0
  1.  
  2. #include<stdio.h>
  3. #define MAX_STRLEN 256
  4. #define SIN_TIPO float
  5.  
  6.  
  7. /*Source code from the web and Uriel Cambrón Hernández*/
  8.  
  9. int main() {
  10.     SIN_TIPO afd[20][20];
  11.     char a_1[MAX_STRLEN];
  12.     char b[MAX_STRLEN];
  13.     int con;
  14.     int i;
  15.     int j;
  16.     int k;
  17.     float l;
  18.     int opc;
  19.     char x[MAX_STRLEN][10][10];
  20.     for (i=1;i<=10;i+=1) {
  21.         for (j=1;j<=10;j+=1) {
  22.             x[i][j]="0";
  23.         }
  24.     }
  25.     do {
  26.         printf("Menu\n");
  27.         printf("1.-Input nodes\n");
  28.         printf("2.-Input tags\n");
  29.         printf("3.-Input unions\n");
  30.         printf("4.-Show AFN Lenguaje\n");
  31.         printf("5.-Get AFD\n");
  32.         printf("6.-Get Regular Expresion\n");
  33.         printf("7.-Exit\n");
  34.         do {
  35.             scanf("%i",&opc);
  36.         } while (!(opc==1 || opc==2 || opc==3 || opc==4 || opc==6 || opc==5 || opc==7));
  37.         switch (opc) {
  38.         case 1:
  39.             printf("¿How many nodos? (1-10)?:  ");
  40.             scanf("%i",&k);
  41.             k=k+1;
  42.             for (i=2;i<=k;i+=1) {
  43.                 j=1;
  44.                 printf("Write nodos: %f",i-1);
  45.                 scanf("%s",x[i][j]);
  46.             }
  47.             break;
  48.         case 2:
  49.             printf("¿How many tags?(1-10)?:  ");
  50.             scanf("%f",&l);
  51.             l=l+1;
  52.             for (i=2;i<=l;i+=1) {
  53.                 j=1;
  54.                 printf("Write tags:  %f",i-1);
  55.                 scanf("%s",x[j][i]);
  56.             }
  57.             break;
  58.         case 3:
  59.             con=1;
  60.             for (i=2;i<=k;i+=1) {
  61.                 for (j=2;j<=l;j+=1) {
  62.                     printf("¿What nodo(s) points %s in the tag %s?:  ",x[i][j-con],x[1][j]);
  63.                     scanf("%s",x[i][j]);
  64.                     con=con+1;
  65.                 }
  66.                 con=1;
  67.             }
  68.             for (i=1;i<=k;i+=1) {
  69.                 for (j=1;j<=l;j+=1) {
  70.                     printf("%s  ",x[i][j]);
  71.                 }
  72.                 printf(" \n");
  73.             }
  74.             break;
  75.         case 4:
  76.             a_1=x[2][1];
  77.             b=x[k][1];
  78.             printf("¿Where is the inicial node?  ");
  79.             scanf("%s",a_1);
  80.             printf("¿What is the final node?
  81.             printf("L(A)=(");
  82.             printf("{");
  83.             for (i=2;i<=k;i+=1) {
  84.                 printf("[%s],",x[i][1]);
  85.             }
  86.             printf("},E,{");
  87.             for (j=2;j<=l;j+=1) {
  88.                 printf("%s,",x[1][j]);
  89.             }
  90.             printf("},%s,%s)\n",a_1,b);
  91.             break;
  92.         case 5:
  93.             printf("%s\n",a_1);
  94.             break;
  95.         case 6:
  96.             printf("%s\n",a_1);
  97.             break;
  98.         }
  99.     } while (opc!=7);
  100.     return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement