389 - Basically Speaking

All about problems in Volume 3. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Shihab
New poster
Posts: 33
Joined: Thu Jun 13, 2013 1:19 pm

Re: 389

Post by Shihab » Wed Apr 02, 2014 11:23 am

Still WA

Code: Select all

#include<cstdio>
#include<cstring>
#include<iostream>

using namespace std;

long long  power(int base,long long p)
{
    long long i=0,result=1;

    for(; i<p; i++)
    {
        result*=base;
    }


    return result;

}

int char_to_int(char c)
{
    return c-55;
}

int f1(int n)
{
    return 55+n;
}

void f(long long number,int base2)
{
    char string1[100000],string2[100000],error[10]={'E','R','R','O','R','\0'};
    int i=0,j,k;

    while(number!=0)
    {
        string1[i]=(number%base2)+'0';
        //printf("%c\n",string1[i]);

        if((number % base2) >9)
        {
            string1[i]=f1(number%base2);
        }

        i++;

        number/=base2;
    }
    string1[i]='\0';

    if(i>7)
        printf("%7s\n",error);
    else
    {

        i--;

        j=0;
        while(i>=0)
        {
            string2[j++]=string1[i--];
        }

        string2[j]='\0';

        printf("%7s\n",string2);

    }

}


long long  base_convert(char s[],long long len,int base)
{

    int i=0;
    long long temp;
    long long base2_number=0;

    while(s[i]!='\0')
    {
        temp=s[i]-'0';

        if(s[i]>='A' && s[i]<='Z')
            temp=char_to_int(s[i]);

        base2_number+=(temp * power(base,len));
        len--;

        i++;
    }


    return base2_number;
}

int main()
{

    long long base1,base2,flag,base2_number,len,v,i;

    char base1_number[100000];

    while(scanf("%s %lld %lld",base1_number,&base1,&base2)==3)
    {

        i=0;
        flag=0;
        v=0;

        if(base1_number[0]=='0')
            printf("%7lld\n",v);
        else
        {
//            while(base1_number[i]!='\0')
//            {
//                v=base1_number[i]-'0';
//
//                if(base1_number[i]>='A' && base1_number[i]<='Z')
//                    v=char_to_int(base1_number[i]);
//
//                i++;
//
//            }

            //if(!flag)
            {
                len=strlen(base1_number)-1;

                base2_number=base_convert(base1_number,len,base1);

                if(base2==10)
                {
                    printf("%7lld\n",base2_number);
                }
                else
                {

                    f(base2_number,base2);

                }

            }

        }


    }

    return 0;
}


brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 389

Post by brianfry713 » Thu Apr 03, 2014 11:34 pm

Input 01 10 10
Output should be 1
Check input and AC output for thousands of problems on uDebug!

Shihab
New poster
Posts: 33
Joined: Thu Jun 13, 2013 1:19 pm

Re: 389

Post by Shihab » Fri Apr 04, 2014 5:30 pm

Thanks Bryanfry713 , AC

Nakar81
New poster
Posts: 7
Joined: Sun Sep 18, 2016 6:40 pm

Re: 389 - Basically Speaking

Post by Nakar81 » Sun Sep 18, 2016 7:44 pm

I have tried to solve the problem in multiple ways without success (RE and TL).

I put my code (RE):

Code: Select all

REMOVE AFTER AC
Can somebody help me?
Last edited by Nakar81 on Sat Nov 12, 2016 9:11 pm, edited 1 time in total.

Nakar81
New poster
Posts: 7
Joined: Sun Sep 18, 2016 6:40 pm

Re: 389 - Basically Speaking

Post by Nakar81 » Sat Nov 12, 2016 4:44 pm

Solve

Post Reply

Return to “Volume 3 (300-399)”