Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <math.h>
- int main(){
- char in[33];
- int tc;
- scanf("%d",&tc);
- for(int i=1;i<=tc;i++){
- int index = 0;
- long long res = 0;
- scanf(" %s",in);
- char bin[strlen(in)];
- for(int j=0;j<strlen(in);j++){
- if(in[j]=='1' || in[j]=='0'){
- bin[index++] = in[j];
- }
- if(in[j]=='('){
- bin[index++] = '-';
- j+=3;
- }
- }
- int digs = index-1;
- for(int j=0;j<index;j++){
- if(bin[j]=='1'){
- res+=pow(2,digs);
- }
- if(bin[j]=='-'){
- res-=pow(2,digs);
- }
- digs--;
- }
- printf("Case #%d: %lld\n",i,res);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment