Saturday, November 21, 2009

SPOJ: Some very easy problems

Its been a month since I have started coding in SPOJ. There are over 5000 problems present there. Its really gets very tough when one tries to get some easy problems from that lot. So, I dedicate this post to beginners. Go for the below mentioned problems.

Some very easy classical problems:

TEST- This is the first problem I solved in SPOJ. I recommend the same for you. It gives a brief introduction of the whole environment. What you need to do is to accept and print the input by the user until you come across 42. The easiest problem at SPOJ and a confidence booster to begin with..!! ;)

ADDREV- Take two numbers as input. Reverse both. Add the reversed number. Reverse again. Simple..!! The thing you need to keep in mind is that you have to provide the number of test cases first. While taking the inputs you can print the result too. You need not store them and print later.

FASHION- Quite big explanation of the problem (a bit interesting too ;) ). The only thing you need to keep in mind is that you have to sort the degree of hotness of men and women and then multiply and add them up. If you do not sort them, it will give a WA.

MIRRORED- Print "Mirrored pair" wherever you confront "bd" or "db" or "pq" or "qp", otherwise print "Ordinary pair". Don't forget to print "Ready" in the beginning. You do not have to take the test cases as input here. Just end the input when you confront two spaces. I got an AC at very first attempt..!! Hope the same for you.. :)

NSTEPS- Analize the graph properly. Whenever x and y co-ordinates are even the corresponding output is (x+y) for input (x=y) and (x=y-2). When they are odd the corresponding ouput is (x+y-1) for input (x=y) and (y=x-2). You can also do the problem with a different approach too. You can form a series for the numbers, and hence, generate the output.

OFORTUNE- Common.. don't get astonished by the enormous length of the question. Try tackling the problem. It just needs six inputs and a simple interest and compound interest formula implementation thats it.. Try it.. You will gain a hell lot of points..!!

Some very easy challenge problems:

SIZECON- The difficulty doesn't lie in the problem statement. The difficulty lies in the choice of programming language. I managed to do it in 96 characters. Best solution in c++ has 70 characters in it. Perl language wins with just 6 characters..!!

BFWRITE- I have already written a post about this problem. Try learning Brainf_ck language and solve this problem too. Here's the link to my post.

More easy problems are being searched. Kindly mention some in comments if you confront one.. Here's my SPOJ handle.. vaibhav_pandey.

* * * * *

6 comments:

  1. I tried OFORTUNE but ended up losing precision somewhere! :(

    ReplyDelete
    Replies
    1. even i lost precision due to typecasting somewhere :(

      Delete
  2. Hi there!
    As I'm fairly new to spoj contest, I have faced a little problem, that is, I feel the last test case is not ended with a newline(enter) in every problem. So I think each time I submit a source code, It waits for a newline and I get TLE. This , even happens for somehow easy problems that I've got annoyed :(
    Can you help me with this?

    ReplyDelete
  3. @boris.. try and get help from SPOJ forum.

    @masood.. try "while(cin>>input)" for questions using a file as an input.

    ReplyDelete
  4. this my code almost my logic is correct in two ways but the complier tell that it is wrong answer
    the link for code is
    https://www.spoj.pl/problems/NSTEPS/
    code is following is any one help me
    thanks i advance
    my main id is= rajisekra.d@gmail.com
    waiting for u r respince

    code 1:
    #include


    int main()
    {
    int out[200000],n,x,y,z=0;
    long int i;
    scanf("%d",&n);

    for(i=0;i


    int main()
    {
    int out[10000],n,x,y,z=0,i;
    scanf("%d",&n);

    for(i=0;i<n;i++)
    {
    scanf("%d%d",&x,&y);
    if(x==y)
    {
    if(x%2==1)
    z=(x*2)-1;
    else
    z=x*2;
    }
    else if((x-2)==y)
    {
    if(x%2==0)
    z=(y*2)+2;
    else
    z=(y*2)+1;
    }
    else
    z=0;
    out[i]=z;
    }
    for(i=0;i<n;i++)
    { if(out[i]!=0)
    printf("%d\n",out[i]);
    else
    printf("No Number\n");
    }
    return 0;

    }

    ReplyDelete
  5. hey.. use spoj forums (https://www.spoj.pl/forum). And yaa.. plzz don't post your source code as comments to SPOJ probelms.. coders hate that..

    ReplyDelete