Advertisement
nontawat1996

Untitled

Sep 11th, 2011
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 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,check=1,total=0;
  8.     scanf("%d",&n);
  9.  
  10.     for(i=0; i<n; i++)
  11.     {
  12.         scanf("%s",&code[i]);
  13.     }
  14.  
  15.     for(i=0; i<n; i++)
  16.     {
  17.         for(j=check; j<n; j++)
  18.         {
  19.             if(code[check]==code[i] && code[i]!='1')
  20.             {
  21.                 code[i]='1';
  22.                 code[check]='1';
  23.                 total+=2;
  24.                 i-=1;
  25.             }
  26.             else
  27.             {
  28.                 i=check-1;
  29.                 check++;
  30.                 break;
  31.             }
  32.             check++;
  33.         }
  34.     }
  35.     //printf("%s %d\n",code,total);
  36.     if(strlen(code)-total==0)
  37.     {
  38.         printf("0\nempty");
  39.         return 0;
  40.     }
  41.  
  42.     printf("%d\n",strlen(code)-total);
  43.     for(i=strlen(code)-1;i>=0;i--)
  44.     {
  45.         if(code[i]!='1') printf("%c",code[i]);
  46.     }
  47.  
  48.  
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement