Page 1 of 3

11185 - Ternary

Posted: Mon Jul 23, 2007 8:06 am
by linux
I'm getting Output limit exceed. Can you suggest why?

Code: Select all

#include<stdio.h>

main () {
	long long n;
	short ind,res[1000],i;
	
	while (scanf("%lld",&n) && n!=-1) {
		ind =0;
                [removed after AC.
	}

	return 0;
}
:oops:

Posted: Mon Jul 23, 2007 8:34 am
by sohel
From problem statement.
Input is terminated by a line containing a negative value.
It might not end with -1.

Posted: Mon Jul 23, 2007 9:08 am
by little joey
"11185 OLE!!!!!!" is not the way to open a thread in this forum. Read the sticky post.

Posted: Mon Jul 23, 2007 1:47 pm
by linux
Thanks very much for your help and to inform me about that. That's a good idea!
I got AC. :P

Posted: Sun Aug 26, 2007 9:09 pm
by kana
i'm getting Runtime time error with this one....can anyone help me?

Code: Select all

    deleted

Posted: Tue Aug 28, 2007 2:07 pm
by Jan
Why you are using such a big array?

Posted: Tue Aug 28, 2007 9:44 pm
by kana
is that the only problem in my code? with a smaller array size it shows invalid memory reference. what should i do?

Posted: Tue Aug 28, 2007 9:53 pm
by Jan
Your algorithm is not correct. Check your code for n=41. Hope it helps.

none

Posted: Wed Sep 05, 2007 11:10 am
by oliveralderete
1000000000 = 2120200200021010001
try it!
:roll:

remember end of input is a NEGATIVE number.

i got AC just doing a recursive func two lines code.

sorry, my english is not very well!

Posted: Wed Sep 12, 2007 9:17 pm
by kana
thnx jan & oliveralderete!!! i've got it acc :D

Re: 11185 - Ternary

Posted: Thu Nov 13, 2008 2:18 pm
by Md. Mijanur Rahman
Thank you so much, I have got accepted now.

Re: 11185 - Ternary

Posted: Thu Nov 13, 2008 4:33 pm
by helloneo
Well.. Maybe your code print an extra '\n' when n == 0 :-)


Ps. Remove your code after AC.. :-)

Re: 11185 - Ternary

Posted: Fri Feb 06, 2009 10:31 am
by vahid sanei
here is my Acc code

Code: Select all

 code removed by moderator!
i want know other solution for converting a numbers to other base
thanks in advance

Re: 11185 - Ternary

Posted: Sun Mar 22, 2009 7:16 pm
by ahmed
I don't know why I am getting WA.As far as I know my logic is right.Please give me any suggestion about why I am getting WA.My code is given below:-

Code: Select all

#include<iostream>
#include<cmath>

using namespace std;

int main(void)
{
	double num,ter,b;

	while(cin >> num)
	{
		if(num<0.00)
			break;
		else
		{
			ter=0.0;
			for(b=1.0;num>2.0;num=floor(num/3.0),b*=10.0)
			{
				ter+=(fmod(num,3.0))*b;
			}
			ter+=num*b;
			printf("%.0lf\n",ter);
		}
	}
	return 0;
}


Re: 11185 - Ternary- plz provide me some test cases

Posted: Mon Jun 08, 2009 5:54 am
by hemanth.avs
I don't know why I am getting WA.As far as I know my logic is right.Please give me any suggestion about why I am getting WA.My code is given below:-

Code: Select all


#include<iostream>
using namespace std;
int main()
{
long long num;
cin >> num;
while(num>=0)
{	
long long sum = 0;
while(num!=0)
{
long long rem;
rem = num%3;
num = num/3;
sum = 10*sum + rem;
}
while(sum!=0)
{	
long long rem;
rem = sum%10;
sum = sum/10;
num = 10*num + rem;
}	
cout << num << endl;
cin >> num;
}
return 0;
}