Wednesday, April 27, 2011

Script facing Class Not Found Exception while running from RQM

If your script has dependency on External (third party jar or your own Created Jars) The place to keep them before running them from RQM is okay hold on 
before that 
RQM As a product actually gives you two options 
1.Simple Option 
2.very Simple option :)

Now let me stop beating around the Bush and get to the point 
 
Say your Script name is myname.java and your Script uses a method printMyName() which is part of External1.Jar,and printyourName which is part of External2.jar . One way to execute script is to put every thing(External1 and External2.jar) in the machine which has RFT installed at location 
C:\Documents and Settings\All Users\Application Data\IBM\RFT\customization








And test will go fine
as this is the default location we look for while executing the test 

The next option is where you want to keep all teh dependency at a shared location 
That you can do by giving a switch at RQM UI under Execution Argument option 
like -projectPath c:\ExernalJar_Location 
where External jar location is the place where i have put the 
External1.jar and External2.jar

Shoot Questions if you did not find it working:)



Sunday, April 17, 2011

4. Transform the Expression




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.

Example

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

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

the algorithm is pretty simple Every operation has a binding weight, with + and - being the lowest. There are two rules:
  • print out numbers immediately
  • never put a lighter item on a heavier item
  • left parentheses go on the stack
  • right parentheses pop off the stack until you hit a left parentheses, and then remove the left parentheses

Code based on that:
A
PS: i have solved it for any given expression as per sun you need to take input and iterate it as per the user want it to and then get the output 


import java.util.Stack;


public class reversePolishExp
{

public static String Infix2(String input)
{
char[] in = input.toCharArray();
Stack<Character> stack = new Stack<Character>();
StringBuilder out = new StringBuilder();
for (int i = 0; i < in.length; i++)
switch (in[i]) {
case '+':
case '-':
while (!stack.empty() && (stack.peek() == '*' || stack.peek() == '/')) {
out.append(' ');
out.append(stack.pop());
}
out.append(' ');
stack.push(in[i]);
break;
case '*':
case '/':
out.append(' ');
stack.push(in[i]);
break;
case '(':
stack.push(in[i]);
break;
case ')':
while (!stack.empty() && stack.peek() != '(') {
out.append(' ');
out.append(stack.pop());
}
stack.pop();
break;
default:
out.append(in[i]);
break;
}
while (!stack.isEmpty())
out.append(' ').append(stack.pop());

return out.toString();
}

public static void main (String args[])
{
// reversePolishExp exp = new reversePolishExp();
String man=reversePolishExp.Infix2("(a+b)*(c+d)");
System.out.print(man);
}
}








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.

Example

Input:
1
2
88
42
99

Output:
1
2
88
My approach to this problem 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
    public static void main (String args[])
    {
     int i=0;
  int []anArray;
  String line=null;
  anArray = new int[100];
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     while (true) 
     {
      try {
       line=br.readLine();
   anArray[i] = Integer.parseInt(line);
   } catch (IOException e) {
    e.printStackTrace();
   }
      if((anArray[i])==42)
      {
       break;
      } 
      i++;
     }  
     for (int pos=0;pos<i;pos++)
     {
      System.out.println(anArray[pos]);
     }    
    }
}

Counting Cells in a Sector


Problem Statement - Counting Cells in a Sector

Consider a two-dimensional grid of cells, each of which may be empty or filled. The filled cells  that are connected form a sector. Two cells are said to be connected if they are adjacent to each other horizontally, vertically or diagonally. There may be several sectors on the grid. Your job is to find the largest sector (in terms of number of cells) on the grid. 

The following figure illustrates a grid with 3 sectors (the largest contains 5 cells).



Problem
Write a program that determines the size of the largest sector for a given grid. 

Input
The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs. The grid is given as a set of string, each composed of 0s and 1s. The 1 indicates that the cell is filled and 0 indicates an empty cell. The strings should be converted into the grid format. The largest grid that should be considered is a 25x25 grid.

Output
For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line. The output is the size of the largest sector found on the grid. 

Sample Input
2

11000
01100
00101
10001
01011 

1011
1010

Sample Output
5
3
Solution to this problem 

package test;

import java.util.Scanner;

public class CountMax {

/**
* author manish
* @param args
*/
private static int grid[][];
// static int[][] grid=new int[25][25];
private static int rows;
private static int cols;
private static final int MARKED = -1;
public static int count()
{
int maxCount=0;
int count=0;
for(int i=0;i<rows;i++)//  i
{
for(int j=0;j<cols;j++) // j
{
count=countMatrix(i,j);
//this if block to make sure that maximum node connection is returned
if(count>maxCount)
{
maxCount=count;
unmarkGrid();
}
}//for j
} //for i
return maxCount;
}
public static int countMatrix(int row,int col)
{
//if row is going out of bound
if(row<0 || row>=rows)
return 0;
//if column is going out of bound
if(col<0 || col>=cols)
return 0;
// no point looking for relations if value is not 1
if(grid[row][col]!=1)
return 0;
// if it is none of the case above then we need to check and figure out
grid[row][col]=MARKED;
int sizeofObj=1 + countMatrix(row - 1, col - 1)
+ countMatrix(row - 1, col) + countMatrix(row - 1, col + 1)
+ countMatrix(row, col - 1) + countMatrix(row, col + 1)
+ countMatrix(row + 1, col - 1) + countMatrix(row + 1, col)
+ countMatrix(row + 1, col + 1);
return sizeofObj;
}
//make it unmarked so that next time a fresh iteratio will happen and -1 will be removed from array
public static void unmarkGrid()
{
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++)
if (grid[i][j] == MARKED)
grid[i][j] = 1;

}
public static void main(String[] args) {
// TODO Auto-generated method stub
// INPUT PART OF IT 
System.out.print("Enter the no of rows and columns\n");
Scanner scannerObject = new Scanner(System.in); 
rows=scannerObject.nextInt();
cols=scannerObject.nextInt();
grid = new int[rows][cols];
for(int i=0;i<rows;i++)
for(int j=0;j<cols;j++)
{
try {
// System.out.print("Enter the Digits in terms of 1 and 0\n");
grid[i][j]=scannerObject.nextInt();
// System.out.print(grid[i][j]);
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
for(int i=0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
System.out.print(grid[i][j]+"\t");
}
System.out.print("\n");
}
//  CALCULATION PART OF IT 
int val=count();
   System.out.print(val);
}
}