Page 4 of 5
355 - WA passes all dataset in this forum,but....anyone help
Posted: Sun Apr 20, 2008 9:51 pm
by kbr_iut
hey guyes my code passes all input set of this forum but I am still getting wA
I skipped leading 0's and used unsigned long long datatype..
pliz any one help...here is my code
Re: 355 - The Bases Are Loaded
Posted: Mon Apr 21, 2008 4:57 am
by Jan
Don't use pow or other functions that use floating point calculations. Write manual functions if needed (only integer calculations are needed!).
Re: 355 - jan vi, avoid pow(),but (still WA)
Posted: Tue Apr 22, 2008 8:46 pm
by kbr_iut
code removed. now AC
Re: 355 - The Bases Are Loaded
Posted: Wed Apr 23, 2008 3:53 am
by Jan
There are no leading zeros. So, this is not a problem. The problem is your code doesn't work for 0. Just think that what should be the output of '2 3 0'. Your code is definitely wrong in this case.
Re: 355 - The Bases Are Loaded
Posted: Wed Apr 23, 2008 6:15 pm
by kbr_iut
jan vi , u r really u....thanx,now AC
Re: 355 - The Bases Are Loaded
Posted: Wed Jul 09, 2008 9:53 pm
by maruf
getting WA.plz help
Code: Select all
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
long long int a,i,k,n,m;
long long int p,q;
long long int y[5000];
char x[5000];
while(scanf("%lld",&p)!=EOF)
{
scanf("%lld",&q);
scanf("%s",x);
n=strlen(x);
int f=1;
for(i=0;i<n;i++)
{
if(x[i]>='A' && x[i]<='F')
m=x[i]-55;
else
m=x[i]-48;
if(m>=p )
{
printf("%s is an illegal base %lld number\n",x,p);
f=0;
break;
}
}
if(f==1)
{
printf("%s base %lld = ",x,p);
if(n==1 && x[0]==0)
printf("0 base %lld\n",q);
else
{
int sum=0;
for(i=n-1,k=0;i>=0;k++)
{
if(x[i]>='A' && x[i]<='F')
sum+=(x[i]-55)*pow(p,k);
else
sum+=(x[i]-48)*pow(p,k);
i=i-1;
}
p=sum;
int m=0;
for( ;p!=0;p=p/q)
y[m++]=p%q;
for(i=m-1;i>=0;i--)
{
if(y[i]>=10 && y[i]<=15)
printf("%c",y[i]+55);
else
printf("%lld",y[i]);
}
printf(" base %lld\n",q);
}
}
}
return 0;
}
Re: 355 - The Bases Are Loaded
Posted: Thu Jul 10, 2008 10:06 am
by Nishith csedu 1448
Maruf check this input..........
output:
Hope you will get acc soon.

Re: 355 - The Bases Are Loaded
Posted: Thu Jul 10, 2008 12:14 pm
by maruf
still WA...
should i use array for generating output??
355-wrong answer
Posted: Sat Jul 12, 2008 9:51 pm
by sunahian
I have checked all the possible case. but I have gotten wrong answer.please any one can help me.
here is the code.
Code: Select all
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
int main()
{
long long int i,j,k,l,n,m,b[1000],t,flag,index,slag,p,u,v;
char a[1000],c[1000];
while(scanf("%lld%lld%s",&n,&m,a)==3)
{
l=strlen(a);
slag=0;
for(i=0,j=0;i<l;i++)
{
if(isdigit(a[i]))
{
b[j]=a[i]-48;
j++;
}
else if(isalpha(a[i]))
{
b[j]=a[i]-55;
j++;
}
else
{
slag=1;
printf("%s is an illegal base %lld number\n",a,n);
break;
}
}
if(slag==1)
continue;
flag=0;
for(i=0;i<j;i++)
{
if(b[i]>=n)
{
printf("%s is an illegal base %lld number\n",a,n);
flag=1;
}
}
if(flag==1)
continue;
p=0;
index=0;
for(i=0;i<j;i++)
{
p=(p*n)+b[i];
}
for(;;)
{
u=p%m;
v=p-u;
p=v/m;
if(u<=9)
{
c[index]=u+48;
index++;
}
else if(u>=10)
{
c[index]=u+55;
index++;
}
if(p<=0)
break;
}
c[index]='\0';
printf("%s base %lld = ",a,n);
for(i=index-1;i>=0;i--)
printf("%c",c[i]);
printf(" base %lld\n",m);
}
return 0;
}
Re: 355-The Bases Are Loaded
Posted: Sun Jul 13, 2008 5:43 am
by sunahian
I have checked all the possible case. but I have gotten wrong answer.please any one can help me.
here is the code.
Code: Select all
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
int main()
{
long long int i,j,k,l,n,m,b[1000],t,flag,index,slag,p,u,v;
char a[1000],c[1000];
while(scanf("%lld%lld%s",&n,&m,a)==3)
{
l=strlen(a);
slag=0;
for(i=0,j=0;i<l;i++)
{
if(isdigit(a[i]))
{
b[j]=a[i]-48;
j++;
}
else if(isalpha(a[i]))
{
b[j]=a[i]-55;
j++;
}
else
{
slag=1;
printf("%s is an illegal base %lld number\n",a,n);
break;
}
}
if(slag==1)
continue;
flag=0;
for(i=0;i<j;i++)
{
if(b[i]>=n)
{
printf("%s is an illegal base %lld number\n",a,n);
flag=1;
}
}
if(flag==1)
continue;
p=0;
index=0;
for(i=0;i<j;i++)
{
p=(p*n)+b[i];
}
for(;;)
{
u=p%m;
v=p-u;
p=v/m;
if(u<=9)
{
c[index]=u+48;
index++;
}
else if(u>=10)
{
c[index]=u+55;
index++;
}
if(p<=0)
break;
}
c[index]='\0';
printf("%s base %lld = ",a,n);
for(i=index-1;i>=0;i--)
printf("%c",c[i]);
printf(" base %lld\n",m);
}
return 0;
}
I have checked all the possible case. but I have gotten wrong answer.please any one can help me.
here is the code.
[code]
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
int main()
{
long long int i,j,k,l,n,m,b[1000],t,flag,index,slag,p,u,v;
char a[1000],c[1000];
while(scanf("%lld%lld%s",&n,&m,a)==3)
{
l=strlen(a);
slag=0;
for(i=0,j=0;i<l;i++)
{
if(isdigit(a[i]))
{
b[j]=a[i]-48;
j++;
}
else if(isalpha(a[i]))
{
b[j]=a[i]-55;
j++;
}
else
{
slag=1;
printf("%s is an illegal base %lld number\n",a,n);
break;
}
}
if(slag==1)
continue;
flag=0;
for(i=0;i<j;i++)
{
if(b[i]>=n)
{
printf("%s is an illegal base %lld number\n",a,n);
flag=1;
}
}
if(flag==1)
continue;
p=0;
index=0;
for(i=0;i<j;i++)
{
p=(p*n)+b[i];
}
for(;;)
{
u=p%m;
v=p-u;
p=v/m;
if(u<=9)
{
c[index]=u+48;
index++;
}
else if(u>=10)
{
c[index]=u+55;
index++;
}
if(p<=0)
break;
}
c[index]='\0';
printf("%s base %lld = ",a,n);
for(i=index-1;i>=0;i--)
printf("%c",c[i]);
printf(" base %lld\n",m);
}
return 0;
}
[/code]
355 - Clarification
Posted: Sat Jul 19, 2008 7:32 am
by zyxw
I got AC after 6 WA
I would like to make few clarifications so tat it might help others:
1. As said by others, there are
no negative inputs.
2. The problem states that, the number to be converted may contain invalid
digits.
But, it may contain invalid
characters too!
Example:
Here
A4 is invalid, as a number with base 10 can have digits from '0' to '9' only.
I didn't consider this case initially.
3. Another reason behind WA (for me) was precision error.
Then I used 'int' to take input for both the bases.
For pow() function, i used like this:
Code: Select all
(long long int) pow( (double)base1, i) );
Help me! Why Time Limit Exceeded
Posted: Tue Oct 28, 2008 6:16 pm
by athanhcong
This is the first time I submit my code to UVA.
After many times Wrong Answer, I change my input from
scanf("%d %d %s", &oriBase, &newBase, &oriValue);
to
while (scanf("%d %d %s", &oriBase, &newBase, &oriValue))
And get TLE not WA, enjoy, but I can't find why's my code TLE.
Please help me. here my code.
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const int max= 255;
int check(char* num, int fromBase)
{
int i, temp;
/* ok= 1;*/
int numlen= strlen(num);
for (i= 0; i< numlen; i++)
{
if ((num[i]>= '0') && (num[i]<= '9'))
num[i]= num[i]- '0';
else if ((num[i]>= 'A') && (num[i]<= 'F'))
num[i]= num[i]- 'A' + 10;
else
return 0;
if (num[i]>= fromBase) return 0;
}
return 1;
}
unsigned long toBase10(char num[max], int numlen, int fromBase) {
unsigned long result= 0; int i;
/*printf("%s %d\n", num, numlen);*/
for (i= 0; i< numlen; i++)
result= result* fromBase + num[i];
return result;
}
void toBase(unsigned long num, int base, char* result) {
char temp[max];
int i= 0, j;
do
{
temp[i++]= num % base;
num= num / base;
}while (num!= 0);
/* */
i--;
for (j= 0; j<= i; j++)
{
if ((temp[i -j] >= 10))
result[j]= temp[i-j] - 10 + 'A';
else
result[j]= temp[i-j] + '0';
}
result[j]= '\0';
}
int main()
{
int oriBase, newBase;
char oriValue[max], newValue[max];
int oriNumLen;
unsigned long base10Value;
while (scanf("%d %d %s", &oriBase, &newBase, &oriValue))
{
/*printf("%d %d %s\n", oriBase, newBase, oriValue);*/
oriNumLen= strlen(oriValue);
printf("%s", oriValue);
if (check(oriValue, oriBase))
{
base10Value= toBase10(oriValue, oriNumLen, oriBase);
/*printf("\n%lu <- Base 10 Value\n", base10Value);*/
toBase(base10Value, newBase, newValue);
printf(" base %d = %s base %d\n", oriBase, newValue, newBase);
}
else
printf (" is an illegal base %d number\n", oriBase);
}
return 0;
}
Re: 355 - The Bases Are Loaded
Posted: Thu Nov 06, 2008 11:03 am
by L I M O N
Re: 355 - The Bases Are Loaded
Posted: Tue Nov 18, 2008 4:17 pm
by Fluffymoo
Try to change
while (scanf("%d %d %s", &oriBase, &newBase, &oriValue))
to
while (scanf("%d %d %s", &oriBase, &newBase, &oriValue)==3)
Re: 355 The Bases Are Loaded
Posted: Sat May 09, 2009 9:35 am
by Jehad Uddin
prob no 355.Can anybody help me,i m getting WA for this code.
Deleted after ac...