Page 1 of 4

10093 - An Easy Problem!

Posted: Fri Jun 21, 2002 11:10 am
by Revenger
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;
    Read(ch);
    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;
  if Eoln(InPut) then Readln;
  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.

Posted: Sat Jun 22, 2002 4:10 am
by Revenger
Ha ha! The only my mistake was that I haven't noticed that in input file may be symbols "+" or "-"

Posted: Fri Jul 26, 2002 5:55 pm
by hongping
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";

				
	}
}

Posted: Fri Oct 18, 2002 5:34 pm
by Noim
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. :)

Posted: Wed Nov 06, 2002 9:51 am
by Ivan Golubev
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?

10093:Why WA

Posted: Fri Jan 31, 2003 8:13 pm
by razibcse
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");
  }
 }
 }
}

Posted: Sat Feb 01, 2003 12:29 am
by turuthok
I might be wrong, but, ... doesn't seem like you're handling lowercase letters.

-turuthok-

thanx a lot

Posted: Sun Feb 02, 2003 7:51 pm
by razibcse
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

Please help meeeeeeee

Posted: Wed Apr 02, 2003 8:13 pm
by Professor_Of_Love
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 !

Posted: Sat Apr 05, 2003 8:01 pm
by Professor_Of_Love
Is there anyone who can help me? :cry:

Posted: Mon Apr 21, 2003 10:53 pm
by david
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.

Posted: Mon Apr 21, 2003 10:55 pm
by david
well i mistook the name; the last post should be addressed to Professor_Of_Love.

10093 rescue me

Posted: Tue Nov 25, 2003 11:30 am
by problem
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]

don't get it

Posted: Wed Mar 03, 2004 2:35 pm
by sohel
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.

:cry:

Posted: Wed Mar 03, 2004 6:55 pm
by Noim
sorry boss, i was wrong .
your answer is correct.
answer should be 14