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

Ferdous
New poster
Posts: 26
Joined: Sun Dec 14, 2003 1:17 pm
Location: Dhaka, Bangladesh
Contact:

Question about Problem 389 (Basically Speaking)

Post by Ferdous »

Queted from problem description:
The project manager of the Super Neato Model I calculator has informed you that the calculator will have the following neato features:


It will have a 7-digit display.
Its buttons will include the capital letters A through F in addition to the digits 0 through 9.
It will support bases 2 through 16.
Should I assume that the maximum length of input is 7?


With best regards.
Ferdous
I am destined to live on this cruel world........
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Try this I/O.

Post by _.B._ »

This I/O helped me to get it ACed :D

Input:

Code: Select all

      0 10 10
   0000 10 10
9999999 10  2
9999999 10 10
9999999 10 16
 98967F 16 10
    418 10 16
    1A2 16 10
1111000  2 10
1111000  2 16
2102101  3 10
2102101  3 15
  12312  4  2
     1A 15  2
1234567 10 16
   ABCD 16 15
FFFFFFF 16 16
EEEEEEE 15 15
1111111  2  2
      0  2  2
Output:

Code: Select all

      0
      0
  ERROR
9999999
 98967F
9999999
    1A2
    418
    120
     78
   1765
    7CA
  ERROR
  11001
 12D687
   D071
FFFFFFF
EEEEEEE
1111111
      0
Hope it helps!
_.
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Try this.

Post by _.B._ »

Greetings!
Try these Inputs, and I'm sure you'll have to work on your code.

Try this Input first:

Code: Select all

0000001  2 10
0000000  2 10
      0 10 10
   0000 10 10
      0  2  2
Now try this one:

Code: Select all

0000000  2 10
      0 10 10
   0000 10 10
      0  2  2
Hope it helps!
_.
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Try this.

Post by _.B._ »

Greetings!
First, try posting your code between the [ code ][ /code ] brackets.
Then you might want to look the other posts related to this problem, and try this I/O, wich helped me to get it ACed :D

Input:

Code: Select all

      0 10 10
   0000 10 10
9999999 10  2
9999999 10 10
9999999 10 16
 98967F 16 10
    418 10 16
    1A2 16 10
1111000  2 10
1111000  2 16
2102101  3 10
2102101  3 15
  12312  4  2
     1A 15  2
1234567 10 16
   ABCD 16 15
FFFFFFF 16 16
EEEEEEE 15 15
1111111  2  2
      0  2  2
Output:

Code: Select all

      0
      0
  ERROR
9999999
 98967F
9999999
    1A2
    418
    120
     78
   1765
    7CA
  ERROR
  11001
 12D687
   D071
FFFFFFF
EEEEEEE
1111111
      0
Hope it helps!
_.
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

WA??

Post by _.B._ »

Coudln't find anything wrong with your code, then tryed several cases, and everything worked just fine!!
Then I changed the limits for

char input[1000];
char converted[1000];

to

char input[10000];
char converted[10000];

And submited it... it was ACed!!
Then I submited your original code, and it was ACed too!!
I don't understand, are you getting WAs??
_.
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Yup!

Post by _.B._ »

Greetings Ferdous!
7 indeed. I made that assumption, and got it ACed.
You may also browse the topics related to this problem.
This I/O helped me to get it ACed :D

Input:

Code: Select all

      0 10 10
   0000 10 10
9999999 10  2
9999999 10 10
9999999 10 16
 98967F 16 10
    418 10 16
    1A2 16 10
1111000  2 10
1111000  2 16
2102101  3 10
2102101  3 15
  12312  4  2
     1A 15  2
1234567 10 16
   ABCD 16 15
FFFFFFF 16 16
EEEEEEE 15 15
1111111  2  2
      0  2  2
Output:

Code: Select all

      0
      0
  ERROR
9999999
 98967F
9999999
    1A2
    418
    120
     78
   1765
    7CA
  ERROR
  11001
 12D687
   D071
FFFFFFF
EEEEEEE
1111111
      0
Hope it helps!
_.
smilitude
Experienced poster
Posts: 137
Joined: Fri Jul 01, 2005 12:21 am

Post by smilitude »

thanks .B.
:roll: i am not sure what happened.. but i didnt get a AC that time.. its really confusing.. cause i submitted that and got AC!
anyway.. thanks a lotttt dude!
fahim
#include <smile.h>
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Good!

Post by _.B._ »

Glad it helped you :D
Perhaps the problem was re-visited.

Keep posting! 8)
_.
Ferdous
New poster
Posts: 26
Joined: Sun Dec 14, 2003 1:17 pm
Location: Dhaka, Bangladesh
Contact:

Post by Ferdous »

I am not sure of what's wrong with my code. I assumed MAX_LEN of the number I have to convert from (1st number of a line of input) is 7 and I got WA. I just changed it to 12 and it got AC?!

I declared 2 string.

Code: Select all

#define MAX_LEN 7

/*
First number of an input line (the number to be converted) is stored here
*/
char numFrom[MAX_LEN+1];

/*
output is stored here. max input is FFFFFFF. For this max input, max output in base 2 is 28 bits long. That's why MAX_LEN*4 +1.
*/
char numTo[MAX_LEN*4 + 1];

But it didn't work. I had to change it to 12.

What were the sizes of these two arrays in your code?


With best regards.
Ferdous
Last edited by Ferdous on Wed Aug 02, 2006 11:18 am, edited 1 time in total.
I am destined to live on this cruel world........
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Nada.

Post by _.B._ »

Hello again!
I used size 8 for the input string. I usually make limits a bit longer than what the problem states.

Code: Select all

typedef char T_string[8];
I took a look to your code, and I don't know what the MAX_LEN has to do with the WA. It should work with 'MAX_LEN 7'.
The only thing that I do in my code, wich you don't, is to trim the possible leading 0s from input lines. Even when I declared the input strings as size 8, when I 'cin' them, it will read the whole string, even if it's bigger than 7.
So, an input like this:

Code: Select all

0000000000000000000000000000000000000000000003 10 10
0000000000000000000000000000000000000000000003 10 2
Will throw this output:

Code: Select all

      3
     11
But I'm still not sure how it would affect your 'MAX_LEN 7'.
_.
Ferdous
New poster
Posts: 26
Joined: Sun Dec 14, 2003 1:17 pm
Location: Dhaka, Bangladesh
Contact:

Post by Ferdous »

mysterious indeed !
I am destined to live on this cruel world........
danieldragonlion
New poster
Posts: 1
Joined: Sun Aug 20, 2006 4:00 am

389 WA why?

Post by danieldragonlion »

#include<iostream>
using namespace std;

void g(char z[1000], int x, int c);

int main()
{ char z[1000];
int x,c;



while(cin >>z>>x>>c){ g(z,x,c);}
cin >>z>>x>>c;
return 0;
}

void g(char z[1000], int x, int c)
{

int v,b=1,n=0,m[1000],a,s[1000],d=0,f;

v=strlen(z);

for(int i=0; i<v;i++){if(z<58)m=z-48; else{m=z-55;}}

for(int i=1; i<v+1; i++){ n=n+m[v-i]*b; b=b*x; }

while(n>c){a=n%c; s[d]=a; n=n/c; d++;}
s[d]=n;
f=d;

if(d<7){
for(d; d>-1; d--){ for(f; 7-f>1; f++){cout <<" ";}
if(s[d]<10){cout <<s[d];}
if(s[d]==10){cout <<"A";}
if(s[d]==11){cout <<"B";}
if(s[d]==12){cout <<"C";}
if(s[d]==13){cout <<"D";}
if(s[d]==14){cout <<"E";}
if(s[d]==15){cout <<"F";}
} }
else{cout <<" ERROR";}
cout <<"\n";


}
J&Jewel
New poster
Posts: 50
Joined: Thu Jul 31, 2003 10:43 am
Location: Daffodil University,Dhaka,Bangladesh
Contact:

Post by J&Jewel »

Please post your code in the code box, so that every one can understand your program code easily.
I hate Wrong Answer!
Kire Sopov
New poster
Posts: 7
Joined: Wed Sep 15, 2004 2:01 am

389 - CE

Post by Kire Sopov »

Why am I getting a compile error?

Code: Select all

#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>

void ConvertNum(std::string &str, int nFrom, int nTo)
{
	static const char szDigits[] = "0123456789ABCDEF";
	int nValue10(0), nProduct(1);

	// Convert from base nFrom to base 10:
	for (std::string::const_reverse_iterator it = str.rbegin(); it != str.rend(); ++it)
	{
		int nTmp = ((*it >= '0') && (*it <= '9'))  ?  int(*it - '0') : 10 + (*it - 'A');
		nValue10 += nTmp * nProduct;
		nProduct *= nFrom;
	}

	// Convert from base 10 to base nTo:
	str.clear();
	do
	{
		str.push_back(szDigits[nValue10 % nTo]);
		nValue10 /= nTo;
	}
	while ((nValue10 > 0) && (str.length() < 8));

	if (str.length() > 7)
		str = "ERROR";
	else
		std::reverse(str.begin(), str.end());
}

int main()
{
	std::string	strNum;
	int			a, b;

	while (NULL != (std::cin >> strNum >> a >> b))
	{
		ConvertNum(strNum, a, b);
		std::cout << std::setw(7) << strNum << std::endl;
	}
}
albet_januar
New poster
Posts: 35
Joined: Wed Apr 12, 2006 6:03 pm
Location: jakarta, indonesia
Contact:

Post by albet_januar »

my code give WA.. can anybody help..
did I do something wrong??

Code: Select all

ACC after i know my silly mistake..
hix..
Last edited by albet_januar on Wed Jan 03, 2007 6:16 pm, edited 1 time in total.
Post Reply

Return to “Volume 3 (300-399)”