Thursday, 13 August 2015

         MINIMUM DRAWS-HACKERRANK SOLUTION


Problem Statement
Jim is off to a party and is searching for a matching pair of socks. His drawer is filled with socks, each pair of a different color. In its worst case scenario, how many socks (x) should Jim remove from his drawer in the worst case scenario after which he finds a matching pair?
Input Format
The first line contains the number of test cases T.
Next T lines contains an integer N which indicates the total pairs of socks present in the drawer.
Output Format
Print the number of Draws (x) Jim makes in the worst case scenario.
Constraints
1T1000
0<N<106
Sample Input
2
1
2
Sample Output
2
3
 

SOLUTION : 

#include<iostream>
using namespace std;
int main()
{
int t,n,k;
cin>>t;
while(t--)
{
cin>>n;
k=n+1;
cout<<k<<endl;
}
return 0;
}

Monday, 23 March 2015

Lonely Integer : hacker rank

Hallo Readers!!!
i 've attached my code for the hackerrank problem the lonley integer from algorithm section
the following code was compiled under jre8 environment.


import java.util.*;
import java.io.*;

public class cli {

public static void main(String[] args) {
int[] x = new int[100];
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
   int result = 0;
   if(n%2==1)
   {
   for (int i=0;i<n;i++) {
    x[i]=sc.nextInt();
       result ^= x[i];
   }
   System.out.println("result:"+result);
   }

}

}

Thursday, 23 October 2014

JAVA IMPLEMENTATION OF PASS1 of TWO PASS Assembler

An Assembler is a system software which converts an Assembly Language(ALP) into object code.A two pass assembler converts the assembly language into computer language (object code) which then passes through the linkers and loaders and then gets converted as an application file.
In the pass 1 of two pass assembler the ALP is coverted to an intermediate file which again gets converted to an object code in the pass2.
PASS1 OF A TWO PASS ASSEMBLER :


algorithm :

begin
            if starting address is given
                        LOCCTR = starting address;
            else
                        LOCCTR = 0;
            while OPCODE != END do                 ;; or EOF
                        begin
                        read a line from the code
                        if there is a label
                                    if this label is in SYMTAB, then error
                                    else insert (label, LOCCTR) into SYMTAB
                        search OPTAB for the op code
                        if found
                                    LOCCTR += N           ;; N is the length of this instruction (4 for MIPS)
                        else if this is an assembly directive
                                    update LOCCTR as directed
                        else error
                        write line to intermediate file
                        end
            PROGRAM size =  LOCCTR - starting address;
end

JAVA CODE FOR PASS 1 OF A TWO PASS ASSEMBLER:

import java.io.*;
import java.util.*;
class pass1
{
public static void main(String args[])throws Exception
{
int loc=0;
int j=0,k;
FileReader f1=new FileReader("input.txt");
BufferedReader b1=new BufferedReader(f1);
FileReader f2=new FileReader("optab.txt");
BufferedReader b2=new BufferedReader(f2);
FileWriter f3=new FileWriter("symtab.txt");
BufferedWriter b3=new BufferedWriter(f3);
FileWriter f4=new FileWriter("intermediate.txt");
BufferedWriter  b4=new BufferedWriter(f4);
StringBuffer sb = new StringBuffer();
String s,s3,s4,tmp,sd;
String s1[]=new String[3];
String s2[]=new String[3];
while((s=b1.readLine())!=null)
{
int m=0;
StringTokenizer st=new StringTokenizer(s);
while(st.hasMoreTokens())
{
s1[m]=st.nextToken();
m++;
}
if(s1[1].equals("START"))
{
b4.write("   ");
for(int h=0;h<3;h++)
{
b4.write("  ");
b4.write("  "+s1[h]);
}
loc=Integer.parseInt(s1[2]);
b4.newLine();
}
else 
{
b4.write(loc+"  ");
if(s1[0].equals("-")!=true)
{
b3.write(" "+s1[0]);
b3.write(loc+" ");
}
while((sl=b2.readLine())!=null)
{
j=0;
StringTokenizer se=new StringTokenizer(sl);
while(se.hasMoreTokens())
{
s2[j]=se.nextToken();
j++;
}
if(s1[1].equals(s2[0])==true)
loc=loc+3;
break;
}
    if(s1[1].equals("BYTE"))
loc=loc+1;
else if(s1[1].equals("RESB"))
loc=loc+(1*Integer.parseInt(s1[2]));
else if(s1[1].equals("WORD"))
loc=loc+3;
else if(s1[1].equals("RESW"))
loc=loc+(3*Integer.parseInt(s1[2]));
for(int a=0;a<3;a++)
{
b4.write("  ");
b4.write("   "+s1[a]);
}
b4.newLine();
b3.newLine();
}
}
b4.close();
b3.close();
}
}

Monday, 2 June 2014

The Microsoft effect on me...

My start with windows xp:
                Hey guys it is a known fact that Microsoft ( மைக்ரோசாஃப்ட்-Tamil font for Microsoft ) has the greater impact in almost everyone's life  ever since the origin of windows and it didn't spare me too. The Microsoft and it's technology has been admiring me right  from the day I came to know about windows operating system during my high school.yes, that was the first time I ever used a PC with the ever green windowsxp


              But I have used this wonderful operating system during my school lab sessions for ms paint . yeah!, it all started there , the painting  experience with the windows made my good olden days with .Those good days made me to demand my parents a new PC with obvious windowsxp operating system.
           Then as the time goes by I started  studying about the other products of Microsoft  such as ms office
 through my school syllabus where I learnt a lot about the windowsxp and also the traditional browser of the world Internet explorer.
  • Switch to windows vista and then windows 7:

              After the  golden period of windowsxp Microsoft launched windows vista in 2007 and windows 7 in 2009 this is the period where i started learning how to utilise an operating system efficiently by writing  the codes, and the windows 7 was launched at the right time though i didn't had much experience with windows vista.
                  The windows 7 launch made me to get obsessed with the computers since its user interface and office 2010 were all amazing . The windows 7 which supported all the drivers by default made the operating system even better user friendly ,this feature in fact reduced  the work of the user while using the computers and even the installation of windows 7 while upgrading from windowsxp become easier . This made me to upgrade my friends computer to migrate from windowsxp to windows 7 which brought us a step closer to the latest technology.
MY FIRST HANDS ON WINDOWS 8 AND WINDOWS PHONE :
                    In 2012 I finished my high school and  enrolled myself into engineering and then i came to know about the windows phone , windows 8 operating system which was launched in later 2012
                    I attended my first ever workshop on windows8/WP8/windows azure and app development which was conducted by MSP's in Chennai  and that workshop  triggered me to work on and have my hands on the application development for windows8 and windows phone. From then on i started developing windows application with  the help of  well known sdk  visual studio .

                  And talking on  visual studio,yes, it is the best IDE I've ever worked,VS is the perfect sdk for beginners who have the desire to work on application development just like me.
                Then I started working on windows application for mobile phones and also the windows8 and contests like join the tech elite  just triggered our thoughts and application development skills.
             on coming to mobile application development the contests and challenges from the dvlup  makes me to update myself to the innovating and the developing technology from Microsoft just like updating myself to  windows8.1,visual studio 2013 .
              Day by day  my passion for Microsoft grows and i continued my works with windows development.and also i kept attending all boot camps and workshops conducted my Microsoft ,all these days i use to  help my college friends on windows development with the little knowledge of what i learnt in workshops and boot camps .
THE MICROSOFT ASSOCIATION:
              Also i was waiting keenly for my chance of associating myself with Microsoft and yes as i was waiting so as some more Microsoft enthusiasts like me were waiting for an opportunity Microsoft announced that it is launching a new program called MICROSOFT STUDENT ASSOCIATES[MSA] which is tagged as MSP India(new) .
             Though i  didn't get the chance of seeing myself as  an MSP i have hopes of seeing my self as an MSA since  i am a Microsoft follower and i love to see people around me also to be associated with the greater technologies.
And yeah,this i how Microsoft inspired my life technically ,it made me to update myself to the latest tech stuff.
MY RESPONSIBILITIES AS MSA:
  •  Taking all the new tech stuff from Microsoft to the people so that every one knows the tech height of this world
  •  conducting workshops,boot camps in my college campus for sharing my knowledge with others and also guide the budding developers.
  •   making sure that my friends and other students to whomever approaches me gets the clear knowledge on what they are doing for the windows development.
  •  I hardly believe in myself and since i am having a good conduct in my college and also among my circle i can promote the Microsoft products well since Microsoft products pave the wave for people to get associated with the greater technology.