Page 4 of 7

didn't understand

Posted: Wed May 17, 2006 6:49 pm
by eyeabhi
Hi a123123123888,

I didn't understand wht u tried to say.

But i have solved the problem. It had the problem with the size of the array.

Thank u.

Posted: Thu Jun 15, 2006 4:51 pm
by marcpacios
I'm trying it with Java, but it sais Compilation Error, but in my computer it runs good.

I'm using BigInteger.

Does anyone know why?

Posted: Tue Jun 20, 2006 4:49 pm
by taskin
java suporrt in judge is not good. i think class BigInteger is not available yet. read this
http://acm.uva.es/problemset/java.html

Posted: Wed Aug 16, 2006 4:50 pm
by nev4
This one is really in judge input:

000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000

or

0000000000000000000000000000000000000000000000000
4566515645624562456254625462542642434323432343341

Posted: Fri Mar 09, 2007 9:00 pm
by Jemerson
Guys, don't know what is wrong with my code, can anyone help me?

I'm a Java programmer and C++ noob. I used BigInteger library found here:

http://www.comp.nus.edu.sg/~stevenha/pr ... gInteger.h

My code follows:

Code: Select all


#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <malloc.h>
#include <cmath>
#include <cstring>
#include <ctime>
#include <strstream>
#include <string>
#include <stdexcept>

using namespace std;

/* BigInteger class here... Copied integrally as found on the above url */

using namespace BigMath; // compulsory

int main() {
  char str[1000];
  while (cin >> str) {   
	BigInteger& n1 = *new BigInteger(str);
	cin >> str;
	BigInteger& n2 = *new BigInteger(str);
        n1 = n1 * n2;
        cout << n1 << endl;
  }	
}


Posted: Fri Sep 07, 2007 8:02 pm
by ashis.csedu
What is the problem with my code - it's getting WA.
I've read all the posts, that's why I've ommited any leading zeros...increased the size of the arrays...Please check it.

Code: Select all

Thanks Jan, 
Removed code after getting Accepted.
I've also checked with all the I/O in posted corresponding threads...

Posted: Fri Sep 07, 2007 11:22 pm
by Jan
I think your code is right. Try using

Code: Select all

while(scanf("%s %s",a,b)==2)
{
}
Hope it helps.

Posted: Sat Sep 08, 2007 7:25 am
by ashis.csedu
Thanks Jan,
Your point is right. Taking input using gets() is wrong in the following inputs...(Leading spaces in a line jeopardized my procedures). Good observation!!

Code: Select all

Sample Input:
0000005
     1250000
    1 
	   00000000000000
    12
50
      0
  100001
    5 
80100

Code: Select all

Sample Output:
6250000
0
600
0
400500

I Got WA...

Posted: Mon Feb 18, 2008 8:21 pm
by kantaki
I got WA with my code.

Having tested many cases, I got correct value I think.

please help me.

Code: Select all

I got AC.

Posted: Wed Feb 27, 2008 8:57 pm
by turcse143
Thanks ashis da
i got AC
ur input-output set
helps me a lot

10106 - Product geting WA

Posted: Mon Jun 09, 2008 7:41 am
by nahid
I've read all the posts about this problem.and tried all the critical inputs, but, still WA. here is my code.

Code: Select all

#include<stdio.h>
#include<string.h>
#define SIZEXYI 255
#define SIZEXYJ 510

int main()
{
	char a[255],b[255];
	int x[255],y[255],xy[SIZEXYI][SIZEXYJ],i,j,alen,blen,car,p,res[550];
	
	while(scanf("%s %s",a,b)==2)
	{

		alen = strlen(a); blen = strlen(b);
		

		for(i=alen-1;i>=0;i--)        
		{
			x[alen-1-i] = a[i]-48;
		}
		x[alen] = -1;                 
		
		for(i=blen-1;i>=0;i--)
		{
			y[blen-1-i] = b[i]-48;
		}
		y[blen] = -1;

		for(i=0;i<SIZEXYI;i++)
		{
			for(j=0;j<SIZEXYJ;j++)
			{
				xy[i][j] = 0;		
			}
		}

		for(i=0;x[i]!=-1;i++)
		{
			for(j=0;j<i;j++)
				xy[i][j] = 0;  

			car = 0;
			for(j=0;y[j]!=-1;j++)
			{
				p = x[i]*y[j] + car;    
				car = p/10;
				xy[i][j+i] = p%10;
			}
			if(car>0)
				xy[i][j+i] = car;
		}
		
		car = 0;
		
		for(j=0;j<SIZEXYJ;j++)
		{
			p = 0;
			for(i=0;i<SIZEXYI;i++)
			{
				p = p + xy[i][j];		
			}
			p = p + car;
			car = p/10;
			res[j] = p%10;
		}

		for(j = SIZEXYJ; j>=0; j--)
		{
			if(res[j]>0)
				break;
		}
		if(j==-1)
			printf("0");
		for(; j>=0; j--)
			printf("%d",res[j]);

		printf("\n");	
	}
	return 0;
}

WA: 10106 - Product, plz help me!!

Posted: Mon Sep 29, 2008 4:38 am
by anowar_jaman
Hi,
Everytime I submit my code, I just get a WA. :cry: I rechecked my code a lot, but wasn't able to find the bug. Would you plz see my code and kindly tell me
where I am doing the mistake. I coded my own big_int class and used it in this problem. Only those methods which are used in the main function are given with their respective body for your comfort to read. Thanks in advance, I really need ur help :cry:

Code: Select all

#include <string>
#include <iostream>
#include <cstdio>
using namespace std;

class big_int{
public:
	string num;

protected:
	big_int operator+(string a)
	{
		big_int s;
		
		s = num + a;

		return s;
	}

	big_int operator+(char* a)
	{
		big_int s;

		s = num + a;

		return s;
	}

public:
	big_int(){num = "";}
	big_int(string a){num = a;}

	void reverse(); //ok

	void remove_0()
	{
		if(num[0] == '0')
		{
			int i = (int)num.find_first_not_of('0');
			num.erase(0, i);
		}

		if(num.size() == 0)
			num = "0";
	}

	size_t size(){return num.size();}

	string get(){return num;} //ok

	//*string get_ref(){return &num};

	big_int root();

	big_int operator=(big_int a); //ok
	big_int operator=(string a); //ok
	big_int operator=(int a); //ok
	big_int operator=(char *a); //ok

	big_int operator+(big_int a); //ok
	big_int operator+(int a); //ok

	big_int operator-(big_int a);
	big_int operator-(int a);

	big_int operator*(big_int a); //ok
	big_int operator*(int a);//ok

	big_int operator/(big_int a); 
	big_int operator/(int a); // ok

	bool operator<(big_int a);//ok
	bool operator>(big_int a);//ok
	bool operator==(big_int a);//ok
	bool operator!=(big_int a);//ok
	bool operator<=(big_int a);//ok
	bool operator>=(big_int a);//ok
};

big_int big_int::operator=(big_int a)
{
	num = a.get();

	return *this;
}
big_int big_int::operator=(string a)
{
	num = a;

	return *this;
}
big_int big_int::operator=(int a)
{
	//char add_str[2];
	//add_str[1] = 0;
	
	num = "";

	while(a)
	{
		//add_str[0] = a%10 + '0';
		//num = num + add_str;
		num.push_back(a%10 + '0');
		a /= 10;
	}

	reverse();
	remove_0();

	return *this;
}
big_int big_int::operator=(char* a)
{
	string b = a;
	num = b;

	return *this;
}

void big_int::reverse()
{
	int i, j;

	j = num.size();

	for(i=0, j--; i<j; i++, j--)
		num[i] ^= num[j] ^= num[i] ^= num[j]; 

	return;
}

char a[260], b[260];

int main()
{
	big_int num1, num2, result;

	while(scanf(" %s %s", a, b) == 2)
	{
		num1 = a;
		num2 = b;

		num1.remove_0();

		result = num1*num2;

		//cout<<result.num<<endl;

		for(int i=0; i<result.num.size(); i++)
			printf("%c", result.num[i]);
		printf("\n");
	}

	return 0;
}

big_int big_int::operator*(big_int a)
{
	remove_0();
	a.remove_0();

	int len, len_a, i, j, carry, temp;
	big_int result;

	if(num == "0" || a.num == "0")
	{
		result = "0";
		return result;
	}

	reverse();
	a.reverse();

	num.push_back('0');
	a.num.push_back('0');

	len = num.size();
	len_a = a.num.size();

	carry = 0;

	for(i=0; i<len; i++)
	{
		//if(num[i] == '0')
		//	continue;

		for(j=0, carry = 0; j<len_a; j++)
		{
			//if(a.num[j] == '0')
			//	continue;

			temp = (num[i] - '0') * (a.num[j] - '0') + carry;

			if((i+j)<result.num.size())
			{
				temp += result.num[i+j] - '0';
				result.num[i+j] = temp%10 + '0';
			}
			else
				result.num.push_back(temp%10 + '0');

			carry = temp/10;
		}

		if(carry)
			result.num.push_back(carry + '0');
	}

	result.reverse();
	result.remove_0();

	reverse();

	return result;
}

Re: 10106 - Product

Posted: Thu Apr 07, 2011 9:01 am
by anjanpstu
I am always getting wa in this problem.But I think all input gives right output help me

Code: Select all


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
 char sr1[2500],ctr,ctr1;char sr2[2500];char sr3[3000];char sr4[3000];char sr5[3000];char sr6[3000];long long int rt,rt1;
 long long int max,min;long long int count;long long int h;
 //freopen("12.in","rb",stdin);
    while((scanf("%s %s",&sr1,&sr2))==2)
    {
        long long int rem=0;long long int res=0;long long int rem1=0;long long int res1=0;long long int rem2=0;long long int res2=0;long long int rem3=0;long long int res3=0;
        long long int l11=strlen(sr1);
        long long int l22=strlen(sr2);
          if(sr1[0]=='-')
              {
            for(long long int i=0;i<l11-1;i++)
               sr1[i]=sr1[i+1];
            sr1[l11-1]='\0';
              }

         if(sr2[0]=='-')
              {
            for(long long int i=0;i<l22-1;i++)
                sr2[i]=sr2[i+1];
             sr2[l22-1]='\0';
              }

    long long int l1=strlen(sr1);
    long long int l2=strlen(sr2);
    long long int l3;
       for(long long int i=0;i<l1/2;i++){char d=sr1[l1-i-1];sr1[l1-i-1]=sr1[i-1+1];sr1[i-1+1]= d;}
          sr1[l1]='\0';
      for(long long int i=0;i<l2/2;i++){char d=sr2[l2-i-1];sr2[l2-i-1]=sr2[i-1+1];sr2[i-1+1]= d;}
         sr2[l2]='\0';

if(l1>=l2)
{
  for(long long int j=0;j<l2;j++){char d1=sr2[j];int t1=d1-'0';
      for(long long int i=0;i<l1;i++){char d2=sr1[i];int t2=d2-'0';
      if(i<(l1-1)){long long int mul=(t1*t2)+rem;rem=mul/10;res=mul%10;char d3=res+'0';sr4[i]=d3;}
         else if(i==(l1-1)){long long int mul=(t1*t2)+rem;rem=mul/10;res=mul%10;
          if(rem>0)
          {char d4=res+'0';char d5=rem+'0';
          sr4[i]=d4;sr4[i+1]=d5;
          sr4[i+2]='\0';}
          else if(rem<=0)
          {char d4=res+'0';
           sr4[i]=d4;sr4[i+1]='\0';}rem=0;
         }
         else
         {
         }
      }

   if(j<1)
   {
 l3=strlen(sr4);
   for(long long int k=0;k<l3;k++)
   {
      char d6= 0+'0';
      sr3[k]=d6;
   }
  sr3[l3]='\0';
  for(long long int k1=0;k1<l3;k1++)
   {
    char d7=sr3[k1];
    int t3=d7-'0';
    char d8=sr4[k1];
    int t4=d8-'0';
    int t5=t3+t4;
    char d9=t5+'0';
    sr3[k1]=d9;
   }
   sr3[l3]='\0';
   }

    if(j>=1)
   { long long int l32=strlen(sr3);
       for(long long int i=0;i<l32/2;i++)
      {
     char d=sr3[l32-i-1];
     sr3[l32-i-1]=sr3[i-1+1];
     sr3[i-1+1]= d;
      }
     sr3[l32]='\0';
       long long int l4=strlen(sr4);
long long int r9=j+l4;
long long int r10=j;
for(int k7=0;k7<r9;k7++)
 {
   if(k7<r10)
   {
     char d10=0+'0';
     sr5[k7]=d10;
   }
   else if(k7>=r10)
   {
       char d11=sr4[k7-r10];
       sr5[k7]=d11;
   }
sr5[r9]='\0';
 }
long long int l6=strlen(sr3);
long long int l5=strlen(sr5);
long long int r11=l5-l6;
if(r11<=0)
{
for(long long int k11=0;k11<l6;k11++)
{
  char d16=sr3[k11];
    sr6[k11]=d16;
}
sr6[l6]='\0';
for(long long int i=0;i<l6/2;i++)
   {
     char d=sr6[l6-i-1];
     sr6[l6-i-1]=sr6[i-1+1];
     sr6[i-1+1]= d;
   }
   sr6[l6]='\0';
   rem3=0;
long long int t12=strlen(sr6);
  for(long long int k10=0;k10<=t12;k10++)
   {
       char d14=sr5[k10];
       int u1=d14-'0';
       char d15=sr6[k10];
       int u2=d15-'0';
       if(u1>=0&&u2>=0)
       {
       long long int sum2=u1+u2+rem3;
         rem3=sum2/10;
         res3=sum2%10;
         char d16=res3+'0';
         sr3[k10]=d16;
       }
       else
            {
              long long int sum2=sum2;
                rem3=sum2/10;
                res3=sum2%10;
                 if(rem3>=1)
                     {
                     char d17=rem3+'0';
                      sr3[k10++]=d17;
                      sr3[k10++]='\0';
                     }
                     else
                     sr3[k10++]='\0';
            }
   }
}
else if(r11>0)
{
   for(long long int k8=0;k8<l5;k8++)
          {
       if(k8<r11)
       {
         char d12=0+'0';
         sr6[k8]=d12;
       }
       else if(k8>=r11)
       {
          char d13=sr3[k8-r11];
          sr6[k8]=d13;
       }
   }
   sr6[l5]='\0';
   for(long long int i=0;i<l5/2;i++)
   {
     char d=sr6[l5-i-1];
     sr6[l5-i-1]=sr6[i-1+1];
     sr6[i-1+1]= d;
   }
   sr6[l5]='\0';
   long long int t12=strlen(sr6);
  for(long long int k10=0;k10<=t12;k10++)

   {
       char d14=sr5[k10];
       int u1=d14-'0';
       char d15=sr6[k10];
       int u2=d15-'0';
       if(u1>=0&&u2>=0)
       {
       long long int sum1=u1+u2+rem2;
         rem2=sum1/10;
         res2=sum1%10;
         char d16=res2+'0';
         sr3[k10]=d16;
       }
       else
            {
             long long int sum1=sum1;
                rem2=sum1/10;
                res2=sum1%10;
                 if(rem2>=1)
                     {
                     char d17=rem2+'0';
                      sr3[k10++]=d17;
                      sr3[k10++]='\0';
                     }
                     else
                     sr3[k10++]='\0';
            }
         }
      }
    }
 }
}





           else if(l2>l1){
for(long long int j=0;j<l1;j++)
  {
     char d1=sr1[j];
     int t1=d1-'0';
      for(long long int i=0;i<l2;i++)
      {

          char d2=sr2[i];
          int t2=d2-'0';

         if(i<(l2-1))
         {
         long long int mul=(t1*t2)+rem;
          rem=mul/10;
          res=mul%10;
          char d3=res+'0';
          sr4[i]=d3;
         }
         else if(i==(l2-1))
         {
             long long int mul=(t1*t2)+rem;
          rem=mul/10;
          res=mul%10;
          if(rem>0)
          {
          char d4=res+'0';
          char d5=rem+'0';
          sr4[i]=d4;
          sr4[i+1]=d5;
          sr4[i+2]='\0';
          }
          else if(rem<=0)
          {
             char d4=res+'0';
             sr4[i]=d4;
             sr4[i+1]='\0';
          }
             rem=0;
         }
         else
         {
         }
      }

   if(j<1)
   {
 l3=strlen(sr4);
   for(long long int k=0;k<l3;k++)
   {
      char d6= 0+'0';
      sr3[k]=d6;
   }
  sr3[l3]='\0';
  for(long long int k1=0;k1<l3;k1++)
   {
    char d7=sr3[k1];
    int t3=d7-'0';
    char d8=sr4[k1];
    int t4=d8-'0';
    int t5=t3+t4;
    char d9=t5+'0';
    sr3[k1]=d9;
   }
   sr3[l3]='\0';
   }

    if(j>=1)
   {
      long long int l32=strlen(sr3);
       for(long long int i=0;i<l32/2;i++)
      {
     char d=sr3[l32-i-1];
     sr3[l32-i-1]=sr3[i-1+1];
     sr3[i-1+1]= d;
      }
     sr3[l32]='\0';

       long long int l4=strlen(sr4);
long long int r9=j+l4;
long long int r10=j;
for(long long int k7=0;k7<r9;k7++)
 {
   if(k7<r10)
   {
     char d10=0+'0';
     sr5[k7]=d10;
   }
   else if(k7>=r10)
   {
       char d11=sr4[k7-r10];
       sr5[k7]=d11;
   }
sr5[r9]='\0';
 }
long long int l6=strlen(sr3);
long long int l5=strlen(sr5);
long long int r11=l5-l6;
if(r11<=0)
{
for(long long int k11=0;k11<l6;k11++)
{
  char d16=sr3[k11];
    sr6[k11]=d16;
}
sr6[l6]='\0';
for(long long int i=0;i<l6/2;i++)
   {
     char d=sr6[l6-i-1];
     sr6[l6-i-1]=sr6[i-1+1];
     sr6[i-1+1]= d;
   }
   sr6[l6]='\0';
long long int t12=strlen(sr6);
  for(long long int k10=0;k10<=t12;k10++)
   {
       char d14=sr5[k10];
       int u1=d14-'0';
       char d15=sr6[k10];
       int u2=d15-'0';
       if(u1>=0&&u2>=0)
       {
       long long int sum2=u1+u2+rem3;
         rem3=sum2/10;
         res3=sum2%10;
         char d16=res3+'0';
         sr3[k10]=d16;
       }
       else
            {
              long long int sum2=sum2;
                rem3=sum2/10;
                res3=sum2%10;
                 if(rem3>=1)
                     {
                     char d17=rem3+'0';
                      sr3[k10++]=d17;
                      sr3[k10++]='\0';
                     }
                     else
                     sr3[k10++]='\0';
            }
   }
}
else if(r11>0)
{
   for(int k8=0;k8<l5;k8++)
          {
       if(k8<r11)
       {
         char d12=0+'0';
         sr6[k8]=d12;
       }
       else if(k8>=r11)
       {
          char d13=sr3[k8-1];
          sr6[k8]=d13;
       }
   }
   sr6[l5]='\0';
   for(long long int i=0;i<l5/2;i++)
   {
     char d=sr6[l5-i-1];
     sr6[l5-i-1]=sr6[i-1+1];
     sr6[i-1+1]= d;
   }
   sr6[l5]='\0';
   long long int t12=strlen(sr6);
  for(long long int k10=0;k10<=t12;k10++)

   {
       char d14=sr5[k10];
       int u1=d14-'0';
       char d15=sr6[k10];
       int u2=d15-'0';
       if(u1>=0&&u2>=0)
       {
       long long int sum1=u1+u2+rem2;
         rem2=sum1/10;
         res2=sum1%10;
         char d16=res2+'0';
         sr3[k10]=d16;
       }
       else
            {
             long long int sum1=sum1;
                rem2=sum1/10;
                res2=sum1%10;
                 if(rem2>=1)
                     {
                     char d17=rem2+'0';
                      sr3[k10++]=d17;
                      sr3[k10++]='\0';
                     }
                     else
                     sr3[k10++]='\0';
            }
         }
      }
    }
 }
           }

long long int l324=strlen(sr3);
for(long long int i=0;i<l324/2;i++)
      {
     char d=sr3[l324-i-1];
     sr3[l324-i-1]=sr3[i-1+1];
     sr3[i-1+1]= d;
      }
   sr3[l324]='\0';

     if(sr3[0]=='0')
     {
    for(long long int i=0;sr3[i]=='0';i++)
      count=i;
         h=count+1;
            if(h!=l324)
              {
       for(long long int j=h;j<strlen(sr3);j++)
          printf("%c",sr3[j]);printf("\n");
              }
              else if(h==l324)
                 printf("0\n");
      }
       else if(sr3[0]!='0')printf("%s\n",sr3);

      }
return 0;
}




Re: 10106 - Product

Posted: Sat Jul 02, 2011 7:25 pm
by plamplam
Hey anjanpstu....wtf is this? Do you know how long is your code? Exactly 444 lines.....man....what was on your mind when you wrote this? This can be solved very simply using string multiplication...try to make your code simple and shorter and avoid complexity all the time. But anyway I found your problem. Your program can't handle cases when the first number is less than the second number
Consider these two cases:

Code: Select all

284339888 9091
9091 284339888

Code: Select all

2584933921808
2584933921808
Your program just prints a blank line for the latter case :D :lol: :) :wink:

Re: 10106 - Product

Posted: Sat Jul 02, 2011 7:28 pm
by plamplam
@anowar jaman....Your program doesn't even pass the sample I/O....try checking with the sample I/O first next time before you post here.