Page 4 of 7

Posted: Tue Jan 02, 2007 2:36 pm
by Spykaj

Code: Select all

128 10 2

Posted: Mon Jan 22, 2007 7:53 am
by stcheung
I have read all the related threads and also tried all the sample inputs given but couldn't understand why I am getting PE. My output is exactly the same as the sample outputs posted in this forum.

Below is my code for doing the output. I tried both adding and not adding a blank line at the end, but no luck. Any special case? Thanks.

Code: Select all

if(result == "")
        	result = "0";
       	if(result.length() > 7)
       		cout << "  ERROR";
       	else cout << setw(7) << setiosflags(ios::right) << result;
       	cout << "\n";

Posted: Mon Jan 22, 2007 5:15 pm
by Darko

Posted: Tue Jan 23, 2007 6:14 am
by stcheung
Haha you are correct, I did miss that one because I limited my search to the Volume3 Forum only. Thanks a lot!

389 Basically Speaking - Presentation Error

Posted: Tue Jan 30, 2007 1:09 am
by x140l31
Hi! Can someone help me? I have read a lot of posts of this problem, but they're about WA, and my problem is PE =/

Code: Select all

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;


int number(char n) {
	if (n <= '9' and n >= '0') return n - '0';
	return n - 'A' + 10;
}


char num_b(int n) {
	if (n <= 9 and n >= 0) return '0' + n;
	return 'A' + n - 10;
}


int base_a_to_dec(string n, int a) {
	int s = n.size();
	int dec = 0;
	for (int i = 0; i < s; ++i) dec = dec*a + number(n[i]);
	return dec;
}


void base_dec_to_b(int dec, int b, int w) {
	if (dec < b) cout << setw(w) << num_b(dec%b);
	else {
		base_dec_to_b(dec/b, b, w - 1);
		cout << num_b(dec%b);
	}
}


int main() {
	string num;
	while (cin >> num) {
		int a, b;
		cin >> a >> b;
		int n = base_a_to_dec(num, a);
		if (b*b*b*b*b*b*b <= n) cout << setw(7) << "ERROR" << endl;
		else {
			base_dec_to_b(n, b, 7);
			cout << endl;
		}
	}
}
Help please! :(

Posted: Fri Feb 16, 2007 2:05 pm
by NightFir

Posted: Mon Feb 19, 2007 8:45 pm
by x140l31
thanks for reply... you think that my presentation error was the

setw(7) << "ERROR"

??? I also tried

cout << " ERROR" << endl;

and it also says PE =/

My code is getting WA

Posted: Fri Apr 13, 2007 5:01 pm
by mrunmoy
_.B._ my code passed all your test cases which you have given in other 389 posts but i am still getting WA:-

Help!

Code: Select all

/* Hided */
i need more test inputs to fail my code. i have tried all the test inputs available on all the 389 posts here and get the correct result but get WA by online judge!

thanks to everyone! i got AC

the problem: i was not printing a '\n' at the end

Posted: Tue May 15, 2007 1:39 pm
by x140l31
sorry to post two times but can anyone help me please? xD

Posted: Mon Jul 16, 2007 6:32 am
by chetan
i am getting WA :(( :((

please help me

Code: Select all

CODE DELETED AFTER AC :)

Posted: Mon Jul 16, 2007 8:29 am
by chetan
well i got AC . but again time is very bad :( 1.4 s
as far as implementation goes i use a look up table. thats much faster.
should i go in for optimizations or is there any other algo available ????

Posted: Mon Feb 25, 2008 8:28 pm
by fR0D
my program is giving RE plz help me...

Code: Select all

Code Deleted after AC

Posted: Tue Feb 26, 2008 9:53 am
by CSEDU_1323
hi,
increase num nnum array size & initialize inum to 0 just after input
doing that i got ur code ac

hope this help

Posted: Tue Feb 26, 2008 3:19 pm
by fR0D
thnx vry much it helped :)

Why WA in 389 ??

Posted: Tue Jun 17, 2008 11:59 am
by newton
i cant find any bug. May anybody help me.

Code: Select all

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

int main()
{
	//freopen("in.txt","rt",stdin);
	char base16[]= "0123456789ABCDEF",num[10000];
	int convertedNum[10000],i,j,originalNum,givenBase,base;
	while(scanf("%s %d %d",num,&givenBase,&base) == 3){			
		originalNum = 0;		
		int len = strlen(num);
		for(i = 0;i < len;i++){
			if(num[i] <= '9' && num[i] >= '0' )
				originalNum = originalNum * givenBase + (num[i] - '0');
			else if(num[i] <= 'F' && num[i] >= 'A')
				originalNum = originalNum * givenBase + (num[i] - 'A' + 10);
		}
		if(originalNum == 0){
			printf("      0\n");
			continue;
		}
		for(i = 0; originalNum; i++)
		{
			convertedNum[i] = originalNum % base;
			originalNum /= base;
		}
		i--;
		if(i > 7){
			printf("  ERROR\n");
			continue;
		}
		for(j = 0; j < 6 - i; j++)
			printf(" ");
		
		while(i >= 0)
		{
			printf("%c",base16[convertedNum[i]]);
			i--;
		}
		printf("\n");
	}
	//fclose(stdin);
	return 0;
}