11185 - Ternary

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

Moderator: Board moderators

Re: 11185 - Ternary

Postby helloneo » Mon Jun 08, 2009 4:25 pm

Try this case..

Code: Select all
3
-1



My output..

Code: Select all
10
helloneo
Guru
 
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Re: 11185 - Ternary Why W/A

Postby noor_aub » Fri May 28, 2010 7:57 am

I know My Algorithm is right, Then Why wrong answer

Code: Select all
Thanks Sohel. I forget the basic rules of Checking Input range.
Code Remove After A/C
Last edited by noor_aub on Fri May 28, 2010 3:19 pm, edited 1 time in total.
noor_aub
New poster
 
Posts: 26
Joined: Sat Aug 22, 2009 12:16 pm

Re: 11185 - Ternary

Postby sohel » Fri May 28, 2010 10:22 am

What does your program output if the input is 0?
Hint: When you get WA in a problem, try to check the extreme cases first( In this case 0 and 1000000000)
User avatar
sohel
Guru
 
Posts: 862
Joined: Thu Jan 30, 2003 5:50 am
Location: University of Texas at San Antonio

Re: 11185 - Ternary

Postby shaon_cse_cu08 » Wed Jul 28, 2010 7:50 am

Can Someone Help me to determine what is wrong with my code... I have tested several case... :( :(
Code: Select all
Code Removed After AC....


I didn't think of the out put 0 when the case is 0... :)
It's not who i m inside me... But what i do, that defines me...:)
shaon_cse_cu08
New poster
 
Posts: 47
Joined: Tue May 25, 2010 9:10 am

Re: 11185 - Ternary

Postby ratul.i » Mon Jul 23, 2012 1:17 am

Can anyone please tell me why I get runtime error for this code:

Code: Select all
#include<stdio.h>

void reverse(char *num, int count)
{
    while(count>=0)
    {
        printf("%c",num[count]);
        count--;
    }
}

int main()
{
    long int a;

    while(1)
    {
        scanf("%ld",&a);

        if(a<0)
            break;
        else if(a==0)
            printf("0\n");
        else
        {
            char *c; int i=0;
            while(a>=1)
            {
                long int x = a%3;
                c[i]=x+'0';
                a /= 3;
                i++;
            }
            reverse(c, i-1);
            printf("\n");
        }
    }

    return 0;
}

ratul.i
New poster
 
Posts: 2
Joined: Mon Jul 23, 2012 1:14 am

Re: 11185 - Ternary

Postby brianfry713 » Tue Jul 24, 2012 1:41 am

instead of
Code: Select all
char *c;

try
Code: Select all
char c[MAXSIZE];
brianfry713
Guru
 
Posts: 1771
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11185 - Ternary

Postby ratul.i » Tue Jul 24, 2012 2:10 am

Thnx, Thnx a lot brianfry713 ... Accepted :D
ratul.i
New poster
 
Posts: 2
Joined: Mon Jul 23, 2012 1:14 am

Re: 11185 - Ternary

Postby Nahian37 » Sun Oct 14, 2012 11:50 am

#include<stdio.h>
int main()
{
long n,i,j,a[50];
while(1)
{
scanf("%ld",&n);
if(n<=0) break;

for(i=0;n>0;i++)
{
a[i]=n%3;
n=n/3;
}
for(j=i-1;j>=0;j--)
{
printf("%ld",a[j]);
}
printf("\n");
}
return 0;
}
whats the problem with this code?
Nahian37
New poster
 
Posts: 2
Joined: Sun Oct 14, 2012 11:45 am

Re: 11185 - Ternary

Postby brianfry713 » Tue Oct 16, 2012 1:19 am

For input:
Code: Select all
0
-1
AC output:
Code: Select all
0
brianfry713
Guru
 
Posts: 1771
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11185 - Ternary

Postby shuvrothpol1 » Thu Oct 25, 2012 9:28 am

I've accepted this problem after 3 times compiler error.But i can't find out the problem why the code is compiled error. For this I ignore the string.h function and do the task manually and got accepted . But still now I am in fix why I can't use strrev() function ? my previous code given below:

#include <stdio.h>
#include <string.h>

int main ()

{
char str [50];
int n,i;
scanf ("%d",&n);

while (n>=0){

i=0;
if (n==0){
str[i]=0;
str[i++]+=48;
}

while (n!=0){
str[i]=n%3;
str[i++]+=48;
n/=3;
}
str[i]='\0';

printf ("%s\n",strrev(str));
scanf ("%d",&n);

}
return 0;
}
shuvrothpol1
New poster
 
Posts: 17
Joined: Wed Aug 15, 2012 12:37 pm

Re: 11185 - Ternary

Postby brianfry713 » Fri Oct 26, 2012 12:22 am

strrev isn't supported in the judge's compiler.
brianfry713
Guru
 
Posts: 1771
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11185 - Ternary

Postby shuvrothpol1 » Fri Oct 26, 2012 9:13 pm

Tnx sir.....
shuvrothpol1
New poster
 
Posts: 17
Joined: Wed Aug 15, 2012 12:37 pm

Previous

Return to Volume CXI

Who is online

Users browsing this forum: No registered users and 1 guest