389 - Basically Speaking

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

Moderator: Board moderators

Spykaj
New poster
Posts: 47
Joined: Sun May 21, 2006 12:13 pm

Post by Spykaj »

Code: Select all

128 10 2
stcheung
Experienced poster
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am
Contact:

Post 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";
Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

stcheung
Experienced poster
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am
Contact:

Post by stcheung »

Haha you are correct, I did miss that one because I limited my search to the Volume3 Forum only. Thanks a lot!
x140l31
Learning poster
Posts: 69
Joined: Tue Jan 30, 2007 12:51 am

389 Basically Speaking - Presentation Error

Post 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! :(
NightFir
New poster
Posts: 5
Joined: Thu Feb 17, 2005 2:01 pm

Post by NightFir »

x140l31
Learning poster
Posts: 69
Joined: Tue Jan 30, 2007 12:51 am

Post 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 =/
mrunmoy
New poster
Posts: 17
Joined: Mon Apr 09, 2007 3:11 pm
Location: India
Contact:

My code is getting WA

Post 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
Best Regards,
Mrunmoy.

I belong to { IDIOTS }
IDIOTS - Intelligent Dynamic & Innovative On-The-Spot!
x140l31
Learning poster
Posts: 69
Joined: Tue Jan 30, 2007 12:51 am

Post by x140l31 »

sorry to post two times but can anyone help me please? xD
chetan
New poster
Posts: 43
Joined: Sun Sep 24, 2006 2:39 pm

Post by chetan »

i am getting WA :(( :((

please help me

Code: Select all

CODE DELETED AFTER AC :)
Last edited by chetan on Mon Jul 16, 2007 8:30 am, edited 1 time in total.
chetan
New poster
Posts: 43
Joined: Sun Sep 24, 2006 2:39 pm

Post 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 ????
fR0D
New poster
Posts: 29
Joined: Mon Feb 11, 2008 5:59 am
Contact:

Post by fR0D »

my program is giving RE plz help me...

Code: Select all

Code Deleted after AC
Last edited by fR0D on Tue Feb 26, 2008 3:19 pm, edited 1 time in total.
CSEDU_1323
New poster
Posts: 10
Joined: Mon Feb 25, 2008 8:22 pm
Location: Dhaka, Bangladesh.

Post 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
--- B HAPPY & KEEP SMILING ------
fR0D
New poster
Posts: 29
Joined: Mon Feb 11, 2008 5:59 am
Contact:

Post by fR0D »

thnx vry much it helped :)
newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Why WA in 389 ??

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

Return to “Volume 3 (300-399)”