10013 - Super long sums
Moderator: Board moderators
Re: 10013 - Super Long Sums
ac
Last edited by sreejond on Thu Jun 04, 2009 2:40 pm, edited 1 time in total.
Re: 10013 - Super Long Sums
When you use' %c' you should be careful.
Hope it helps.
Code: Select all
scanf("%c%c%c",&a[k],&ch,&b[k]); should be replaced with
scanf(" %c %c %c",&a[k],&ch,&b[k]);
Ami ekhono shopno dekhi...
HomePage
HomePage
Re: 10013 - Super Long Sums
vhaia,
sorry for disturbing again.
when i use scanf(" %c %c %c",&a[k],&ch,&b[k]);
my program give no ans.
one question more why i use "%c" like this.
thank you for your reply.
sreejon
cuet'06
sorry for disturbing again.
when i use scanf(" %c %c %c",&a[k],&ch,&b[k]);
my program give no ans.
one question more why i use "%c" like this.
thank you for your reply.
sreejon
cuet'06
Re: 10013 - Super Long Sums
The reason is scanf eliminates spaces. Thats why you shouldn't use %c for eliminating spaces.
Ami ekhono shopno dekhi...
HomePage
HomePage
TLE Help
Can anyone help with the following code? I've gotten TLE for all my submissions and I can't figure out how to optimize it more than where it is at. Thanks.
Code: Select all
#include <iostream>
#include <time.h>
#include <sstream>
#include <algorithm>
using namespace std;
int main() {
int cases = 0, digits = 0;
ostringstream s;
int v[1000010];
//clock_t start, end;
//start = clock();
cin >> cases;
while ( cases --> 0 ) {
cin >> digits;
int a, b;
for ( int i = 0; i < digits; i++ ) {
cin >> a >> b;
v[i] = a + b;
}
ostringstream s2;
for ( int i = digits - 1; i >= 0; i-- ) {
if ( v[i] >= 10 ) {
v[i - 1]++;
v[i] -= 10;
}
s2 << v[i];
}
string s2_rev = s2.str();
reverse(s2_rev.begin(), s2_rev.end());
s << s2_rev << endl;
if ( cases >= 1 ) s << endl;
}
cout << s.str();
//end = clock();
//printf ("%f seconds\n", ((float)end - (float)start) / 1000000.0F);
return 0;
}
10013 - Super Long Sums - WA
Hi, i got WA, and I don't know why, please, help me to debug it, where the code fails?
... thanks
Yes!, problem was "\n\n" to end.
Thanks!


Code: Select all
Removed After AC
Thanks!

Last edited by RoMeLuKo on Sat Nov 07, 2009 2:30 am, edited 1 time in total.
Luck!
Re: 10013 - Super Long Sums
why I am getting WA
I have passed all the test cases given in the boards
please some one check and tell me why WA
here is my code:
pls help 
I have passed all the test cases given in the boards
please some one check and tell me why WA
here is my code:
Code: Select all
Removed After AC

Last edited by abid_iut on Wed Dec 17, 2008 11:48 pm, edited 1 time in total.
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/
http://akanoi.webs.com/
-
- Learning poster
- Posts: 78
- Joined: Sun Nov 30, 2008 5:00 pm
- Location: IUT-OIC, Dhaka, Bangladesh
Re: 10013 - Super Long Sums
Your code is not AC because of this:
The problem description says:
Code: Select all
printf("\n\n");
Good luckThere is a blank line between output blocks.
May be tomorrow is a better day............ 

Re: 10013 - Super Long Sums
Thanks Articuno
Got AC!!
Got AC!!

i love to wait... wait for better... and better will come...
http://akanoi.webs.com/
http://akanoi.webs.com/
-
- Experienced poster
- Posts: 136
- Joined: Sat Nov 29, 2008 8:01 am
- Location: narayangong,bangladesh.
- Contact:
Re: 10013 - Super Long Sums
whats wrong with my code!!!
got WA.
got WA.
Code: Select all
#include<stdio.h>
#include<memory.h>
int sum[1000002];
int main()
{
int i,ndigit,a,b,ncount;
int c,count=1;
scanf("%d",&ncount);
while(count<=ncount)
{
memset(sum,0,sizeof(sum));
scanf("\n\n%d",&ndigit);
for(i=0;i<ndigit;i++)
{
scanf("\n%d %d",&a,&b);
c=0;
sum[i]=a+b;
}
for(i=ndigit-1;i>0;i--)
{
sum[i]=sum[i]+c;
if(sum[i]>=10){
c=1;
sum[i]=sum[i]%10;
}
else
c=0;
}
sum[i]=sum[i]+c;
for(i=0;i<ndigit;i++)
{
printf("%d",sum[i]);
}
if(count<ncount)
printf("\n\n");
count++;
}
return 0;
}
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
Re: 10013 - Super Long Sums
change this part
into this
hope it helps
Code: Select all
if(count<ncount)
printf("\n\n");
Code: Select all
if(count<ncount)
printf("\n\n");
else printf("\n");
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/
http://akanoi.webs.com/
Re: 10013 - Super Long Sums
Hi this is my code, can anybody tell me why is that i'm getting TLE please
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
long long cant;
char aux[10];
cin>>cant;
for(int i=0; i<cant; i++)
{
if(i>0) cout<<endl;
gets(aux);
int pares;
cin>>pares;
int num1, num2;
vector<int> resp;
for(int j=0; j<pares; j++)
{
cin>>num1>>num2;
resp.push_back(num1+num2);
}
reverse(resp.begin(),resp.end());
for(int j=0; j<(resp.size()-1); j++)
{
if(resp[j]>=10)
{
resp[j+1]+=1;
resp[j]%=10;
}
}
if(resp[resp.size()-1]>=10)
{
resp[resp.size()-1]=resp[resp.size()-1]%10;
resp.push_back(1);
}
reverse(resp.begin(),resp.end());
for(int j=0; j<resp.size(); j++)
cout<<resp[j];
cout<<endl;
}
return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
long long cant;
char aux[10];
cin>>cant;
for(int i=0; i<cant; i++)
{
if(i>0) cout<<endl;
gets(aux);
int pares;
cin>>pares;
int num1, num2;
vector<int> resp;
for(int j=0; j<pares; j++)
{
cin>>num1>>num2;
resp.push_back(num1+num2);
}
reverse(resp.begin(),resp.end());
for(int j=0; j<(resp.size()-1); j++)
{
if(resp[j]>=10)
{
resp[j+1]+=1;
resp[j]%=10;
}
}
if(resp[resp.size()-1]>=10)
{
resp[resp.size()-1]=resp[resp.size()-1]%10;
resp.push_back(1);
}
reverse(resp.begin(),resp.end());
for(int j=0; j<resp.size(); j++)
cout<<resp[j];
cout<<endl;
}
return 0;
}
Re: 10013 - Super Long Sums
choby123 wrote:Hi this is my code, can anybody tell me why is that i'm getting TLE please![]()
Code: Select all
gets(aux);
Code: Select all
vector<int> resp;
Code: Select all
if(resp[resp.size()-1]>=10)
{
resp[resp.size()-1]=resp[resp.size()-1]%10;
resp.push_back(1);
}
Solving for fun..
-
- New poster
- Posts: 1
- Joined: Tue Mar 31, 2009 2:52 am
Re: 10013 - Super Long Sums
Hey guys, I think I need some help here...
I don't think this problem is hard or anything, but i'm having a hell of a time to get AC here.
This is my code anyways:
I just keep getting TLE no matter what I do =/
heres my input file:
6
18
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
3
3 0
7 9
2 8
5
5 0
8 1
8 0
1 1
1 1
4
8 0
6 3
6 3
2 8
3
1 5
3 6
2 0
4
0 9
0 9
0 9
1 9
And heres the output:
1999999999999999998
470
59822
9000
692
10000
Now tnx in advance for any help =D!
I don't think this problem is hard or anything, but i'm having a hell of a time to get AC here.
This is my code anyways:
Code: Select all
#include <iostream>
#include <cstdlib>//10013
using namespace std;
unsigned long nums[2][1000001],n,m,carry=0;
int main()
{
cin>>n;for(int i=0;i<n;++i){cin>>m;memset(nums,0,sizeof(int)*2*1000001);
for(int j=m-1;j>=0;--j)cin>>nums[0][j]>>nums[1][j];carry=0;
for(int j=0;j<m;++j){nums[0][j]+=nums[1][j]+carry;carry = nums[0][j]/10;nums[0][j]%=10;if(carry && j==m-1)++m;}
if(i)cout<<endl;for(int j=m-1;j>=0;--j)cout<<nums[0][j];cout<<endl;}
return 0;
}
heres my input file:
6
18
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
9 9
3
3 0
7 9
2 8
5
5 0
8 1
8 0
1 1
1 1
4
8 0
6 3
6 3
2 8
3
1 5
3 6
2 0
4
0 9
0 9
0 9
1 9
And heres the output:
1999999999999999998
470
59822
9000
692
10000
Now tnx in advance for any help =D!
-
- New poster
- Posts: 24
- Joined: Fri Oct 24, 2008 8:37 pm
- Location: CUET, Chittagong, Bangladesh
- Contact:
Re: 10013 - Super Long Sums
Getting Runtime Error.....
Can anyone help me
Got AC. Thanks Obaida
Can anyone help me
Got AC. Thanks Obaida
Last edited by aliahmed on Tue Apr 07, 2009 10:50 pm, edited 1 time in total.