|
|
back to boardCommon Board1048 - Super long sums... HELP I still have troubles with this program, please help me, i don´t found the error. Here is my code #include <iostream> using namespace std; unsigned long int m, c; int *v, *v2; int main() { cin>>m; v=new int[m+5]; v2=new int[m+5]; for(c=0;c<m;c++) cin>>v[c]>>v2[c]; c=m-1; while(c>0) { v[c]+=v2[c]; if(v[c]>=10) { v[c-1]+=v[c]/10; v[c]%=10; } c--; } v[0]+=v2[0]; for(c=0;c<m;c++) cout<<v[c]; delete [] v; delete [] v2; return 0; } beforehand thanks... I see you have MLE (+) Posted by qwerty 19 Jul 2005 02:01 Of course you get Memory limit: You use 2 arrays, where each element int (4 bytes). If there are 1000000 digits, than You need 4000000 bytes, that grather than 1 MB. Try to think out any trick. Even use array of char, or ... Try to solve this easy problem yourself :) Good Luck Re: I see you have MLE (+) Thanks, i´m working in that, I just want to know the better way to do it. Thanks qwerty, I still work !! I see you can not to do it... (+) Posted by qwerty 19 Jul 2005 02:33 Try to store in every ceil of your array not 1 but more digits, i.e. use not 10-based nubmers, but 1000000-based. Or think more carefully and think out algo without arrays. Thats all. And try to solve other, more simple problems. For example 1000(A+B), or 1068. Good Luck. Ok, I try first other programs... Ok, I´ll try first other programs... Ok, I´ll take your advice. I will try other programs, because i have the idea but something is missing :p Thanks a lot, I appreciate your help If you want, I'll help you more. (+) Posted by qwerty 20 Jul 2005 14:49 My e-mail: barssimfi@mail.ru If you know russian, it is very good. I can help you, I can correct your codes and find some mistakes in this easy problems. |
|
|