Page 2 of 3
Re: 11185 - Ternary
Posted: Mon Jun 08, 2009 4:25 pm
by helloneo
Try this case..
My output..
Re: 11185 - Ternary Why W/A
Posted: Fri May 28, 2010 7:57 am
by noor_aub
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
Re: 11185 - Ternary
Posted: Fri May 28, 2010 10:22 am
by sohel
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)
Re: 11185 - Ternary
Posted: Wed Jul 28, 2010 7:50 am
by shaon_cse_cu08
Can Someone Help me to determine what is wrong with my code... I have tested several case...
I didn't think of the out put 0 when the case is 0...

11185 - ternary
Posted: Sat Dec 10, 2011 12:37 pm
by desperate12
Why I have got WA I can't understand ... ...
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
int main()
{
long long a;
int ternary[200],i,j;
while(cin>>a)
{
if(a<0)
{
return 0;
}
if(a==0)
{
cout<<'0'<<endl;
}
else
{
for(i=0;a>0;i++)
{
ternary=a%3;
a=a/3;
}
for(j=i-1;j>=0;j--)
{
cout<<ternary[j];
}
}
cout<<endl;
}
return 0;
}
Re: 11185 - ternary
Posted: Fri Jan 13, 2012 1:47 am
by brianfry713
You're printing an extra newline for N=0.
Re: 11185 - Ternary
Posted: Mon Jul 23, 2012 1:17 am
by ratul.i
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;
}
Re: 11185 - Ternary
Posted: Tue Jul 24, 2012 1:41 am
by brianfry713
Re: 11185 - Ternary
Posted: Tue Jul 24, 2012 2:10 am
by ratul.i
Thnx, Thnx a lot brianfry713 ... Accepted

Re: 11185 - Ternary
Posted: Sun Oct 14, 2012 11:50 am
by Nahian37
#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=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?
Re: 11185 - Ternary
Posted: Tue Oct 16, 2012 1:19 am
by brianfry713
Re: 11185 - Ternary
Posted: Thu Oct 25, 2012 9:28 am
by shuvrothpol1
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=0;
str[i++]+=48;
}
while (n!=0){
str=n%3;
str[i++]+=48;
n/=3;
}
str='\0';
printf ("%s\n",strrev(str));
scanf ("%d",&n);
}
return 0;
}
Re: 11185 - Ternary
Posted: Fri Oct 26, 2012 12:22 am
by brianfry713
strrev isn't supported in the judge's compiler.
Re: 11185 - Ternary
Posted: Fri Oct 26, 2012 9:13 pm
by shuvrothpol1
Tnx sir.....
Re: 11185 - Ternary
Posted: Tue Jul 23, 2013 2:35 pm
by raihan_sust5
any one please give some critical test case so i can test my code.....i am having a wrong answer..
