Advertisement
FoxTuGa

Matriculas

May 8th, 2011
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.38 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #define TRUE 1
  4.  
  5. int _Val(int Num, int LimitInf, int LimitSup);
  6. int _Toupper(char x);
  7.  
  8. int main()
  9. {
  10.     /// Declaracao e Iniciliazacao de variaveis.
  11.     int Formato1, N1, N2, N3, N4, Formato2, count;
  12.     int n1, n2, n3, n4, temp;
  13.     char X1, X2, X3, X4, x2, x1;
  14.     Formato1 = N1 = N2 = N3 = N4 = Formato2 = count = temp = x2 = n1 = n2 = x1 = 0;
  15.     /////
  16.  
  17.     /// Input e Validacao da Matricula 1
  18.     printf("Indique o Formato (M1): ");
  19.     fflush(stdin);
  20.     scanf("%d", &Formato1);
  21.    
  22.     // Escolha do tipo de Matricula
  23.     printf("Introduza a Matricula (M1): ");
  24.     fflush(stdin);
  25.     switch(Formato1)
  26.     {
  27.     case 1: scanf("%c%c-%d-%d", &X1, &X2, &N1, &N2);;break;
  28.     case 2: scanf("%d-%d-%c%c", &N1, &N2, &X1, &X2);break;
  29.     case 3: scanf("%d-%c%c-%d", &N1, &X1, &X2, &N2);break;
  30.     default: printf("\nErro\n"); return 0;
  31.     }
  32.  
  33.     X1 = _Toupper(X1);
  34.     X2 = _Toupper(X2);
  35.  
  36.     // Validacao
  37.     if( !_Val(N1,0,99) || !_Val(N2,0,99) || !_Val(X1,'A','Z') || !_Val(X2,'A','Z') )
  38.     {
  39.         printf("\nErro\n");
  40.         return 0;
  41.     }
  42.     /////
  43.  
  44.     /// Input e Validacao da Matricula 2
  45.     printf("Indique o Formato (M2): ");
  46.     fflush(stdin);
  47.     scanf("%d", &Formato2);
  48.    
  49.     // Escolha da Matricula 2
  50.     printf("Introduza a Matricula (M2): ");
  51.     fflush(stdin);
  52.     switch(Formato2)
  53.     {
  54.     case 1: scanf("%c%c-%d-%d", &X3, &X4, &N3, &N4);;break;
  55.     case 2: scanf("%d-%d-%c%c", &N3, &N4, &X3, &X4);break;
  56.     case 3: scanf("%d-%c%c-%d", &N3, &X3, &X4, &N4);break;
  57.     default: printf("\nErro\n"); return 0;
  58.     }
  59.  
  60.     X3 = _Toupper(X3);
  61.     X4 = _Toupper(X4);
  62.  
  63.     // Validacao da Matricula 2
  64.     if( !_Val(N3,0,99) || !_Val(N4,0,99) || !_Val(X3,'A','Z') || !_Val(X4,'A','Z') )
  65.     {
  66.         printf("\nErro\n");
  67.         return 0;
  68.     }
  69.     /////
  70.    
  71.     for(x1 = X1; x1 <= X3 ; x1++)
  72.     {
  73.         for(x2 = 'A'; x2 < 'Z'+1 ; x2++)
  74.         {
  75.             if( temp == 0 )
  76.                     x2 == X2;
  77.             for(n1 = 0; n1 <= 99 ; n1++)
  78.             {
  79.                 if( temp == 0 )
  80.                     n1 == N1;
  81.                 for(n2 = 0; n2 <= 99 ; n2++)
  82.                 {
  83.                     if( temp == 0 )
  84.                     {
  85.                         temp++;
  86.                         n2 = N2;
  87.                     }
  88.                     if( n2 == N4 && n1 == N3 )
  89.                         break;
  90.                 }
  91.                 count += n2;
  92.                 if( n2 == N4 && n1 == N3 && x2 == X4)
  93.                     break;
  94.             }
  95.             if( n2 == N4 && n1 == N3 && x2 == X4 && x1 == X3)
  96.                     break;
  97.         }
  98.     }
  99.    
  100.     printf("\n %d \n", count);
  101.  
  102.  
  103.     return 0;
  104. }
  105.  
  106. int _Val(int Num, int LimitInf, int LimitSup)
  107. {
  108.     return (Num >= LimitInf && Num <= LimitSup) ? 1 : 0;
  109. }
  110.  
  111. int _Toupper(char x)
  112. {
  113.     return (x >= 'a' && x <= 'z') ? x+32 : x;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement