C

Self reproducing Program:

     char*f="char*f=%c%s%c;main()
     {printf(f,34,f,34,10);}%c";
     main(){printf(f,34,f,34,10);}

XML & XSLT

This Style sheet is to add a DOCTYPE tag to a XML Document using Identity Transformation:

xyz.xsl is the name of the Style Sheet. 

<?xml version="1.0" ?>

<xsl:stylesheet version="1.0"

   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- identity template -->

<xsl:template match="/">

<![CDATA[<!DOCTYPE >]]>

<xsl:apply-templates/>

</xsl:template>

<xsl:template match="@*|node()">

    <xsl:copy>

        <xsl:apply-templates select="@*|node()"/>

    </xsl:copy>

</xsl:template>

</xsl:stylesheet>

xyz.xml is transformed using the above Style Sheet:

<?xml version="1.0"?>

<?xml-stylesheet type="text/xsl" href="xyz.xsl"?>

<x xmlns:n1="http://www.w3.org"   xmlns:n2="http://www.w3.org" >

<xyz>

<hjk>

abc

</hjk>

<lkj>

567

</lkj>

</xyz>

</x>

Transformed XML document:

<?xml version="1.0" encoding="utf-8"?>

&lt;!DOCTYPE &gt;

<?xml-stylesheet type="text/xsl" href="xyz1.xsl"?><x xmlns:n1="http://www.w3.org" xmlns:n2="http://www.w3.org">

<xyz>

<hjk>

abc

</hjk>

<lkj>

567

</lkj>

</xyz>

</x> 

SQL

SQL script that will remove extra rows from the table below based on non-unique id and datetime of creation. Leave the last row for the day, based on datetime for each id without using any SQL aggregation functions.

> select Id, creation_time from test;

Id creation_time

1 03/05/2007 12:02:09

1 03/05/2007 11:45:00

1 03/05/2007 13:05:54

1 03/05/2007 15:59:59

2 03/05/2007 10:55:01

2 03/05/2007 11:15:02

2 03/05/2007 16:23:34

The content of table after script execution should be:

> select Id, creation_time from test;

1 03/05/2007 15:59:59

2 03/05/2007 16:23:34

DELETE FROM Test WHERE NOT EXISTS
(SELECT T1.Id, T1.Creation_time FROM(

SELECT DISTINCT T.Id, (SELECT TOP 1 Creation_time From Test WHERE Id = T.Id ORDER BY Creation_time DESC) AS Creation_time
FROM Test AS T) AS T1
WHERE T1.Id = Test.Id AND T1.Creation_time = Test.Creation_time)
;

JAVA

/*
 * GenTelString.java
 * Given a ten digit phone number, as a string(format is your discretion, 1234567890, 123-456-7890, (123)456-7890, etc..),
 * generate all the letter combinations that are possible based on the telephone keypad's number/letter relationship
 * (i.e. 1 is related to no letters, 2 is related to 'a' 'b' 'c', 3 is related to 'd' 'e' 'f', etc).
 */
import java.io.*;
import javax.swing.*;
public class GenTelString {
   
    /** Creates a new instance of GenTelString */
   
   static char a[][] = {
        {},
        {},
        {'a','b','c'},
        {'d','e','f'},
        {'g','h','i'},
        {'j','k','l'},
        {'m','n','o'},
        {'p','q','r','s'},
        {'t','u','v'},
        {'w','x','y','z'}
    };
           int[] first = new int[10];
           int[] second = new int[10];
           int[] pos = new int[10];
           
           boolean more = true;
            long MAX = 9999999999L;
    public GenTelString(String s) {
   
        more = true;
               try
            {
                long ll = Long.parseLong(s);
                if(ll > MAX || s.length() != 10 || ll < 0)
                {
                   System.out.println(s+"-> errorneous Telphone#");
                   //System.out.println("LL"+ll);
                }
                else
                {
                    System.out.println(s+"-->");
                    for(int j=0; j<10; j++)
                    {
                        first[j] = Integer.parseInt(s.substring(j,j+1));
                        second[j] = a[first[j]].length;
                        pos[j] = 0;
           // System.out.println( first[j] );
           // System.out.println(second[j]);
            //System.out.println(pos[j]);
                    }
           
                        while(more) 
                        {
                            System.out.println(getString());
                        }
                    }
                }
            catch(NumberFormatException e)
            {
              System.out.println(s+"---> errorneous Telphone#"); 
             
            }
        }
   
    public static void main (String argv[])
    {
            String[] s = {
                "08050708031","3009000007", "1006000000"
            };
            for(int i=0;i<s.length;i++)
            {GenTelString g = new GenTelString(s[i]);}

    }
   
    public  String getString()
    {
        StringBuffer alpha = new StringBuffer();
           
        for(int j =0; j<10; j++)
            if(a[first[j]].length !=0)alpha.append(a[first[j]][pos[j]]);
       
        for(int j = 9; j > -1; j--)
        {
           //System.out.println(j);
            if(second[j] ==0 || pos[j] == second[j] - 1) {
                more = false;
             //   System.out.println("j->" + j);
            }
            else
            {
                more = true;pos[j]++;
            for(int k = j+1; k<10;k++)pos[k]=0;
               
               // String input = JOptionPane.showInputDialog("enter");
                break;
            }
        }

        return alpha.toString();
    }
    }

PSEUDO

Given 3 cell phone towers and 1 cell phone, calculate which tower is closest to the cell phone at any point in time for a mobile cell phone.

// Problem 3: This is written in pseudo code. This an algorith for calculating nearest Tower (it is the variable "nearest_tower") for a moving cellular Phone

/*

//assume:

//send_msg(tower_id, cell_id, cell_time) : sends a message to Tower tower_id; infact it is a fixed a channel the tower's communication channel

//         we shall assume it is integer - 0, 1 or 2

//         cell_id: for this may fixed equipment number say 21345;

//         cell_time is the time accordind to the cell when the message is

sent

//Timer_tick is an event handler, whenever coresponding set time interval for Timer elapses //msg_receipt is an even handler for any message received from any channel */

 

int nearest_tower=0, tower=0, cell_id=21345, interval = 10000, elapsed = 0, last_tower=4, last_interval=10000; Time last_time, now_time, near_time; Timer msgTimer; Message msg;

main()

{

      msgTimer.interval=100; // unit is milliseconds

      msg.init(); // initializes the msg object used for both sending and receiving messages

      msgTimer.enable = true;// This starts msgTimer ticking

      last_time = near_time = Time.currentTime(); } msgTimer_tick(sender, eventArgs) {

      for(tower=0;tower<3;tower++)

            {msg.send_msg(tower,cell_id, Time.currentTime())};

      if((last_time >= (near_time + 5000))&&(interval <> last_interval))

      {

            nearst_tower = last_tower;

            interval = last_interval;

            near_time = last_time;

            Display( "Tower ="+ nearest_tower+ "Time = "+ near_time + "Distance = " + interval);

      }

      msgTimer.interval = 5000;// next Timer Tick shall take place after 5 seconds and messages shall be sent to all towers

      msgTimer.enable = true;

           

}

     

msg_receipt(sender, eventArgs)

{

// event Arguments received are CellId, TowerId, CellMsgTime - it is time argument of send_msg method

      if(eventArgs.cellId == cell_id)

      {    

            now_time = Time.currentTime();     

            elapsed = now_time - eventArgs.cellMsgTime;

            if(interval >= elapsed)

            {    

                  nearest_tower = eventArgs.towerId;

                  interval = elapsed;

                  near_time = now_time;

                  Display( "Tower ="+ nearest_tower+ "Time = "+ near_time + "Distance = " + interval);

            }

            else

            {

                  if(now_time >= (near_time + 5000))

                  {

                        nearest_tower = eventArgs.towerId;

                        interval = elapsed;

                        near_time = now_time;

                        Display( "Tower ="+ nearest_tower+ "Time = "+ near_time + "Distance = " + interval);

                  }

            }

            last_time = now_time;

            last_tower = eventArgs.towerId;

            last_interval = elapsed;

 

      }

}