## 10093 - An Easy Problem!

Moderator: Board moderators

Revenger
Experienced poster
Posts: 132
Joined: Sun Apr 14, 2002 12:27 pm
Location: Russia

### 10093 - An Easy Problem!

I just wonder why I get WA? Can anyone help me? Please!

Code: Select all

``````Program p10093;

Const Abc = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';

Var DivRes       : Array[1..62]of integer;
i,MinDR,j    : Integer;
ch           : Char;

begin
While Not Eof(InPut) Do begin
for i:=1 to 62 do DivRes[i]:=0;
MinDR:=2;
While True do begin
if (Eof(InPut))or(Eoln(InPut)) then break;
if Pos(ch,Abc)>0 then j:=Pos(ch,Abc)-1 else MinDr:=100;
if j+1>MinDR then MinDR:=j+1;
for i:=MinDR to 62 do
DivRes[i]:=(DivRes[i]*i+j) mod (i-1);
end;
j:=-1;
for i:=MinDR to 62 do
if DivRes[i]=0 then begin
j:=i;
Break;
end;
if j=-1 then Writeln('such number is impossible!')
else Writeln(j);
end;
end.``````

Revenger
Experienced poster
Posts: 132
Joined: Sun Apr 14, 2002 12:27 pm
Location: Russia
Ha ha! The only my mistake was that I haven't noticed that in input file may be symbols "+" or "-"

hongping
New poster
Posts: 11
Joined: Fri Jul 26, 2002 5:43 pm
Hi, I have taken into consideration the possibility of a + or - sign. But this still doesnt work. Perhaps someone could help me debug please. Thanks a lot!

Code: Select all

``````
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>

char a[2000000];

int v(char c)
{
if ('0'<=c && '9' >=c)
return c-'0';
if ('A'<=c && 'Z' >=c)
return c-'A'+10;
if ('a'<=c && 'z' >=c)
return c-'a'+36;
if (c=='-')
return -1;
if (c=='+')
return -2;
}

void main(void)
{
while (gets(a))
{
long long i;
i=0;
int b,max,neg=1;
while (v(a[i])<0)
{
if (v(a[i])==-1)
neg=-1;
a[i]='0';
i++;
}
max=0;
for (i=strlen(a)-1;i>=0;i--)
{
if (max<v(a[i])) max=v(a[i]);
}
if (max<2)max=2;

int ok=0;
for (b=max;b<=62;b++)
{
int c=b-1;
long long m=1;
long long x=0;
for (i=strlen(a)-1;i>=0;i--)
{
x=(x+((v(a[i])%c)*m)%c)%c;
m=(m*b)%c;
//cout << b << " " << x << endl;
}
if ((neg*x)%c==0)
{
ok=1;
cout << b << endl;
break;
}
}
if (!ok)
cout << "such number is impossible!\n";

}
}``````

Noim
Learning poster
Posts: 88
Joined: Sun Oct 13, 2002 6:11 am
I have solved this problem. Most Probably This problem is not for '-'
and '+'.

what is your output for input: 265
The actual output is : D

You may test for this input.
__nOi.m....

Ivan Golubev
Experienced poster
Posts: 167
Joined: Fri Oct 19, 2001 2:00 am
Location: Saint Petersburg, Russia
Each line in the input file will contain an integer (as defined in mathematics) number of any integer base (2..62).
Do you think that, for example, -1000 is not an integer and it's incorrect as input value?

razibcse
New poster
Posts: 50
Joined: Mon Jul 22, 2002 3:17 am
Contact:

### 10093:Why WA

I tried to check all possibilities including negative or zero number..

but it kept getting WA...

if someone kindly suggest me what to do, i'll b very greatful...

Code: Select all

``````#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX 100000
void main()
{
char str[MAX];
long flag,max,min_base,val,a,b,len,sum;
while(gets(str))
{
len=strlen(str);
if(len!=0)
{
sum=0;
max=0;
for(a=0;a<len;a++)
{
if(!isalpha(str[a]) && !isdigit(str[a]))
continue;
if(isdigit(str[a]))
val=str[a]-'0';
else if(isalpha(str[a]))
val=str[a]-'A'+10;
if(val>max)
max=val;
sum+=val;
}

if(max==0 && sum==0)
printf("2\n");
else
{
min_base=max+1;
flag=1;
for(b=min_base-1;;b++)
{
if((sum%b)==0)
break;
if(b>=61)
{
flag=0;
break;
}

}
if(flag)
printf("%ld\n",b+1);
else if(!flag)
printf("such number is impossible!\n");
}
}
}
}``````

turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:
I might be wrong, but, ... doesn't seem like you're handling lowercase letters.

-turuthok-

razibcse
New poster
Posts: 50
Joined: Mon Jul 22, 2002 3:17 am
Contact:

### thanx a lot

Thanx man for ur nice suggestion..
I checked for lower case letters & got it Accepted...

thanx again for ur valuable time on this problem

Razib

Professor_Of_Love
New poster
Posts: 9
Joined: Tue Apr 01, 2003 10:03 pm

Please can anyone help me on this code? Why WA? Where is my mistake??

[c]#include<stdio.h>
#include<ctype.h>
#include<string.h>

char str[32000];

void main(void)
{
char high,low;
int i,flag;
while(gets(str))
{
high = 0, flag = 0;
for(i=0;i<strlen(str);i++)
{
if(!(isupper(str)||islower(str)||isdigit(str)))
if(str!='-')
flag=1;
if(high<str)
high = str;
}
if(flag==1)
{
printf("such number is impossible!\n");
continue;
}
if(isdigit(high))
high = high-'0'+1;
if(isupper(high))
high = high-'A'+10+1;
if(islower(high))
high = high-'a'+36+1;
printf("%d\n",(int)high);
}
}[/c]
Thanks !

Professor_Of_Love
New poster
Posts: 9
Joined: Tue Apr 01, 2003 10:03 pm
Is there anyone who can help me?

david
Learning poster
Posts: 83
Joined: Mon Apr 21, 2003 10:14 pm
Hi razibcse.
If I understand well your code, the only thing you try to do is ensure that no digit is used bigger or equal than the base, isn't it? That has little to do with the problem as you have to find a suitable base such that R is divisible by (n - 1). For instance, for R = 5464, your answer, 7, is invalid since 6 does not divide 1957. The correct answer in this case is 20. (19 divides 41724).
Hope this helps you.
By the way, negative numbers are not to be taken into account.

david
Learning poster
Posts: 83
Joined: Mon Apr 21, 2003 10:14 pm
well i mistook the name; the last post should be addressed to Professor_Of_Love.

problem
New poster
Posts: 27
Joined: Mon Nov 10, 2003 12:40 am

### 10093 rescue me

help me plz why wa.i think my solution is ok.kindly rescue me.

[cpp]
#include<stdio.h>
#include<string.h>
#include<math.h>
#define ma 5000
#include<ctype.h>

void main()
{
long int i,j,sum=0,l,l1,l2,max,q;
char t[ma]={0};
while(gets(t))
{
max=0;
i=strlen(t);
if(i==1)
{
l=(t[0]-65);
l1=(t[0]-97);
l2=(t[0]-48);
if(t[0]>='0'&&t[0]<='9')
printf("%ld\n",l2+1);
else if(t[0]>='A'&&t[0]<='Z')
printf("%ld\n",l+11);
else if(t[0]>='a'&&t[0]<='y')
printf("%ld\n",l1+37);
}
if(i==2&&t[0]=='-')
{
l=(t[1]-65);
l1=(t[1]-97);
l2=(t[1]-48);
if(t[1]>='0'&&t[1]<='9')
printf("%ld\n",l2+1);
else if(t[1]>='A'&&t[1]<='Z')
printf("%ld\n",l+11);
else if(t[1]>='a'&&t[1]<='y')
printf("%ld\n",l1+37);
}
else if(i>2&&t[0]=='-')
{
for(j=1;j<i;j++)
{
if(isupper(t[j]))
{
l=t[j]-65;
sum+=(l+10);
if((l+10)>max)
max=l+10;
}
if(islower(t[j]))
{
l1=t[j]-97;
sum+=l1+36;
if((l1+36)>max)
max=l1+36;
}
if(isdigit(t[j]))
{
l2=t[j]-48;
sum+=l2;
if(l2>max)
max=l2;
}
}
while(fmod(sum,max)!=0)
{
q=fmod(sum,max);
max++;
}
printf("%ld\n",max+1);
}

else if(i>=2&&t[0]!='-')
{
for(j=0;j<i;j++)
{
if(isupper(t[j]))
{
l=t[j]-65;
sum+=(l+10);
if((l+10)>max)
max=l+10;
}
if(islower(t[j]))
{
l1=t[j]-97;
sum+=(l1+36);
if((l1+36)>max)
max=l1+36;
}
if(isdigit(t[j]))
{
l2=t[j]-48;
sum+=l2;
if(l2>max)
max=l2;
}
}
while(fmod(sum,max)!=0)
{
q=fmod(sum,max);
max++;
}
printf("%ld\n",max+1);
}
max=0;
sum=0;

}
}
[\cpp]

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

### don't get it

For 265, my program outputs 14.
The problem statement noted that the output should be in decimal number system ... so how come the output is D.

is 14 wrong.
if it is can anybody explain the reason.

This problem looks straight forward, I can't seem to understand why I keep getting WA.

Noim
Learning poster
Posts: 88
Joined: Sun Oct 13, 2002 6:11 am