Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int main()
  5. {
  6.    
  7.     int dias=0,i=0,x=0,y=0,cont=0;
  8.  
  9.     scanf("%d", &dias);
  10.     char letra[dias];
  11.    
  12.  
  13.         for(i=0;i<dias;i++)
  14.         {
  15.             scanf("%s", &letra[i]);
  16.  
  17.                 switch(letra[i])
  18.                 {
  19.                     case 'D':
  20.                     {
  21.                         x++;
  22.                         if(x > y)
  23.                         {
  24.                             if(x-1 == y && x-2 < y)  
  25.                             {
  26.                                 if(letra[i-1] != 'C')
  27.                                 {
  28.                                     cont++;
  29.                                 }
  30.                             }
  31.  
  32.                         }
  33.                         break;
  34.                     }
  35.                     case 'C':
  36.                     {
  37.                         y++;
  38.                         if(x < y)
  39.                         {
  40.                             if(y-1 == x && y-2 < x)
  41.                             {
  42.                                 if(letra[i-1] != 'D')
  43.                                 {
  44.                                     cont++;
  45.                                 }
  46.                             }
  47.                         }
  48.                         break;
  49.                     }
  50.                 }
  51.         }
  52.     if(cont==0)
  53.         {  
  54.             printf("%d", cont);
  55.         }
  56.     else
  57.         {
  58.             printf("%d", cont-1);
  59.         }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement