Friday, December 14, 2007

Super long sums

Here's the problem statement: Super long sums
Accepted in the 7th try, after getting 6 Time Limit Exceeded errors. Moral of the story: don't use cin or cout as far as possible. Stick to ANSI C standards and use good ol' scanf and printf, though cumbersome!

#include "iostream"
#include "cstdio"

using namespace std;

main()
{
int a[1000000];
int n, i, j, x, y, m;

cin>>n;

for(i=0; i 0) printf("\n");
scanf("%d", &m);
for(j=0; j<m; j++) {
scanf("%d%d",&x,&y);
a[j] = x+y;
}
for(j--; j>=0; j--) {
if(a[j] > 9) {
a[j-1]++;
a[j] -= 10;
}
}
for(j=0; j<m; j++) printf("%d", a[j]);
printf("\n");
}

return 0;
}

No comments:

Contributors