10035 - Primary Arithmetic

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

Moderator: Board moderators

User avatar
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim » Sat Mar 24, 2007 10:54 am

You are not considering carry forwarded.

try the case:

input
999
989

output
3

Rushow
New poster
Posts: 14
Joined: Sat Oct 14, 2006 4:09 pm
Location: Dhaka,Bangladesh

Post by Rushow » Sat Mar 24, 2007 8:35 pm

You are not considering carry forwarded.

try the case:

input
999
989

output
3
I have tried this case.
And I have found output 3.
So, again question what's the problem? I have changed my code as below. But no result:

Code: Select all

/* p10035 */
/* Primary Arithmetic */

#include<stdio.h>
#include<math.h>
void main()
{
	unsigned long int n1,n2,r1,r2;
	int s,sum,num; 
	while(scanf("%lu%lu",&n1,&n2)!=EOF)
	{
		if(n1==0&&n2==0)
			break;
		s=0;num=0;
		while((n1>0)||(n2>0))
		{
			r1=n1%10;
			n1=n1/10;
			r2=n2%10;
			n2=n2/10;
			sum=r1+r2+num;
			if(sum>9)
			{
				s++;
				if(sum>9)
					num=sum-9;
			}

		}
		if(s==0)
			printf("No carry operation.\n");
		else if(s==1)
			printf("1 carry operation.\n");
		else
			printf("%d carry operations.\n",s);
	}
}
		
		

	
	

abdullah<cse du>
New poster
Posts: 39
Joined: Mon Dec 04, 2006 2:18 pm
Location: Bangladesh(CSE DU)
Contact:

Post by abdullah<cse du> » Sat Mar 24, 2007 10:12 pm

Hi,

Just try this input.

5210357 1245874

Correct output is : 3 carry operations.

But your output is : 4 carry operations.

You have done some mistakes in carry operation.

ABDULLAH.

ranacse05
New poster
Posts: 37
Joined: Wed Mar 28, 2007 5:08 pm
Location: Rajshahi
Contact:

10035~Help Me!!!

Post by ranacse05 » Sat Apr 07, 2007 3:19 pm

Any body plz tell me wheer is the error.
I don't find any error and i tryed all kind of I/O,but i got WA!


*************Code Removed***********
Last edited by ranacse05 on Sun Apr 08, 2007 10:42 pm, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Sat Apr 07, 2007 11:26 pm

Try input '99 1'.
Ami ekhono shopno dekhi...
HomePage

ranacse05
New poster
Posts: 37
Joined: Wed Mar 28, 2007 5:08 pm
Location: Rajshahi
Contact:

Post by ranacse05 » Sun Apr 08, 2007 8:47 am

I try it and the answer is 2 carry operations.Its ok,then where is the problem?

ranacse05
New poster
Posts: 37
Joined: Wed Mar 28, 2007 5:08 pm
Location: Rajshahi
Contact:

Post by ranacse05 » Sun Apr 08, 2007 8:58 am

Sorry that out put was ok in Turbo C but VC++ out put was wrong.
Pls cheack this one

********Code Removed***********
Last edited by ranacse05 on Sun Apr 08, 2007 10:36 pm, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Sun Apr 08, 2007 4:18 pm

Check your code again. What is 'n'? And why are you using it? And 'long unsigned int' doesn't make any sense. To post codes you can use the 'code' option from the editor. And you can remove your unnecessary codes by editing posts.
Ami ekhono shopno dekhi...
HomePage

ranacse05
New poster
Posts: 37
Joined: Wed Mar 28, 2007 5:08 pm
Location: Rajshahi
Contact:

Post by ranacse05 » Sun Apr 08, 2007 10:33 pm

Thanks Jan,at last i got AC,Can i Get ur email address?I'm in 3rd semister in RUET,(CSE).Some time i'll ask u for help bcoz this board take too much time. :lol:
I like to solve problems.

mahfuz05
New poster
Posts: 3
Joined: Fri Mar 30, 2007 6:26 am

Post by mahfuz05 » Sun Apr 15, 2007 3:39 pm

thanks spykaj i got ac.



.......******* CODE REMOVED******...........
Last edited by mahfuz05 on Mon Apr 16, 2007 9:26 am, edited 1 time in total.

User avatar
Spykaj
New poster
Posts: 47
Joined: Sun May 21, 2006 12:13 pm

Post by Spykaj » Sun Apr 15, 2007 5:41 pm

If you paste your code, use: You forget dots, it should be:

Code: Select all

if(carry==0) printf("No carry operation.\n");
instead of

Code: Select all

if(carry==0) printf("No carry operation\n");
Last edited by Spykaj on Mon Apr 16, 2007 8:16 pm, edited 1 time in total.

LZ
New poster
Posts: 2
Joined: Sun Apr 15, 2007 7:50 pm
Location: Indonesia

Post by LZ » Sun Apr 15, 2007 7:54 pm

I've been trying so many times but i still got WA. Please help me to find the mistakes.

#include<cstdio>
#include<cstdlib>
#include<cstring>

int main()
{
char a[15], b[15];
unsigned long int c=1,d=1;
int len, p, jml=0,ctr;



while(1)
{
ctr=0;

scanf("%s %s",&a ,&b);
sscanf(a,"%ld",&c);
sscanf(b,"%ld",&d);
if(c==0&&d==0)break;
if(strlen(a)>strlen(b))
{
len=strlen(a);
p=strlen(b)-1;
for(int i=len-1;i>=0;i--)
{
if(p>=0)
{
jml = jml + a[i]+b[p]-96;
p--;

}
else jml = jml + a[i]-48;

if(jml>9)
{
ctr++;
jml = jml/10;
}
else jml=0;
}
}

else
{
len=strlen(b)-1;
p=strlen(a)-1;
for(int i=len;i>=0;i--)
{
if(p>=0)
{
jml = jml + b[i]+a[p]-96;
p--;
}
else jml = jml + b[i]-48;

if(jml>9)
{
ctr++;
jml = jml/10;
}
else jml=0;
}
}


if(ctr==0)printf("No carry operation.\n");
else if(ctr==1)printf("1 carry operation.\n");
else printf("%d carry operations.\n", ctr);


}


return 0;
}

ranacse05
New poster
Posts: 37
Joined: Wed Mar 28, 2007 5:08 pm
Location: Rajshahi
Contact:

Post by ranacse05 » Sun Apr 15, 2007 8:07 pm

LZ why you take char when you can use long long int???
I like to solve problems.

LZ
New poster
Posts: 2
Joined: Sun Apr 15, 2007 7:50 pm
Location: Indonesia

Post by LZ » Sun Apr 15, 2007 8:17 pm

[quote="ranacse05"]LZ why you take char when you can use long long int???[/quote]

I'm just curious. Actually, i made another program using long but i still got WA. Here's the codes. Please check it if you're not busy. thx alot.

#include<cstdio>

int main()
{
long int a, b, input1, input2;
int ctr, jml=0, i;

while(a!=0||b!=0)
{
ctr=0;
scanf("%ld %ld", &a, &b);

input1=a;
input2=b;
for(i=0;i<10;i++)
{
jml = jml + input1%10 + input2%10;
input1/=10;
input2/=10;
if(jml>9)
{
ctr++;
jml = jml/10;
}
else jml=0;

if(input1==0&&input2==0)break;
}

if(ctr==0)printf("No carry operation.\n");
else if(ctr==1)printf("1 carry operation.\n");
else printf("%d carry operations.\n", ctr);

}

return 0;
}

User avatar
Spykaj
New poster
Posts: 47
Joined: Sun May 21, 2006 12:13 pm

Post by Spykaj » Sun Apr 15, 2007 8:48 pm

OMG USE: !!!!!!!!!!!

Post Reply

Return to “Volume 100 (10000-10099)”