ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1048. Superlong Sums

c program wa#4
Posted by shahmohammadi 18 Jul 2011 02:50
hello. can you help me.what is the test 4. where can i find it.

#include <stdio.h>

int a[1000000],b[1000000] ,c[1000000];
void main()
{
 int n,i,cr=0;
 scanf("%d",&n);

 for(i=0;i<n;i++)
 {
  scanf("%d %d",&a[i],&b[i]);
 }
 for(i=n-1;i>=0;i--)
 {
  c[i  ]= (a[i]+b[i])%10+cr;
  cr= (a[i]+b[i]+cr)/10;
 }
 for(i=0;i<n;i++)
 {
  printf("%d",c[i]);
 }
}
Re: c program wa#4
Posted by morbidel 18 Jul 2011 16:01
Try
21
3 4
9 0
0 9
1 8
2 7
3 6
4 5
5 4
6 3
7 2
8 1
9 0
0 9
1 8
2 7
3 6
4 5
5 4
6 3
7 2
9 1

Hint: try not to use arrays at all

Edited by author 18.07.2011 16:02
Re: c program wa#4
Posted by shahmohammadi 21 Jul 2011 15:18
thank you for your help. i am accepted.
Re: c program wa#4
Posted by shahmohammadi 21 Jul 2011 16:26
now i just use one array and got accepted.
0.671    4 032 KB

Edited by author 21.07.2011 16:27
Re: c program wa#4
Posted by morbidel 21 Jul 2011 16:45
congrats, but try not to use arrays at all!