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:

    <
    >
    =