Simple operation of Oj-244-16 in Nanyang

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.