10013 - Super long sums

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

Post by WR »

to alu_mathics,

in my opinion your last example is not correct. The problem statement says that the length of the sum does not exceed M. As M is 1, the answer 17 should not occur!

Haven't been accepted yet, so I'm not 100% certain but that's how I understand that sentence.

Bye

A1
Experienced poster
Posts: 173
Joined: Wed Jan 28, 2004 3:34 pm
Location: Bangladesh

10013 wa! Please help

Post by A1 »

I am getting Wrong answer again again, when all the input output seem to be Ok! :x :(
Here is my code:
[cpp]
I wait for three days but No Body help me :(
so I remove the code!
[/cpp]

what will be output for this input:

Code: Select all

1
2
9 9
9 9

A1
Experienced poster
Posts: 173
Joined: Wed Jan 28, 2004 3:34 pm
Location: Bangladesh

Post by A1 »

You have work hard for a easy problem! :-? It is just adding , read two digit and add them if carry or if result of this two is greater then 9 then store 1 for next pair of digit . so its is as easy as primary calculation. Just use char string to store result (no need to use long array) :)

JuaingFall
New poster
Posts: 13
Joined: Tue Aug 03, 2004 4:24 am
Location: CHINA

10013 Accepted (P.E.)

Post by JuaingFall »

who can help me? Thanks

Code: Select all

# include <stdio.h>
int main()
{
	long i,j,n,m;
	int num[1000000][2];
	scanf("%ld",&n);
	for(i=0;i<n;i++)
	{
		getchar();
		scanf("%ld",&m);
		for(j=0;j<m;j++)
			scanf("%d%d",&num[j][0],&num[j][1]);
		for(j=m-1;j>=0;j--)
		{
			if(num[j][0]+num[j][1]>=10)
			{
				num[j][0]=num[j][0]+num[j][1]-10;
				num[j-1][0]=num[j-1][0]+1;
			}
			else
				num[j][0]=num[j][0]+num[j][1];	
		}
		for(j=0;j<m;j++)
			printf("%d",num[j][0]);
		printf("\n");
		printf("\n");
	}
	return 0;
}

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

oopsi daisy

Post by sohel »

Hi,

The problem statement says that there is a blank line between two cases...
... which means there is no line after the very last case. :o
A portion of your code
[c]
for(j=0;j<m;j++)
printf("%d",num[j][0]);
printf("\n");
printf("\n");
[/c]

The second newline is not always necessary..

change this part of your code to

[c]
for(j=0;j<m;j++)
printf("%d",num[j][0]);
printf("\n");
if(i<n-1)
printf("\n");
[/c]

Hope it helps. :wink:

JuaingFall
New poster
Posts: 13
Joined: Tue Aug 03, 2004 4:24 am
Location: CHINA

Thanks

Post by JuaingFall »

sohel,Thank you indeed!
I got AC but no ( P.E.) :oops:

crisphean
New poster
Posts: 2
Joined: Thu May 27, 2004 5:04 am
Location: HK SAR
Contact:

thank you very much

Post by crisphean »

I've got AC~thank you very much~

but I am still wondering where the bug is~hahahaha

efr_shovo
New poster
Posts: 38
Joined: Wed Sep 22, 2004 9:09 am

10013 Why P.E

Post by efr_shovo »

/*Why 10013 got Pe Please Help*/

#include<stdio.h>

long long n,i;
long m,j,k,sum,l;
int fd1,data1[1000000],data2[1000000],sum1[1000000],d,fd;

void main()
{
scanf("%lld",&n);
printf("\n");
while(i<n)
{
scanf("%ld",&m);
if(m<1||m>1000000)
break;
for(j=0;j<m;j++)
{
scanf("%d",&data1[j]);
scanf("%d",&data2[j]);
}
for(k=j-1;k>=0;k--)
{
sum=data1[k]+data2[k]+fd;
fd=0;
if(sum>=10)
{
d=sum%10;
sum=d;
fd=1;
}
sum1[l]=sum;
l++;
}
if(fd==1)
{
sum1[l]=fd;
l++;
}
for(j=l-1;j>=0;j--)
printf("%d",sum1[j]);
l=0;
fd=0;
i++;
if(i<n)
printf("\n\n");
}
}

A1
Experienced poster
Posts: 173
Joined: Wed Jan 28, 2004 3:34 pm
Location: Bangladesh

Post by A1 »

Don't work hard with PE code :)
I think One should not post their accepted code here :-?

matrix2
New poster
Posts: 19
Joined: Wed Jul 21, 2004 11:14 am
Location: Suceava, Romania
Contact:

Post by matrix2 »

Probable you must not put a blank line after last case e.g printf("\n\n").
You can write in this way:

while(i < n)
{
/* ...... */
if(i == n)
printf("\n");
else
printf("\n\n");
}
Things are simple, but we make them complex.

efr_shovo
New poster
Posts: 38
Joined: Wed Sep 22, 2004 9:09 am

Again P.E

Post by efr_shovo »

I use your Techniq
"while(i < n)
{
/* ...... */
if(i == n)
printf("\n");
else
printf("\n\n");
}"

But Same P.E

jambon_vn
New poster
Posts: 15
Joined: Wed Sep 29, 2004 6:03 am

Post by jambon_vn »

1
9
8

matrix2
New poster
Posts: 19
Joined: Wed Jul 21, 2004 11:14 am
Location: Suceava, Romania
Contact:

Post by matrix2 »

Oh... I've forgot
Delete the line
printf("\n")
before while(i<n) from your source code and you'll get a clean AC.
Things are simple, but we make them complex.

branka
New poster
Posts: 4
Joined: Fri Sep 10, 2004 2:21 pm

10013, Igot WA. WHY?????????????? I NEAD HELP!!!

Post by branka »

Please, i nead help. Can someone pleas help me. I send my code and i always get WA.
If i have input:
1

3
1 2
4 5
5 5

the output is:
3100

and i don't know haw to make this right.

Here is my code in JAVA:

[java]

Code: Select all

import java.io.*;
import java.util.*;

class Super_long_sums
{
    static String ReadLn (int maxLg)  // utility function to read from stdin
    {
        byte lin[] = new byte [maxLg];
        int lg = 0, car = -1;
        String line = "";

        try
        {
            while (lg < maxLg)
            {
                car = System.in.read();
                if ((car < 0) || (car == '\n')) break;
                lin [lg++] += car;
            }
        }
        catch (IOException e)
        {
            return (null);
        }
        if ((car < 0) && (lg == 0)) return (null);  // eof
        return (new String (lin, 0, lg));
    }

    public static void main (String args[])  // entry point from OS
    {
        Main myWork = new Main();  // create a dinamic instance
        myWork.Begin();            // the true entry point
    }
    void Begin()
    {
        String input;
        StringTokenizer idata;
        int N;
        int stevec = 0;
        int M = 0;
        int prenesi = 0;
        input = Main.ReadLn (255);
        N = Integer.parseInt(input.trim());
        input = Main.ReadLn (255);

        while (stevec<N)
        {
            input = Main.ReadLn (255);
            M = Integer.parseInt(input.trim());
            if((N == 0) &&(M == 0))break;
              int tab1 [] = new int[M];
              int tab2 [] = new int[M];
              int rezultat [] = new int[M];
              for (int i=0; i <= M; i++)
              {
                input = Main.ReadLn (255);
                idata = new StringTokenizer (input.trim());
                tab1[i] = Integer.parseInt(idata.nextToken()); 
                tab2[i] = Integer.parseInt(idata.nextToken());
                rezultat[i] = tab1[i] + tab2[i] + prenesi;
                if(i>0 && rezultat[i] > 9){
				  prenesi = 1;              
                  rezultat[i] = rezultat[i]%10;
                  rezultat[i-1] = rezultat[i-1]+1;
                }//if
                else{
					prenesi = 0;
				}//else
              }//for
              stevec++;
              if(rezultat[0] > 9){           
				  break;
			  }
			  else{
              	System.out.println();
              	for(int k = 0; k < M; k++){
          			  System.out.print(rezultat[k]);
        	  	}
			  }
        	  System.out.println();
        	  System.out.println();
        } //while
     } //Begin()

} //class[/java]

 :oops:  :oops:  :oops: 

Plese help me!!!!! Thank you!!!! :D  :D

A1
Experienced poster
Posts: 173
Joined: Wed Jan 28, 2004 3:34 pm
Location: Bangladesh

Post by A1 »

For
1

3
1 2
4 5
5 5

My Accepted Code output is :

400

Post Reply

Return to “Volume 100 (10000-10099)”