Advertisement
nontawat1996

1069 stack

Sep 11th, 2011
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int main()
  5. {
  6.     char code[100001]={'\0'};
  7.     int i,j,n,total=0;
  8.     scanf("%d",&n);
  9.  
  10.     for(i=0;i<n;i++)
  11.     {
  12.         scanf("%s",&code[i]);
  13.         if(i>0)
  14.         {
  15.             if(code[i]==code[i-1])
  16.             {
  17.                 code[i]='\0';
  18.                 code[i-1]='\0';
  19.                 i-=2;
  20.                 n-=2;
  21.                 total+=2;
  22.             }
  23.         }
  24.     }
  25.     if(strlen(code)==0)
  26.     {
  27.         printf("0\nempty");
  28.         return 0;
  29.     }
  30.     printf("%d\n",strlen(code));
  31.  
  32.     for(i=strlen(code)-1;i>=0;i--)
  33.     {
  34.         printf("%c",code[i]);
  35.     }
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement