Pages

Wednesday, November 20, 2013

How To Gift Amazon Prime Membership ?

How To Gift Amazon Prime Membership this Christmas ?

STEP 1: Go to Amazon Prime Page http://www.amazon.com/prime click here

STEP 2: Once you clicked on "give gift of prime" you will be redirected to "add Prime to cart Page".
               Now, click on "Add Prime to Cart" Button.
STEP 3: Click on "Proceed to checkout" Button.
    
STEP 4: You will be redirected to Gift Wrap Page. Enter email ID of gift recipient (to whom you want to give gift of Prime ), select Gift Delivery Date and Enter Gift message. Click on Continue button.

STEP 5: Select your Payment method and click on Continue Button.
STEP 6: Now you will be redirected to "Order review page". Review you order once before clicking   on "Place Your Order" Button. You can modify email ID of gift recipient, gift delivery date and Gift message for this page. Once you placed your order, gift recipient will get an gift redemption email on gift delivery date (which you selected on Gift wrap page).
 DONE .. :)

Sunday, November 10, 2013

SPOJ: Transform the Expression -- ONP

Problem Description


Click here for SPOJ link: ONP

Transform the algebraic expression with brackets into RPN form (Reverse Polish Notation). Two-argument operators: +, -, *, /, ^ (priority from the lowest to the highest), brackets ( ). Operands: only letters: a,b,...,z. Assume that there is only one RPN form (no expressions like a*b*c).

Input

t [the number of expressions <= 100]
expression [length <= 400]
[other expressions]
Text grouped in [ ] does not appear in the input file

Output

The expressions in RPN form, one per line.

Sample Input/Output

Input:
3
(a+(b*c))
((a+b)*(z+x))
((a+t)*((b+(a+c))^(c+d)))

Output:
abc*+
ab+zx+*
at+bac++cd+^*

Time limit: 5s
Source limit: 50000B
Memory limit: 256MB

Solution description of Transform the Expression - ONP


The solution of this problem is implementation of postfix notation using a stack.

Solution of Transform the Expression(ONP)in C++


#include <iostream>
#include <stack>
#include <cctype>
#include <cstring>
using namespace std;

int main ()
{
    int testCase;
    cin >> testCase;
    char input [410];
    stack <char> s;

    while ( testCase-- ) {
        cin>>input;
        int length = strlen (input);

        for ( int i = 0; i < length; i++ ) {

            if ( isalpha (input [i]) )
                cout << input [i];

            else if ( input [i] == ')' ) {
                cout << s.top ();
                s.pop ();
            }

            else if ( input [i] != '(' )
                s.push (input [i]);
        }

        cout << endl;
    }

    return 0;
}

SPOJ: Prime Generator -- PRIME1

Problem Description

Click here for SPOJ link: PRIME1

Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers!

Input


The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= 1000000000, n-m<=100000) separated by a space.

Output


For every test case print all prime numbers p such that m <= p <= n, one number per line, test cases separated by an empty line.

Sample Input/Output

Input:
2
1 10
3 5

Output:
2
3
5
7

3
5
Time limit: 6s
Source limit: 50000B
Memory limit: 256MB

Solution description of Prime Generator(PRIME1) 


This solution of this problem is direct implementation of Sieve of Eratosthenes method of generating prime numbers. To determine if a number is prime or composite number, we often have to experiment by dividing by primes from a list of primes. We divide by 2, 3, 5, etc. And if none of these divisions comes out even, then our number is a prime.

This is a very simple method for making a list of primes. Here are the steps to find all prime numbers less than or equal to a given integer n by Sieve of Eratosthenes method:

  1. First create an array of consecutive integers from 2 to n: (2, 3, 4, ..., n).
  2. let p be an integer variable, initialize it with 2, the first prime number.
  3. Starting from p, count up in increments of p and cross out all the multiples of p less than or
      equal  to n (2p, 3p, 4p .... kp <= n).
  4. Take the first number greater than p in the array that is uncrossed. If there is no such number
      <= n,then stop. Otherwise, assign this new number in p (which is the next prime), and start
      from step 3.

Solution of Prime Generator(PRIME1)in C

#include<stdio.h>
/**
*  SPOJ: Prime Generator -- PRIME1
*/

int prime[10000],primes;

void init_primes(){
     static int isprime[32000];
     int i,j;
     for(i=2;i<32000;i++) isprime[i]=1;
     for(i=2;i*i < 32000;i++)if(isprime[i])
     {
         for(j=2*i;j<32000;j+=i) isprime[j]=0;        
     }
     primes=0;
     for(i=2;i<32000;i++)
        if(isprime[i]) 
            prime[primes++]=i;
}

int seive[100001];

void find_seive(int lo, int hi){
   int i,j,p,n;
   for(i=0; i<=hi-lo; i++) 
       seive[i]=1;
   for(j=0;;j++){
       p=prime[j];
       if(p*p > hi) break;
       n = (lo/p)*p;
       if(n<lo) n+=p;
       if(n==p) n+=p;
       for(;n<=hi; n+=p) 
          seive[n-lo]=0;         
   }  
}

int main(){
    int cases,caseno,lower,upper,i;
    init_primes();
    scanf("%d",&cases);
    for(caseno=0;caseno<cases;caseno++){
        if(caseno) printf("\n");
        scanf("%d%d",&lower,&upper);
        if(lower<2) lower=2;
        find_seive(lower,upper);
        for(i=0; i<=upper-lower; i++)
            if(seive[i]){
               printf("%d\n",lower+i);
            }                               
    }
    return 0;
}
 

Saturday, November 9, 2013

SPOJ: Life, the Universe, and Everything -- TEST

This is first problem of SPOJ in classical problem set. It is like HELLO WORLD program for beginners who just started online programming in SPOJ. This problem is basically to get acquainted with how the Sphere Online Judge works.

Here is the problem description of  Life, the Universe, and Everything

"Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits."

Sample Input and Output

Input:
1
2
88
42
99

Output:
1
2
88

Solution of Life, the Universe, and Everything in C++

#include <iostream>
using namespace std;
int main()
{
  int i=0;
  while(1){
      cin>>i;
      if(i != 42)
          cout<<i<<endl;
      else
          break;
 }
  return 0;
}

Solution of Life, the Universe, and Everything in C

 #include <stdio.h>
int main()
{
    int i=0;
    while(1){
        scanf("%d",&i);
         if(i != 42)
            printf("%d\n", i);
         else break; 
    }
    return 0;
}

Solution of Life, the Universe, and Everything in JAVA

import java.io.*; 
public class Main
{
   public static void main(String[] args) throws IOException
   {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      int i;
      while(true){
         String s = br.readLine();
         i = Integer.parseInt(s);
         if(i != 42)
          System.out.println(i);
         else
          break;
      }

   }
}

Solution of Life, the Universe, and Everything in Brainf**k

>+[>>,----------[>,----------]+++++[<-------->-]<[>>-<]>+[
-<+++++++[<------>-]<[>>-<]>+[
-<<[>>-<]>+[<<->>->]>
]<+++++++[<++++++>-]>>
]<++++++++[<+++++>-]<
[<]<[>>[++++++++++.>]++++++++++.[[-]<]]<]

Click here If you saw this language first time.

Getting started with Sphere Online Judge (SPOJ)

SPOJ is an online programming website with more than 100,000 registered users and over 10000 problems. It is an online judge system like TopCoder and UVA, in which you can submit solution of problems 24 hours/day in over 40 languages including C, C++, JAVA, C#, Python, Perl and JavaScript. This site is ideal for both beginner as well as expert coders to practice and compete with other coders globally.

Here is the SPOJ's official website link. Apart from the English language, SPOJ is also available in Polish, Portuguese and Vietnamese languages.