boopathi

PEBBLES

Oct 18th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<vector>
  4. #include<csignal>
  5. #include<algorithm>
  6. #include<string>
  7. #include<cstring>
  8. #include<vector>
  9. #include<math.h>
  10. #include<map>
  11. #define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
  12. #define REP(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
  13. #define REV(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
  14. #define GI ({int t;scanf("%d",&t);t;})
  15. #define GL ({int64 t;scanf("%ld",&t);t;})
  16. #define PB push_back
  17. typedef long long int int64;
  18. using namespace std;
  19.  
  20. int main(){
  21.     char s[100000];
  22.     while(scanf("%s",s)) {
  23.         int l = strlen(s), start=-1, last=-1;
  24.         int count[100000]={0};
  25.         FOR(i,l) if(s[i]=='1') { start=i; last=1; count[i]=1; break; }
  26.         if(start == -1) {
  27.             cout<<0<<endl;
  28.             continue;
  29.         }
  30.         REP(i,start,l) {
  31.             bool odd = 1==count[i-1]%2, zero = '0'==s[i];
  32.             count[i] = count[i-1] + (((odd && zero) || (!odd && !zero)) ? 1 : 0);
  33.             last=count[i];
  34.         }
  35.         printf("%d\n",last);
  36.     }
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment