Page 14 of 15

Re: 10013 - Super Long Sums

Posted: Mon Nov 11, 2013 11:32 pm
by brianfry713
There is a blank line between output blocks.

Re:

Posted: Sat May 24, 2014 9:36 pm
by 20717TZ
tenshi wrote:check this case:

1

4
0 9
0 9
0 9
1 9
This is an invalid input, because
Each of the two given integers is not less than 1, and the length of their sum does not exceed M.

Re: 10013 - Super long sums

Posted: Thu Sep 11, 2014 9:05 am
by sajal2k8
Getting RE. Please help:
#include <iostream>

using namespace std;

int main()
{
long long int a,b,c,num[10000],num1[10000],i=0,sum=0,k=0,res[10000];
cin>>a;
while(a--)
{
cin>>b;
while(b--)
{
cin>>num;
cin>>num1;
i++;
}
for(int j=i-1;j>-1;j--)
{
c=num[j]+num1[j];
if(c>9 && j!=0)
{
res[k]=c-10;
k++;
num[j-1]=num[j-1]+1;
}
else
{
res[k]=c;
k++;
}
}
for(int j=k-1;j>-1;j--)
cout<<res[j];
cout<<endl;
if(a!=0)
cout<<endl;
sum=0;i=0,k=0;

}
return 0;
}
Thanks in advance :)

Re: 10013 - Super long sums

Posted: Thu Sep 11, 2014 9:31 pm
by brianfry713
1<=M<=1000000

Re: 10013 - Super long sums

Posted: Sat Sep 13, 2014 9:36 pm
by mgavin2
is using java BigInteger TLE? I can't seem to optimize a java solution enough to pass the time limit.

Re: 10013 - Super long sums

Posted: Mon Sep 15, 2014 8:41 pm
by brianfry713
Try solving it without using BigInteger, just sum and print using int arrays.

Re: 10013 - Super long sums

Posted: Sat Oct 11, 2014 11:40 am
by axelblaze
I getting WA...
Please help me...

Code: Select all

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

int main()
{
    //freopen("in.txt","r",stdin);
    int n,m,carry,j;
    short temp;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        if(i) cout<<endl;
        carry=0;
        cin>>m;
        short int a[m],b[m],ans[m];
        for(j=m-1;j>=0;j--)
            cin>>a[j]>>b[j];
        for(j=0;j<m;j++)
        {
            temp=a[j]+b[j];
            ans[j]=temp%10+carry;
            carry=temp>9;
        }
        for(j=m-1;j>=0;j--)
            cout<<ans[j];
        cout<<endl;
    }
    return 0;
}

Re: 10013 - Super long sums

Posted: Sat Oct 11, 2014 12:56 pm
by lighted
Input

Code: Select all

1

3
1 2
7 2
2 8
Acc Output

Code: Select all

400

Re: 10013 - Super long sums

Posted: Sat Oct 11, 2014 1:35 pm
by axelblaze
Thanks I got AC.. It was a silly mistake though.. I wasn't carefull..
Thanks again.. :)

Re: 10013 - Super long sums

Posted: Wed Oct 15, 2014 2:07 pm
by ashek.rahman
Removed. Solved. :D :lol:

Re: 10013 - Super long sums

Posted: Fri Oct 17, 2014 8:01 am
by nasim.ruet
Please help me. I got time limit. :evil:

Code: Select all

import java.util.Scanner;

public class Main {

	private static Scanner scanner;

	public static void main(String[] args) {
		scanner = new Scanner(System.in);
		int n, m;
		short temp, carry = 0;
		char ch;
		short[] firstAra = new short[1000005];
		short[] secondAra = new short[1000005];


		while (scanner.hasNext()) {
			n = scanner.nextInt();
			for (int j = 0; j < n; j++) {
				m = scanner.nextInt();
				for (int k = 0; k < m; k++) {
					firstAra[k] = scanner.nextShort();
					secondAra[k] = scanner.nextShort();
				}
				String string = "";
				carry = 0;
				for (int k = m - 1; k >= 0; k--) {
					temp = (short) (firstAra[k] + secondAra[k] + carry);
					if (temp > 9) {
						temp = (short) (temp % 10);
						carry = 1;
					} else {
						carry = 0;
					}
					ch = (char) temp;
					ch += 48;
					string = string + ch;
				}
				if (carry == 1) {
					string = string + 1;
				}
				StringBuffer buffer = new StringBuffer(string);
				System.out.println(buffer.reverse() + "\n");
			}

		}

	}

}

thanks in advance. :wink:

Re: 10013 - Super long sums

Posted: Fri Oct 17, 2014 10:16 pm
by brianfry713
Try using BufferedReader and BufferedWriter.

Re: 10013 - Super long sums

Posted: Thu Nov 27, 2014 10:58 pm
by Karkat_Vantas
I don't understand why my code is giving me a submission error. It seems to work on the sample cases and what I can find in this forum. Can someone please explain why this is occuring? Thank you for your help.

Code: Select all

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int trials = in.nextInt();
		StringBuilder a;
		StringBuilder b;
		int l;
		for (int tr = 1; tr <= trials; tr++) {
			a=new StringBuilder("");
			b=new StringBuilder("");
			l=in.nextInt();
			for(int j=0;j<l;j++)
			{
				a=a.append(in.next());
				b=b.append(in.next());
			}
			BigInteger z = new BigInteger(a.toString());
			BigInteger x = new BigInteger(b.toString());
			System.out.println(z.add(x));
			if(tr!=trials)
				System.out.println("");
		}

	}
}

Re: 10013 - Super long sums

Posted: Fri Nov 28, 2014 1:14 pm
by lighted
Sometimes it happens. Try it again. Judge gives TLE for your code.
brianfry713 wrote:Try using BufferedReader and BufferedWriter.

Re: 10013 - Super long sums

Posted: Sun Jan 11, 2015 10:03 am
by bgcsaif
it is said that "each of the two given integers is not less than 1"..... but in sample input there is given 0 as one of the integers..... is there anything i understood wrong???