Showing posts with label java. Show all posts
Showing posts with label java. Show all posts
LinkedList

LinkedList

->Linked List is a linear collection of  objects (called nodes) connected by the reference links.

->Program accesses a linked list via a reference to the first node in list.

->Program accesses a subsequent nodes via the reference link stored in the previous node.

->Reference in the last node of a list is set to null.

Source : from my lecturer slide, sir Jiwa Noris
 

Arrays.fill() Method

Arrays.fill() Method

Java.util.Arrays.fill(int[], int) Method

Arrays.fill() ini digunakan apabila kita ingin mengubah nilai didalam array yang kita buat dengan satu nilai. 
Di bawah ini adalah declaration untuk Arrays.fill()

public static void fill(int[] a, int val)
 
Dibawah ini adalah contoh program yang saya sediakan dengan menggunakan Arrays.fill().
Sumber : http://www.tutorialspoint.com/java/util/arrays_fill_int.htm
494 - Kindergarten Counting Game

494 - Kindergarten Counting Game

Kindergarten Counting Game 

Everybody sit down in a circle. Ok. Listen to me carefully.
``Woooooo, you scwewy wabbit!''
Now, could someone tell me how many words I just said?

Input and Output

Input to your program will consist of a series of lines, each line containing multiple words (at least one). A ``word'' is defined as a consecutive sequence of letters (upper and/or lower case).
Your program should output a word count for each line of input. Each word count should be printed on a separate line.

Sample Input

Meep Meep!
I tot I taw a putty tat.
I did! I did! I did taw a putty tat.
Shsssssssssh ... I am hunting wabbits. Heh Heh Heh Heh ...

Sample Output

2
7
10
9
 
 
10038 - Jolly Jumpers

10038 - Jolly Jumpers

Problem E: Jolly Jumpers

A sequence of n > 0 integers is called a jolly jumper if the absolute values of the difference between successive elements take on all the values 1 through n-1. For instance,
1 4 2 3
is a jolly jumper, because the absolutes differences are 3, 2, and 1 respectively. The definition implies that any sequence of a single integer is a jolly jumper. You are to write a program to determine whether or not each of a number of sequences is a jolly jumper.

Input

Each line of input contains an integer n <= 3000 followed by n integers representing the sequence.

Output

For each line of input, generate a line of output saying "Jolly" or "Not jolly".

Sample Input

4 1 4 2 3
5 1 4 2 -1 6

Sample Output

Jolly
Not jolly
 
10107 - What is the Median?

10107 - What is the Median?

What is the Median? 

The Problem

Median plays an important role in the world of statistics. By definition, it is a value which divides an array into two equal parts. In this problem you are to determine the current median of some long integers. Suppose, we have five numbers {1,3,6,2,7}. In this case, 3 is the median as it has exactly two numbers on its each side. {1,2} and {6,7}.
If there are even number of values like {1,3,6,2,7,8}, only one value cannot split this array into equal two parts, so we consider the average of the middle values {3,6}. Thus, the median will be (3+6)/2 = 4.5. In this problem, you have to print only the integer part, not the fractional. As a result, according to this problem, the median will be 4!

Input 

The input file consists of series of integers X ( 0 <= X < 2^31 ) and total number of integers N is less than 10000. The numbers may have leading or trailing spaces.

Output 

For each input print the current value of the median.

Sample Input 

1
3
4
60
70
50
2

Sample Output 

1
2
3
3
4
27
4
 
Coding

Mini Project Java : UiTM Fee Management System

Program ini untuk personal advisor student printkan slip yang patut dibayar oleh student mengikut pointer. Jika atas 3.5 ada diskaun yang akan diberi. Di samping itu program ini juga membolehkan personal advisor untuk search, delete, add dan edit student data. Di sebabkan semester ini kami perlu implement elemen data structure dalam mini projek, jadi saya menggunakan arraylist, linkedlist, stack dan queue dalam mini projek kami ini.
Tapi saya paling suka guna arraylist disebabkan senang dan mudah untuk digunakan untuk searching, deleting dan editing, kerana kita hanya perlu hantarkan index object tersebut ke arraylist untuk kita delete, search or edit.

Gambar dibawah adalah interface program programnya dan coding yg related to ArrayList, LinkedList, Stack, Queue:

ArrayList
LinkedList
Queue
Stack








Output that can be printed. :)


2013 ACM-ICPC Malaysia National Programming Contest (QUESTION G-RICE SACK)

2013 ACM-ICPC Malaysia National Programming Contest (QUESTION G-RICE SACK)

G
RICE SACK

Problem Description

Several sacks of rice need to be transported to five Orphanage Houses. The heaviest sack will go
to Orphanage House Al-Ameen because it has the most number of orphanges. The lightest will
be sent to Orphanage House Mutiara due to the small number of children staying there.
Given a row of rice sacks, decide which sack goes to Al-Ameen?

Input

The first line is an integer that represent the number of case. The following lines have 5 integers
indicating the weights of 5 rice sacks, each separated by a blank. No sack will have a weight of
more than 100 unit.

Output

For each test case, the output contains a line in the format Case #x: followed by a sequence of
integers, where x is the case number (starting from 1) and an integer that indicates the weight of
a rice sack that will go to Al-Ameen.

Sample Input Output

Sample Input
4
1 6 10 5 20
5 10 25 3 1
30 15 5 1 8
7 4 20 50 5

Sample Output
Case #1: 20
Case #2: 25
Case #3: 30
Case #4: 50

Cara nak selesaikan Problem G ni adalah dengan cari nilai maksimum dari 5 nilai yang diberi.

Solution :
2013 ACM-ICPC Malaysia National Programming Contest (QUESTION F-SAHUR & IMSA’)

2013 ACM-ICPC Malaysia National Programming Contest (QUESTION F-SAHUR & IMSA’)

SAHUR & IMSA’

Problem Description

Midhat is a Network Security Engineer, based in Sarajevo. He is assigned to do some important
consultation projects around the globe in July and August 2013. It happened that Ramadhan (the
fasting month for Muslim) falls during these months for the year 2013. Midhat has to travel to
several cities – Istanbul, Kuala Lumpur, Tokyo, Melbourne, Sao Paolo and Chicago. Even
though it is permissible for Muslims not to fast when travelling, he prefers to continue fasting in
Ramadhan. Midhat has no problem on this matter except he needs to make himself awake for
sahur (early breakfast before dawn) on his own, which he is used to be waked by his mother at
home.

Midhat wants to have his sahur 45 minutes before imsa’ (end time for taking sahur). He decided
to set his travelling alarm clock 45 minutes before imsa’, so that he can take his sahur in time,
make his Fajr prayer and ready to work early. Since he’s travelling to different parts of the
world, the imsa’ time differs from one city to another. Midhat wants to set his travelling clock to
wake him up on time for all the cities he visits. Help Midhat by writing a program that will take
one time stamp, in 24-hour notation, and print out a new time stamp, 45 minutes earlier, also in
24-hour notation.

Note: In 24-hour time notation, it starts with 0:00 (midnight) and ends with 23:59 (one minute
before midnight). In the input and output we'll ignore the leading zeros and colon for simplicity.
So 0:00 will be written as 0 0.

Input

The first line will contain number of test cases, T. After that T lines will follow, where each line
will contain exactly two integers H and M (0 ≤ H ≤ 23, 0 ≤ M ≤ 59) separated by a single space,
the input time in 24-hour notation. H denotes hours and M minutes .

Output

For each test case, the output contains a line in the format Case #x: followed by a sequence of
integers, where x is the case number (starting from 1) and output one line with exactly two
integers, the time 45 minutes before input time .
Sample Input
4
5 0
10 10
0 30
23 47
Sample Output
Case #1: 4 15
Case #2: 9 25
Case #3: 23 45
Case #4: 23 2

Untuk problem F ni hanya perlu masukkan jam dan minit. Kemudian minit tersebut kita tolakkan dengan 45, selepas dapat jawapannya kita bandingkan adakah minit tersebut kurang daripada 0. Jika kurang kita perlu tambahkan kepada 60, dan nilai jam kita tolak kepada 1. Jika nilai jam pula kurang daripada 0, kita perlu tambahkan 24.

Solution :



10055 - Hashmat the Brave Warrior

10055 - Hashmat the Brave Warrior

Problem Link

Cara nak selesaikan problem ni cuma perlu tolak je nilainya. Trick dia kat sini cuma mungkin nilai yang dimasukkan lebih besar jadi kalau integer memang tak boleh la. Dalam solution saya gunakan BigInteger.

Solution :
import java.util.*;
import java.math.*;
public class uva10055 {
public static void main(String [] args) throws Exception {
Scanner scn = new Scanner(System.in);
while(scn.hasNextBigInteger()) {
BigInteger a = scn.nextBigInteger();
BigInteger b = scn.nextBigInteger();
int c = a.compareTo(b);
if(c==1 || c==0)
System.out.println(a.subtract(b));
else
System.out.println(b.subtract(a));
}
}
}