10994- Need help

All about problems in Volume CIX. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

10994- Need help

Postby dotnet12 » Sat Aug 18, 2012 11:01 am

The solution is correct but it exceeds time limit so what can I do about it? Please tell me anyone. Here is my solution:



#include <stdio.h>

int fu(int ab)
{

if(ab%10>0 && ab>0)
{
return ab%10;
}
else
{
return ab/10;
}
}

int S(int a,int b)
{
int ans=0,i;
for(i=a;i<=b;i++)
{
ans+=fu(i);

}
printf("%d", ans);
return 0;
}


int main()
{
int in1,in2,ans;
while((scanf("%d %d",&in1,&in2)==2) && (in1!=-1 && in2!=-1))
{

if(in1>in2)
{
S(in2,in1);

}
else
{
S(in1,in2);

}

}
return 0;


}
dotnet12
New poster
 
Posts: 4
Joined: Fri Aug 17, 2012 9:43 pm

Re: 10994- Need help

Postby brianfry713 » Mon Aug 20, 2012 10:54 pm

Don't double post.
brianfry713
Guru
 
Posts: 1754
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA


Return to Volume CIX

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron