1 / 4
Jun 2012

This is my code for SETNJA SPOJ in C (spoj.pl/problems/SETNJA/)
I am getting WA. Can someone provide good test case for this? Does the answer limit exceeds from unsigned long long?

#include<stdio.h>
typedef unsigned long long ULLD;
ULLD ans=0ull;
char str[10001];
int length;
void recurse(int i, ULLD temp)
{
	if(str[i]=='\0')
	{
		ans=ans+temp;
		return;
	}
	if(str[i]=='L') recurse(i+1,2*temp);
	else if(str[i]=='R') recurse(i+1,2*temp+1);
	else if(str[i]=='P') recurse(i+1,temp);
	else if(str[i]=='*')
	{
		recurse(i+1, 2*temp);
		recurse(i+1 , 2*temp +1);
		recurse(i+1, temp);
	}
}
int main()
{	
	scanf("%s",str);
	length=strlen(str);
	recurse(0,1);
	printf("%llu",ans);
	return 0;
}
  • created

    Jun '12
  • last reply

    Jun '12
  • 3

    replies

  • 314

    views

  • 2

    users

  • 1

    link

What do you think is the test case with the largest possible output? Have you tested it? Have you verified if ans exceeds long long at any point during that process?

If the output exceeds unsigned long long then how can I implement it? I am still learning programming and I don't know anything bigger than unsigned long long blush frowning
Or at least if you can provide some link about it, it would be very helpful for budding programmers smile

If you had to add two 64 digit numbers and all you had was a pencil and paper, could you do it?

If yes, then use arrays and do the same thing.

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 14 7d

Want to read more? Browse other topics in C and C++ or view latest topics.