10106 - Product
Moderator: Board moderators
Re: 10106 product
Yes, I can deal with zero-multiplication, and support more than 10 ^1000.
But it still gets WA.....
But it still gets WA.....
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
I think, that there are no other tricks in this problem.Try to check once again code, which generate product for this problem (multiply function I think
)
In my opinion, if you handle correct data like 00001 * 00010, 002 * 005, 003 * 0 and can calculate numbers in given range (from problem specification) you must get Accepted
) maybe you have problem with carry ?
Best regards
Dominik

In my opinion, if you handle correct data like 00001 * 00010, 002 * 005, 003 * 0 and can calculate numbers in given range (from problem specification) you must get Accepted

Best regards
Dominik
-
- New poster
- Posts: 9
- Joined: Wed Apr 02, 2003 10:28 am
10106
hi i am having trouble with the prob 10106. i used the big integer class instead of the string multiplication . my programs deals with - ve numbers , inputs like 000001*00010,0002*00005,0003*0. but i am not at all sure about the highest limits of its . i have a question , how can can we find that powers like 10^250 will have how many digits.i used 1000000 for my inputs. will it do ?
here is my code . its too big and i am sorry for my stupidity too send too big a code.also sorry for my bad english
is there any problem with my input output format ??????????? pliz help . looking forward for help. thanx in advance.
Riyad
here is my code . its too big and i am sorry for my stupidity too send too big a code.also sorry for my bad english



Code: Select all
#include <iostream.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <string.h>
const int size=100000;
/************ class starts ***************/
int BigIntMajorVersion = 6;
int BigIntMinorVersion = 7;
int BigIntRevision = 25;
typedef unsigned int SizeT;
typedef unsigned int DATATYPE;
const DATATYPE BASE = 10000;
const DATATYPE INVALIDDATA = 65535U;
const SizeT LOG10BASE = 4;
class BigInteger
{
private:
DATATYPE *TheNumber;
SizeT Start;
SizeT End;
bool isNegative;
BigInteger(SizeT,DATATYPE,bool);
void datacopy(BigInteger const&,SizeT);
SizeT datalen(DATATYPE const*) const;
void deallocateBigInteger();
void TrimZeros();
void Set(DATATYPE);
public:
BigInteger();
BigInteger(long);
BigInteger(char const*);
BigInteger(BigInteger const&);
~BigInteger();
int UnsignedCompareTo(BigInteger const&)const;
int CompareTo(BigInteger const&)const;
SizeT Digits() const;
bool isValidNumber() const;
bool isZero()const;
BigInteger& Add(BigInteger const&) const;
BigInteger& Subtract(BigInteger const&) const;
BigInteger& Multiply(BigInteger const&) const;
BigInteger& Multiply(DATATYPE const&) const;
BigInteger& DivideAndRemainder(BigInteger const&,BigInteger&,bool) const;
BigInteger& DivideAndRemainder(DATATYPE const&,DATATYPE&,bool) const;
friend BigInteger& operator+(BigInteger const&, BigInteger const&);
friend BigInteger& operator-(BigInteger const&, BigInteger const&);
friend BigInteger& operator*(BigInteger const&, BigInteger const&);
friend BigInteger& operator*(BigInteger const&, DATATYPE const&);
friend BigInteger& operator*(DATATYPE const&, BigInteger const&);
friend BigInteger& DivideAndRemainder(BigInteger const&, BigInteger const&,BigInteger&,bool);
friend BigInteger& DivideAndRemainder(BigInteger const&, DATATYPE const&,DATATYPE&,bool);
friend BigInteger& operator/(BigInteger const&, BigInteger const&);
friend BigInteger& operator/(BigInteger const&, DATATYPE const&);
friend BigInteger& operator/(DATATYPE const&, BigInteger const&);
friend BigInteger& operator%(BigInteger const&, BigInteger const&);
friend BigInteger& operator%(BigInteger const&, DATATYPE const&);
friend BigInteger& operator%(DATATYPE const&, BigInteger const&);
BigInteger& operator=(BigInteger const&);
friend ostream& operator<<(ostream& , BigInteger const&);
friend istream& operator>>(istream& , BigInteger& );
BigInteger& operator++();
BigInteger& operator++(int);
BigInteger& operator--();
BigInteger& operator--(int);
BigInteger& operator-();
BigInteger& operator<<(SizeT);
BigInteger& operator>>(SizeT);
void abs();
friend BigInteger& abs(BigInteger&);
int toInt();
long toLong();
BigInteger& Power(long )const;
BigInteger& SquareRoot() const;
};
int main(){
char input1[size],input2[size];
BigInteger result;
freopen("input.in","rt",stdin);
while(scanf("%s %s",&input1,&input2)==2){
BigInteger temp1(input1),temp2(input2);
result=temp1*temp2;
cout<<result<<endl;
}
return 0;
}
Riyad
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN
10106 WA HELP ME
my code is below.every thing is ok.but judge reply wa.i m frustated.help me about this problem
/* @JUDGE_ID: xxxxxx 10106 C++ */
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#define MAX 10000
static char x[MAX],s[MAX],z[MAX];
void mul ()
{
int p,q,r,l,m,tag,u,tag1,i,t,j,k,tag2=0;
for(r=0;r<=MAX-1;r++)
z[r]='0';
tag=strlen(x)-1;
tag1=strlen(s)-1;
for(i=tag, m=0;i>=0;i--,m++)
{
for(j=tag1,k=0+m;j>=0;k++,j--)
{
l=k;
r=x-48;
q=s[j]-48;
p=r*q;
while(p!=0)
{
p=p+z[l] -48;
z[l]=(p%10)+'0';
u=p%10;
p=(p-u)/10;
l++;
}
}
}
for(i=MAX-1;i>=0;i--)
{
if(z=='0')
tag2++;
else break;
}
for(i=MAX-1-tag2;i>=0;i--)
printf("%c",z);
printf("\n");
}
void main()
{
while(scanf("%s%s",x,s)!=EOF)
{
mul();
}
}
/* @JUDGE_ID: xxxxxx 10106 C++ */
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#define MAX 10000
static char x[MAX],s[MAX],z[MAX];
void mul ()
{
int p,q,r,l,m,tag,u,tag1,i,t,j,k,tag2=0;
for(r=0;r<=MAX-1;r++)
z[r]='0';
tag=strlen(x)-1;
tag1=strlen(s)-1;
for(i=tag, m=0;i>=0;i--,m++)
{
for(j=tag1,k=0+m;j>=0;k++,j--)
{
l=k;
r=x-48;
q=s[j]-48;
p=r*q;
while(p!=0)
{
p=p+z[l] -48;
z[l]=(p%10)+'0';
u=p%10;
p=(p-u)/10;
l++;
}
}
}
for(i=MAX-1;i>=0;i--)
{
if(z=='0')
tag2++;
else break;
}
for(i=MAX-1-tag2;i>=0;i--)
printf("%c",z);
printf("\n");
}
void main()
{
while(scanf("%s%s",x,s)!=EOF)
{
mul();
}
}
arahman
Input:
4738787878
87897987
333
333
87897987
4738787878
00000000
0
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
Output:
416529915296201586
110889
416529915296201586
0
2469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308642
4738787878
87897987
333
333
87897987
4738787878
00000000
0
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
Output:
416529915296201586
110889
416529915296201586
0
2469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135802469135308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308641975308642
My signature:
- Please make discussion about the algorithm BRFORE posting source code.
We can learn much more in discussion than reading source code. - I HATE testing account.
- Don't send me source code for debug.
-
- Learning poster
- Posts: 95
- Joined: Mon Apr 26, 2004 1:23 pm
- Location: Hong Kong and United States
- Contact:
10106 Product
I used a standard way to do it by using string.
But I got a TLE, how come?????
Thanks for help!!
[cpp]#include <iostream>
#include <string>
using namespace std;
int main()
{
string p,h;
while (!cin.eof())
{
cin>>p>>h;
string y;
bool sky=true;
if (p[0]=='-')
{
sky=false;
p.erase(0,1);
}
if (h[0]=='-')
{
sky=!sky;
h.erase(0,1);
}
if (p.length()<h.length())
{
y=p;
p=h;
h=y;
}
for (int l=0;l<p.length()/2;l++)
{
char i=p[l];
p[l]=p[p.length()-l-1];
p[p.length()-l-1]=i;
}
for (int l=0;l<h.length()/2;l++)
{
char i=h[l];
h[l]=h[h.length()-l-1];
h[h.length()-l-1]=i;
}
y="";
for (int k=1;k<=p.length()+h.length();k++)
y+="0";
for (int l=0;l<h.length();l++)
{
int i=0;
for (int k=0;k<p.length();k++)
{
int s=(p[k]-'0')*(h[l]-'0')+i;
i=(s+y[k+l]-48)/10;
y[k+l]=static_cast<char>((s+y[k+l]-48)%10+48);
int u=k+l;
while (i>0)
{
u++;
s=(y-'0')+i;
i=s/10;
y=static_cast<char>(s%10+48);
}
}
}
for (int l=0;l<y.length()/2;l++)
{
char i=y[l];
y[l]=y[y.length()-l-1];
y[y.length()-l-1]=i;
}
while (y[0]=='0') y.erase(0,1);
if (y=="")
cout<<"0\n";
else
{
if (!sky) cout<<'-';
cout<<y<<endl;
}
}
return 0;
}[/cpp]
But I got a TLE, how come?????
Thanks for help!!
[cpp]#include <iostream>
#include <string>
using namespace std;
int main()
{
string p,h;
while (!cin.eof())
{
cin>>p>>h;
string y;
bool sky=true;
if (p[0]=='-')
{
sky=false;
p.erase(0,1);
}
if (h[0]=='-')
{
sky=!sky;
h.erase(0,1);
}
if (p.length()<h.length())
{
y=p;
p=h;
h=y;
}
for (int l=0;l<p.length()/2;l++)
{
char i=p[l];
p[l]=p[p.length()-l-1];
p[p.length()-l-1]=i;
}
for (int l=0;l<h.length()/2;l++)
{
char i=h[l];
h[l]=h[h.length()-l-1];
h[h.length()-l-1]=i;
}
y="";
for (int k=1;k<=p.length()+h.length();k++)
y+="0";
for (int l=0;l<h.length();l++)
{
int i=0;
for (int k=0;k<p.length();k++)
{
int s=(p[k]-'0')*(h[l]-'0')+i;
i=(s+y[k+l]-48)/10;
y[k+l]=static_cast<char>((s+y[k+l]-48)%10+48);
int u=k+l;
while (i>0)
{
u++;
s=(y-'0')+i;
i=s/10;
y=static_cast<char>(s%10+48);
}
}
}
for (int l=0;l<y.length()/2;l++)
{
char i=y[l];
y[l]=y[y.length()-l-1];
y[y.length()-l-1]=i;
}
while (y[0]=='0') y.erase(0,1);
if (y=="")
cout<<"0\n";
else
{
if (!sky) cout<<'-';
cout<<y<<endl;
}
}
return 0;
}[/cpp]
Last edited by cytmike on Fri May 14, 2004 7:44 am, edited 3 times in total.