Simple operation time limit for 16 binary:MS | Memory limit:65535 KB Difficulty:1
-
Describe
-
now I'm going to give you a 16-in-a-plus-minus expression that requires the result of a 8-input expression.
-
-
Input
-
The
-
first line enters a positive integer T (0<t<100000)
Next there is t line, each line input a string s (length less than 15) string has two numbers and a plus or a minus, and the expression is legal and all operations are less than 31 bits
-
-
Output
-
-
Each expression output takes one row, and the result of the output expression 8 binary.
-
-
Sample input
-
-
329+482318be+67844ae1-3d6c
-
-
Sample output
-
441141001026565
I want to take this problem to practice the conversion of the system, read the best code to know that C language has a direct hexadecimal, octal placeholder
My Code
#include <iostream>#include<cstdio>using namespacestd;intFdfCharc) { if(c >='a') returnC-'a'+Ten; Else returnC-'0';}intMain () {intN; CharC; scanf ("%d",&N); GetChar (); while(n--) { intA =0, B =0, d =0, sign =-1; while(1{//a is the core of the binary-to-10 binary is the d=x*a^n+y*a^n-1+..................+z*a^0 scanf ("%c",&c); if(c = ='+'|| c = ='-') Break; A= A * -+HD (c); } if(c = ='+') Sign=1; Else Sign=0; while(1) {scanf ("%c",&c); if(c = ='\ n') Break; b= b* -+HD (c); } if(sign) d = A +b; ElseD = A-b; printf ("%o\n", D); }}
Best code:
on. #include <stdio.h> Geneva.intMain ()Geneva. {Geneva.intT; to. scanf ("%d",&T); .. while(t--) -. { ,.inta,b,d; the.CharC;Ten. scanf ("%x%c%x",&a,&c,&b); One.if(c=='+') d=a+b; A.Elsed=a-b; -.if(d>=0) -. printf ("%o\n", d); the.Elseprintf"-%o\n",-d); -.} -.}
Simple operation of Oj-244-16 in Nanyang