11185 - Ternary

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

Moderator: Board moderators

linux
Learning poster
Posts: 56
Joined: Sat Jul 01, 2006 12:21 pm
Location: CA-95054
Contact:

11185 - Ternary

Post 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:
Last edited by linux on Mon Jul 23, 2007 1:48 pm, edited 1 time in total.
Solving for fun..
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Post by sohel »

From problem statement.
Input is terminated by a line containing a negative value.
It might not end with -1.
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey »

"11185 OLE!!!!!!" is not the way to open a thread in this forum. Read the sticky post.
The biggest problem with most problems is not how to solve the problem, but how to not solve what is not the problem.
linux
Learning poster
Posts: 56
Joined: Sat Jul 01, 2006 12:21 pm
Location: CA-95054
Contact:

Post by linux »

Thanks very much for your help and to inform me about that. That's a good idea!
I got AC. :P
Last edited by linux on Thu Nov 13, 2008 3:33 pm, edited 1 time in total.
Solving for fun..
kana
New poster
Posts: 19
Joined: Mon Mar 13, 2006 6:03 pm
Location: dhaka

Post by kana »

i'm getting Runtime time error with this one....can anyone help me?

Code: Select all

    deleted
Last edited by kana on Wed Sep 12, 2007 9:14 pm, edited 2 times in total.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Why you are using such a big array?
Ami ekhono shopno dekhi...
HomePage
kana
New poster
Posts: 19
Joined: Mon Mar 13, 2006 6:03 pm
Location: dhaka

Post by kana »

is that the only problem in my code? with a smaller array size it shows invalid memory reference. what should i do?
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Your algorithm is not correct. Check your code for n=41. Hope it helps.
Ami ekhono shopno dekhi...
HomePage
oliveralderete
New poster
Posts: 3
Joined: Wed Aug 29, 2007 4:05 am
Contact:

none

Post 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!
kana
New poster
Posts: 19
Joined: Mon Mar 13, 2006 6:03 pm
Location: dhaka

Post by kana »

thnx jan & oliveralderete!!! i've got it acc :D
Md. Mijanur Rahman
New poster
Posts: 9
Joined: Thu Nov 13, 2008 2:08 pm

Re: 11185 - Ternary

Post by Md. Mijanur Rahman »

Thank you so much, I have got accepted now.
Last edited by Md. Mijanur Rahman on Thu Nov 13, 2008 6:28 pm, edited 1 time in total.
helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Re: 11185 - Ternary

Post by helloneo »

Well.. Maybe your code print an extra '\n' when n == 0 :-)


Ps. Remove your code after AC.. :-)
vahid sanei
Learning poster
Posts: 84
Joined: Fri Jan 09, 2009 4:37 pm
Location: IRAN

Re: 11185 - Ternary

Post 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
Impossible says I`m possible
ahmed
New poster
Posts: 9
Joined: Tue Mar 17, 2009 6:36 pm

Re: 11185 - Ternary

Post 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;
}

hemanth.avs
New poster
Posts: 1
Joined: Mon Jun 08, 2009 5:48 am

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

Post 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;
}




Post Reply

Return to “Volume 111 (11100-11199)”