Page 2 of 4
10093 A hard problem!
Posted: Thu Mar 04, 2004 9:09 am
by sohel
I don't know what I am doing wrong with this problem.
I considered that there could be + or - sign before a number.
If input is 0 output is 2 , isn't it.
I also stared to loop from (max+1) where max is the numerical maximum character ( ie A = 10 and a = 26 and so on).
Then later I converted it to decimal , considering all the bases, and checked whether it is divisible by (Base - 1).
What am I doing wrong.
I will not post my code as yet ...
Can anyone give me some critical input.
Thanx

What I consider
Posted: Mon Mar 08, 2004 4:59 pm
by hackfox
Hi Sohel,
Below is what I consider in this program. For your reference.
a. Don't take care of +/-. Even there are + or - symbol, the result should be the same.
b.Take care of white space, tab. In fact. this kind of characters are ALL
skipped.
c.Check invalid character for certain base. For example, 222 is an invalid
base 2 number. AAA is invalid base 2~10 number.
d.Note the real value, for example,
111 base 2 = 7, but 111 base 4 = 21.
still don't get it
Posted: Tue Mar 09, 2004 10:34 am
by sohel
I considered the things you have mentioned but still get WA.
This time I will post my code:
[cpp]
deleted after getting AC.
[/cpp]
Can somebody give a quick scan on this trivial code and point out the mistake.
Thanks.

confusion
Posted: Wed Mar 10, 2004 10:52 am
by sohel
I am wondering whehter
long long is enough to solve this problem.
If I convert the given number to base 10 ( for each base ) won't it fit
into long long or
do i have to use any other technique to find validity.
If the latter is true , can someone give me some hints on that.
Thanks.
give up
Posted: Sun Mar 14, 2004 12:08 pm
by sohel
I give up!
After a lot of dogged effort ...I am still stuck on this problem.....
..

Posted: Sun Mar 14, 2004 5:15 pm
by little joey
Don't give up, and don't assume the digital representation fits into a long long; the string can be hundreds of 'digits' long.
One hint: how do you determine if a decimal number of arbitrary length is divisible by 9?
isdiv
Posted: Mon Mar 15, 2004 5:29 am
by sohel
I realized that long long is not big enough..... and so I resorted to string division... but still WA!
One hint: how do you determine if a decimal number of arbitrary length is divisible by 9?
I use to following function to check whether a number in base b is divisible by (b-1).
[cpp]
bool isdiv(char str[], int b)
{
int i,k,l;
l = strlen(str);
int sum = 0;
for(i=0;i<l;i++)
{
if( isdigit( str
) )
k = str - '0';
else if( str<='Z')
k = str - 'A' + 10;
else
k = str - 'a' + 36;
sum = sum*b + k;
sum = sum % (b-1);
}
if(sum)
return true;
return false;
}
[/cpp]
Is there anything wrong with this?
Can you give some critcal inputs where this function fails.
Thanks.

Posted: Mon Mar 15, 2004 8:23 am
by little joey
I just submitted your previous code with an extra line sum = sum % (b-1); in contodec() and got accepted!
thanks
Posted: Mon Mar 15, 2004 8:50 am
by sohel
Thank you very much LJ,
This problem has been killing me.... and now the frustration is over.

dev-c++ OK but OJ compile error
Posted: Mon Mar 14, 2005 5:59 pm
by tRipper
I've been solving the problem 10093 on my computer and it compiles perfectly ok (dev-c++), but when i send it to OJ i get compile error. Is something wrong with my code or what?
// code deleted after AC
Posted: Mon Mar 14, 2005 6:05 pm
by tRipper
got it. the problem was in the line
#include <locale>
Why is that? I'm pretty much new in c++ and i thought that for using 'isdigit', 'isupper' and similar u need to include this library.
Posted: Mon Mar 14, 2005 8:27 pm
by Krzysztof Duleba
Character classification functions for C locale are defined in <cctype>. <locale> defines templates for other locales.
An Easy Problem!
Posted: Mon Apr 04, 2005 5:20 pm
by tan_Yui
I got WA, but I couldn't find bugs of my code.
Could anyone check my code?
Or, if you have Accepted code, compare the output of your code with the my code one?
Here is my code.
Thank you.
Re: An Easy Problem!
Posted: Mon Apr 18, 2005 4:07 pm
by tan_Yui
I'm waiting for somebody's help still now.
It's not easy problem for me ....
Thank you.
10093: Why WA?
Posted: Thu May 05, 2005 4:07 pm
by miracle
I've still got WA,can anyone help me?
#include <iostream.h>
int f(char a)
{
if(a>='0' && a<='9')
return a-'0';
if(a>='a' && a<='z')
return a-'a'+36;
if(a>='A' && a<='Z')
return a-'A'+10;
}
int main()
{
char line[250];
int max,tmp,i,j;
unsigned long r;
line[0]='\0';
while(cin.getline(line,250) && line[0])
{
max=-1;
for(i=0;line;i++)
{
tmp=f(line);
if(max<tmp)
max=tmp;
}
max= max<2 ? 2:max+1;
for(i=max;i<=62;i++)
{
r=0;
for(j=0;line[j];j++)
r=(r*i+f(line[j]))%(i-1);
if(r==0)
break;
}
if(i==63)
cout<<"such number is impossible!"<<endl;
else cout<<i<<endl;
line[0]='\0';
}
return 0;
}