Monday, 8 August 2016

Rename a Branch in GIT

Commands to rename a Branch in GIT after doing commits using terminal in Tortoise GIT

> git branch -m old_branch new_branch

> git push origin :old_branch

> git push --set-upstream origin new_branch

Wednesday, 23 September 2015

Check the Existence of a File Using Perl

A simple Perl script to check the existence of the file in the destination place.

Perl Code: 
#check the existence of the file if yes say file exists else terminate the program
$filename = 'G:\\GPB\\protoc-3.0.0-alpha-3-win32\\protoc.exe';
 if (-e $filename)
 {
    print "File Exists!";
 }
 else
 {
    die ("$!\n");   
 }



OutPut:

 > perl CheckExsistenceOfFile.pl
 File Exists!

Tuesday, 8 September 2015

Chef and operators

Following is the program form  https://www.codechef.com/problems/CHOPRT

Chef has just started Programming, he is in first year of Engineering. Chef is reading about Relational Operators.

Relational Operators are operators which check relatioship between two values. Given two numerical values A and B you need to help chef in finding the relationship between them that is, 

  • First one is greater than second or,
  • First one is less than second or,
  • First and second one are equal.


  • Input

    First line contains an integer T, which denotes the number of testcases. Each of the T lines contain two integers A and B.

    Output

    For each line of input produce one line of output. This line contains any one of the relational operators

    '≺' , '≻' , '='.

    Program:

    #include <iostream>
    using namespace std;
    int ProcessNumbers (int InCount);

    int main() {
        // testcase control parameter
        int TestCaseNo;
        int FirstNo, SecondNo;
        cin>>TestCaseNo;
        ProcessNumbers(TestCaseNo);
    return 0;
    }

    int ProcessNumbers(int InCount)
    {
        int FirstNo, SecondNo;
        char output_symbol[3];
        for (int i = 0; i < InCount ; i++ )
        {
            cin>>FirstNo>>SecondNo;
            
            if (FirstNo < SecondNo)
                output_symbol[i] = {'<'};
            else if (FirstNo > SecondNo)
                output_symbol[1] = {'>'} ;
            else 
                output_symbol[i] = {'='} ;
                
        }
        
        for (int j = 0; j < InCount ; j++ )
        {
            cout << "\n" <<output_symbol [j];
        }
       }

    InPut:
    3
    2 3
    4 6
    4 4 
    OutPut:

    <
    >
    =

    Saturday, 3 January 2015

    FIZZ BUZZ

    Write a program that prints the numbers in the given range. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”. Print a new line after each string or number.

    Input Format First line will be the number of testcases, T. Next line will have T integers, denoted by N.

    Output Format For each testcase, print the number from 1 to N. But follow the rules given in the problem statement.

    Constraints

    1 <= T <= 10

    N is an integer.

    Input File

    Expected Output

    You can also look at the solution that passes all test cases for this problem.

    View C Solution

    View Java Solution
    Sample Input (Plaintext Link)

    2
    3 15

    Sample Output (Plaintext Link)

    1
    2
    Fizz
    1
    2
    Fizz
    4
    Buzz
    Fizz
    7
    8
    Fizz
    Buzz
    11
    Fizz
    13
    14
    FizzBuzz



    /* Program */

    #include <iostream>
    using namespace std;

    int main()
    {
        int n;
        int a[10];
        // as per constraints given
        cin>>n;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
       
        for(int j=0;j<n;j++)
        {
            for(int c=1;c<=a[j];c++)
            {
                if(c%3==0 && c%5==0)
                 cout<<"FizzBuzz"<<endl;
                else if(c%3==0)
                 cout<<"Fizz"<<endl;
                else if(c%5==0)
                 cout<<"Buzz"<<endl;
                else
                 cout<<c<<endl;
            }
        }

    return 0;
    }

    Sunday, 19 October 2014

    Nekops-Nu Sequences

    A Nekops-Nu sequence is computed from any sequence of integers by following these rules starting from the first number (left-most number) in the sequence:
    Count the number of successive repetitions of the same number.
    Output the count and then the number.
    Repeat steps 1-3 for the next digit in the sequence
    For example, given the sequence “1 2 1 1”, the Nekops-Nu sequence can be computed as:
    There is 1 instance of the number 1.
    There is 1 instance of the number 2.
    There are 2 instances of the number 1.
    The new Nekops-Nu sequence is “1 1 1 2 2 1”
    The same set of rules can be applied to the resulting sequence to generate more patterns. See the sample
    output for further continuations to the example provided.
    Task
    Write a program that computes the next K instances of the Nekops-Nu sequence for a given sequence of
    numbers.
    Input
    The input will contain:
    0 <= Number of iterative sequences to compute, K <= 10
    Initial sequence of 1 <= N <= 250
    The numbers in the sequence can have any valid 32-bit integer value.
    Outpu The output contains one Nekops-Nu sequence per line starting with the initial input sequence and followed by the K sequences computed. The numbers in each sequence are separated by a single space character. To make the output look more interesting, add periods to pad all the sequences (before and after) such that they are centered align with respect to the longest sequence computed. Given the example above, the two sequences were “1 2 1 1” (length 7 characters) and “1 1 1 2 2 1” (length 11 characters). Therefore the output
    should show:
    ..1 2 1 1..
    1 1 1 2 2 1
    If a specific row and the longest row do not line up (because of odd and even numbers of characters), then
    add an extra dot before the sequence as shown in input/output #2, or refer to the following example:
    .....9999 9999....
    ......2 9999......
    ....1 2 1 9999....
    1 1 1 2 1 1 1 9999
    (i.e. if the number of characters is even in a specific row, then there should be an extra dot before the
    sequence)
    Finally, on the last line, output the number of elements found in the last sequence.
    Note: There is a newline character at the end of the last line of the output.
    Sample Input 1
    3 1 2 1 1
    Sample Output 1
    ....1 2 1 1....
    ..1 1 1 2 2 1..
    ..3 1 2 2 1 1..
    1 3 1 1 2 2 2 1
    8
    Sample Input 2
    1 1 1 1 1 1 1 1 1 1 1
    Sample Output 2
    1 1 1 1 1 1 1 1 1 1
    ........10 1.......
    2

    /* Coding */


    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    using namespace std;


    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */
        // input stream of number
        long int number;
        int limit,new_number,i
        int first_number, next_number;
        int count=0;
        cin>>number;
        //predicting how long the number is...
        if( number > 10 && number < 100 )
            {
            limit=number/10;
            new_number=number%10;
            }
        if( number > 100 && number < 1000 )
            {
            limit=number/100;
            new_number=number%100;
            }
        if( number > 1000 && number < 10000 )
            {
            limit=number/1000;
            new_number=number%1000;
            }
         if( number > 10000 && number < 100000 )
            {
            limit=number/10000;
            new_number=number%10000;
            }
         if( number > 100000 && number < 1000000 )
            {
            limit=number/100000;
            new_number=number%100000;
            }
        // limit. control. loop
       
        for(i=0;i<3;i++)
            {
            if( i=0 )
                {
                cout<<"....";
            }
            if( i=1 )
                {
                cout<<"...";
                }
            if( i=2 )
                {
                cout<<"..";
            }
           
            if( new_number > 0 && new_number < 10 )
                {
                first_number=new_number;
                cout<<"1"<<first_number;
                count = count + 2;
            }
            if(new_number > 10 && new_number < 100 )
                {
                first_number=new_number/10;
                //new_number=new_number%10;
                next_number=new_number%10;
                if ( first_number == next_number )
                    {
                    cout<<"2"<<first_number;
                    count = count + 3;
                }
                else
                    {
                    cout<<"1"<<first_number;
                    cout<<"1"<<next_number;
                    count = count + 4;
                }
            }
            if(new_number > 100 && new_number < 1000 )
                {
                first_number=new_number/100;
                new_number=new_number%100;
                next_number=new_number/10;
                if ( first_number == next_number )
                    {
                    cout<<"2"<<first_number;
                    count = count + 3;
                }
                else
                    {
                    cout<<"1"<<first_number;
                    cout<<"1"<<next_number;
                    count = count + 4;
                }
            }
            if(new_number > 1000 && new_number < 10000 )
                {
                first_number=new_number/1000;
                new_number=new_number%1000;
                next_number=new_number/100;
                if ( first_number == next_number )
                    {
                    cout<<"2"<<first_number;
                    count = count + 3;
                }
                else
                    {
                    cout<<"1"<<first_number;
                    cout<<"1"<<next_number;
                    count = count + 4;
                }
            } 
            if(new_number > 10000 && new_number < 100000 )
                {
                first_number=new_number/10000;
                new_number=new_number%10000;
                next_number=new_number/1000;
                if ( first_number == next_number )
                    {
                    cout<<"2"<<first_number;
                    count = count + 3;
                }
                else
                    {
                    cout<<"1"<<first_number;
                    cout<<"1"<<next_number;
                    count = count + 4;
                }
            }
            if(new_number > 100000 && new_number < 1000000 )
                {
                first_number=new_number/100000;
                new_number=new_number%100000;
                next_number=new_number/10000;
                if ( first_number == next_number )
                    {
                    cout<<"2"<<first_number;
                    count = count + 3;
                }
                else
                    {
                    cout<<"1"<<first_number;
                    cout<<"1"<<next_number;
                    count = count + 4;
                }
            }
            if(i=0)
                {
                cout<<"...."<<endl;
            }
            if(i=1)
                {
                cout<<"..."<<endl;
            }
            if(i=2)
                {
                cout<<".."<<endl;
            }
           
        }
        cout<<count;
          return 0;
    }

    Wednesday, 27 August 2014

    Zero Count :) :)

    William played a number game with his sister as to count the number of Hole in each of the digit. His sister who is poor in mathematics. We have to help her to count the number of Zeros.

    Sample Test Case:
    989
    4

    100
    2

    1456
    1

    /* Code to Crack it is */

    # include <iostream.h>
    # include <conio.h>
    int main()
    {
     clrscr();
     long int n,sum;
     cin>>n;
     sum=0;
     while(n!=0)
     {
      int r;
      r=n%10;
      //cout<<r;
      if(r==6||r==9||r==0)
           sum=sum+1;
      if(r==8)
           sum=sum+2;
      else
           sum=sum+0;

      r=0;
      n=n/10;
     }
     cout<<sum;
    return 00;

    ZOHO Interview Process :) :)

    Zoho Interview Process
    **********************
    Zoho which is a multi production company reli on its employees.
    Its Interview process goes on long and long tedious process..
    but nothing to worry ..
    it will be your turing point in life either by giving success or experience
    The interview process may occupy two to three days based upon their need...
    **************************************
    Interview process - My Experience
    **************************************
    Round 1: 02:15 min extra time will be given 15 min
    40 questions full program
    first 10 questions will carry 1/2 mark each....
     - just finding the out put of the program
    second 5 questions carry 1 mark each
     - simple error predicting and modification of program
    third 5 questions carry 1 mark each
     - simple output predicting program
    fourth 10 questions carry 1 mark each
     - simple input predicting program
    fifth 5 questions carry 1 mark each
     - find out similar programs producing similar outputs
    sixth 5 questions carry 1 mark each
     - find the order of function call from the main section to get the output.
    Round 2:
    Phase I: /* depending upon the number of candidates the number of phases may increase */
    Will give you a question paper consists of 3-4 problems
    solidly it took 4 hours
    After completeion questions will be given to you which may contain other set of questions
    i was given the following problems.

    1. To calculate the summatiom of odd numbers between the given limit.
    Sample test case:
    22 55
    23 27 29 31 37 41 43 47 51 53
    382

    2. To odrer the number in Desending order in the manner of their factors.
    Sample Test case:
    3 13 15 21 5 80
    80 21 3 13 15 5

    3. To print the number in letters
    Sample test case:
    121
    one hundred and twenty one
    33
    thirty three
    /* END of phase1 in round 2*/
    /* I got selected and pass on to phase 2 */
    Phase 2: this round just simply follows the phase I principle and question paper follows.
    Same here solidly it took 4 hours.
    in this round you will not be given all the question at time.
    instead you will be given a question by question...
    time of completion will also be noted.
    1. to print the m x n matrix in the following format.

    x x x x x x x
    x o o o o o x
    x o x x x o x
    x o x x x o x
    x o o o o o x
    x x x x x x x

    2. form universsal set of numbers, have to find the subset of number which satisfy the stipulated conditions
    Sample test case
    { 1,3,4,5,6,7,9}
    3
    {1,5} {3,6} {4,5} {1,5,6} {4,5,6} {1,5,9} {4,5,9}

    3. to predict the lines whether it is parallal, intersecting or overlapping lines
     with four co ordinators given.

    i quit from this stage... :) :)

    /*****************/
    Make everything simple yaar... :)
    dont be complex ...
    simple will always be wanted ... :) :)
    /************/
    All the best do well


    Thank you
    For reading the post