Page 4 of 4

Re: 446 WA -> so easy, but... PLEASE HELP!

Posted: Sat May 31, 2008 4:27 pm
by helloneo
fR0D wrote:do we hav to consider negative numbers???if yes wat will be the result of -20 + -20.
Well.. I'm not sure if we have to consider negative numbers..
But my output for the input "-20 + -20" is..

1111111100000 + 1111111100000 = -64

Re: 446 WA -> so easy, but... PLEASE HELP!

Posted: Sat May 31, 2008 9:03 pm
by fR0D
can u pls point wats wrong with my program???
it gives run time error.

Code: Select all

#include<iostream>
using namespace std;
#include<math.h>

int main()
{
    char h1[4],h2[4],t[1];
    char con[16][5]={"0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"};
    int val[16]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15},d1,d2,N,i,j,k,l1,l2;
    scanf("%d",&N);
    for (i=0;i<N;i++)
    {
        d1=0,d2=0;
        scanf("%s%s%s",&h1,&t,&h2);
        printf("0");
        for (j=3;j>strlen(h1);j--)
            printf("%s",con[0]);
        l1=strlen(h1);
        for (k=0;k<l1;k++,j--)
        {
            if (isdigit(h1[k]))
            {
               printf("%s",con[h1[k]-48]);
               d1+=(int)pow(16,j-1)*val[h1[k]-48];
            }
            else
            {
                printf("%s",con[h1[k]-55]); 
               d1+=(int)pow(16,j-1)*val[h1[k]-55]; 
            }
        }
        printf(" %c ",t[0]=='+'?'+':'-');
        printf("0");
        for (j=3;j>strlen(h2);j--)
            printf("%s",con[0]);
        l2=strlen(h2);
        for (k=0;k<l2;k++,j--)
        {
            if (isdigit(h2[k]))
            {
               printf("%s",con[h2[k]-48]);
               d2+=(int)pow(16,j-1)*val[h2[k]-48];
            }
            else
            {
                printf("%s",con[h2[k]-55]);
               d2+=(int)pow(16,j-1)*val[h2[k]-55]; 
            }
        }                         
        printf(" = %d\n",t[0]=='+'?d1+d2:d1-d2);      
    }
}

Re: 446 WA -> so easy, but... PLEASE HELP!

Posted: Sat Sep 13, 2008 11:25 am
by anondo_iut
check <math.h> will it be <cmath>??

Re: 446 WA -> so easy, but... PLEASE HELP!

Posted: Mon May 26, 2014 9:21 am
by uDebug
fR0D wrote:do we hav to consider negative numbers???
Nope. My AC program didn't. There's subtraction of two positive integers but nothing like

Code: Select all

-FA + -40
in the input.

The test cases by chunyi81 are great.

Re: 446 WA -> so easy, but... PLEASE HELP!

Posted: Mon May 26, 2014 9:27 am
by uDebug
fR0D wrote:can u pls point wats wrong with my program???
it gives run time error.
(1) Change

Code: Select all

scanf("%s%s%s",&h1,&t,&h2);
to

Code: Select all

scanf("%s%s%s",h1,t,h2);
(2) Remember that even though "t" is just a one character string, you need to allocate enough space for the null character as well.

(3) The code doesn't have the header file for "strlen".

Re: 446 WA -> so easy, but... PLEASE HELP!

Posted: Mon May 26, 2014 9:31 am
by uDebug
Ivo Sluganovic wrote:I am trying to solve the Kibbles ``n'' Bits ``n'' Bits ``n'' Bits problem.
It seems like a very easy problem, and it is, but I keep getting WA.
I coded it several times...
Please help me if you see any mistake...
I don't know what could be wrong in such short code.
Your code doesn't match the sample input / output.