aeiou, consider the following input. Your program returns 34.62 while the answer should be 27.85. By the way, if you want an alternative way to do it, you can consider writing each a in terms of a[1], a[0] and a constant. For instance, you can write a[2] as 2*(a[1]+c[1]) - a[0] and so forth until you can formulate a[n+1] in terms of a[1], a[0] and a constant. Then just solve for a[1].
1
2
50.50
43.45
10.15
10.15
10014 - Simple calculations
Moderator: Board moderators
10014 got time limit error
here is my code face time limt error how solve this problem
using this logic?
using this logic?
Code: Select all
#include<stdio.h>
int rec(long n)
{
if(n%10>0)
return n%10;
else if(n==0)
return 0;
else rec(n/10);
}
int main()
{
long p,q;
long sum=0;
long i;
while(scanf("%ld%ld",&p,&q)!=0)
{
if(p<0&&q<0)
break;
else
{
for(i=p;i<=q;i++)
sum+=rec(i);
}
printf("%ld\n",sum);
sum=0;
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10014 got time limit error
It looks like the wrong problem number. Try to think of a faster method. For example, if you were asked to sum the numbers from 1 to 1000000 would you iterate through them all?
Check input and AC output for thousands of problems on uDebug!
10014 - Simple calculations
I can't understand why I got WA? Can anyone please help me. Here is my code:
N.B: Code will be removed after AC.
Code: Select all
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n, test, i;
double sum;
double a1, a0, a2;
double ci[3002];
while(scanf("%d", &n) == 1)
{
cout<<endl;
sum = 0;
scanf("%d", &n);
scanf("%lf", &a0);
scanf("%lf", &a2);
for(i = 1; i <= n; i++)
{
scanf("%lf", &ci[i]);
}
for(i = 1; i <= n; i++)
{
sum += ci[i];
}
a1 = ((a0 + a2)/2) - sum;
printf("%0.2lf\n", a1);
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10014 - Simple calculations
Check input and AC output for thousands of problems on uDebug!