Tutorial Test Case

Tutorial untuk membuat test case kita sendiri. Mengenai tips-tips untuk membuat test case yang berkesan, boleh search di google. Definisi dari Wikipedia mengenai test case :
test case, in software engineering, is a set of conditions or variables under which a tester will determine whether an applicationsoftware systemor one of its features is working as it was originally established for it to do.
Jadi secara ringkasnya ianya hanya untuk menguji program kita sama ada ianya berfungsi seperti yang telah dirancang. Langkah-langkah untuk membuat test case adalah :

1) Buat program anda sendiri dan namakannya dengan nama yang sesuai. Sebagai contoh saya buat soalan di uva. Jadi namanya saya beri uva12646.java. Saya menggunakan java language.


2)Kemudian file yang akan inputkan ke program. Namakannya uva12646.in. ".in" tu saya buat merujuk kepada input.


3)Buat lagi satu file baru uva12646.ans. ".ans" itu merujuk kepada output sebenar yang sepatutnya akan dikeluarkan oleh program kita.


 4)Buat lagi satu file baru uva12646.out. ".out" itu merujuk kepada output yang akan dikeluarkan oleh program kita. Buat masa ini biarkan ianya kosong.



5)Kemudian buka terminal(linux)/command prompt(windows) anda. Dan pergi ke tempat anda save file uva12646.java, uva12646.in, uva12646.ans dan uva12646.out. Pastikan anda savekan file-file tersebut di tempat yang sama.


6)Kemudian compile program anda dengan command "javac uva12646.java".


7)Selepas itu inputkan file anda dengan uva12646.in dan outputkannya di file uva12646.out. "java uva12646 < uva12646.in > uva12646.out"

 

8)Kemudian anda boleh lihat di file uva12646.out untuk melihat output yang dikeluarkan oleh program anda. 


9)Kemudian kita bandingkan file uva12646.ans dan uva12646.out, adakah kedua-dua file itu sama nilainya. Jika sama ianya tidak akan keluarkan apa-apa. Untuk linux kita gunakan "diff", untuk windows kita gunakan "fc".



10) Kita cuba ubah sedikit nilai dalam file uva12646.in.



11)Kemudian kita bandingkan file uva12646.ans dan uva12646.out, adakah kedua-dua file itu sama nilainya dan ianya akan display bahawa ada nilai yang tak sama.


12)Kita boleh bandingkan dengan melihat fail uva12646.out dan uva12646.ans.




Itu sahaja tutorial yang dapat dikongsi.  Sekian.
10783 - Odd Sum

10783 - Odd Sum

Odd Sum 

Given a range [a, b], you are to find the summation of all the odd integers in this range. For example, the summation of all the odd integers in the range [3, 9] is 3 + 5 + 7 + 9 = 24.

Input 

There can be at multiple test cases. The first line of input gives you the number of test cases, T ( 1$ \le$T$ \le$100). Then T test cases follow. Each test case consists of 2 integers a and b ( 0$ \le$a$ \le$b$ \le$100) in two separate lines.

Output 

For each test case you are to print one line of output - the serial number of the test case followed by the summation of the odd integers in the range [a, b].

Sample Input 

2
1
5
3
5

Sample Output 

Case 1: 9
Case 2: 8

Cara untuk selesaikan problem ni hanya perlu tambah nilai ganjil.. Yang penting ianya inclusive.. Perlu tambah dari nilai dari integer pertama yang di input, sehinggalah sampai input integer yang kedua.

Solution :

10071 - Back to High School Physics

10071 - Back to High School Physics

Problem B
Back to High School Physics
Input: standard input
Output: standard output

A particle has initial velocity and constant acceleration. If its velocity after certain time is v then what will its displacement be in twice of that time?

Input
The input will contain two integers in each line. Each line makes one set of input. These two integers denote the value of v (-100 <= v <= 100) and t(0<=t<= 200) ( t means at the time the particle gains that velocity) 
 
Output
For each line of input print a single integer in one line denoting the displacement in double of that time.

Sample Input
0 0
5 12

Sample Output
0
120


Cara untuk menyelesaikan soalan ini cukup mudah kerana dalam soalan tersebut straight to the point terangkan apa yang perlu dibuat. Cuba baca betul-betul ya jika tidak faham. :)

Solution :

11150 - Cola

11150 - Cola

Problem C : Cola
You see the following special offer by the convenience store:
" A bottle of Choco Cola for every 3 empty bottles returned "
Now you decide to buy some (say N) bottles of cola from the store. You would like to know how you can get the most cola from them.
The figure below shows the case where N = 8. Method 1 is the standard way: after finishing your 8 bottles of cola, you have 8 empty bottles. Take 6 of them and you get 2 new bottles of cola. Now after drinking them you have 4 empty bottles, so you take 3 of them to get yet another new cola. Finally, you have only 2 bottles in hand, so you cannot get new cola any more. Hence, you have enjoyed 8 + 2 + 1 = 11 bottles of cola.
You can actually do better! In Method 2, you first borrow an empty bottle from your friend (?! Or the storekeeper??), then you can enjoy 8 + 3 + 1 = 12 bottles of cola! Of course, you will have to return your remaining empty bottle back to your friend.

Input

Input consists of several lines, each containing an integer N (1 ≤ N ≤ 200).

Output

For each case, your program should output the maximum number of bottles of cola you can enjoy. You may borrow empty bottles from others, but if you do that, make sure that you have enough bottles afterwards to return to them.

Sample Input

8

Sample Output

12

Cara nak selesaikannya saya menggunakan cara brute force. Saya membandingkan output saya dengan output di uvatoolkit. Apa yang saya faham jika tidak boleh dibahagi dengan 3 kita akan tambah 1. Tetapi jika dapat dibahagi dengan 3 dan dapat juga dibahagi dengan 2, maka jawapan last sekali itu kita akan tambah dengan 1. Tapi saya tak tau apa sebabnya.

Solution :
11044 - Searching for Nessy

11044 - Searching for Nessy

Searching for Nessy 

The Loch Ness Monsteris a mysterious and unidentified animal said to inhabit Loch Ness, 
a large deep freshwater loch near the city of Inverness in northern Scotland. Nessie is usually categorized as a type of lake monster.

http://en.wikipedia.org/wiki/Loch_Ness_Monster


In July 2003, the BBC reported an extensive investigation of Loch Ness by a BBC team, using 600 separate sonar beams, found no trace of any ¨sea monster¨ (i.e., any large animal, known or unknown) in the loch. The BBC team concluded that Nessie does not exist. Now we want to repeat the experiment.


Given a grid of n rows and m columns representing the loch, 6$ \le$n, m$ \le$10000, find the minimum number s of sonar beams you must put in the square such that we can control every position in the grid, with the following conditions:

  • one sonar occupies one position in the grid; the sonar beam controls its own cell and the contiguous cells;
  • the border cells do not need to be controlled, because Nessy cannot hide there (she is too big).
For example,


$\textstyle \parbox{.5\textwidth}{
\begin{center}
\mbox{}
\epsfbox{p11044.eps}
\end{center}}$$\textstyle \parbox{.49\textwidth}{
\begin{center}
\mbox{}
\epsfbox{p11044a.eps}
\end{center}}$
\epsfbox{p11044b.eps}
where X represents a sonar, and the shaded cells are controlled by their sonar beams; the last figure gives us a solution.

Input 

The first line of the input contains an integer, t, indicating the number of test cases. For each test case, there is a line with two numbers separated by blanks, 6$ \le$n, m$ \le$10000, that is, the size of the grid (n rows and m columns).

Output 

For each test case, the output should consist of one line showing the minimum number of sonars that verifies the conditions above.

Sample Input 

 
3
6 6
7 7
9 13

Sample Output 

 
4
4
12

Cara untuk selesaikan masalah ini adalah dengan melihat kepada sonar beam itu yg mempunyai 3*3. Jadi kita perlu mencari banyak mana sonar beam yang diperlukan untuk memenuhi satu bentuk segi empat tepat tapi tidak kisah jika "border"nya tidak dipenuhi. Kita boleh tengok syarat-syaratnya disini :
  • one sonar occupies one position in the grid; the sonar beam controls its own cell and the contiguous cells;
  • the border cells do not need to be controlled, because Nessy cannot hide there (she is too big).
Jadi untuk selesaikannya kita perlu bahagikan row/3 dan column/3, tetapi jika ada perpuluhan, abaikan. Kita gunakan integer dalam problem ini. Setelah dibahagikan, kemudian darabkan kedua-dua jawapan tersebut. Cara ini saya dapat dengan brute force. :)

Solution :

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));
}
}
}
10921 - Find the Telephone

10921 - Find the Telephone

Problem Link

Cara nak selesaikan soalan ni senang sangat untuk di selesaikan. Kita hanya perlu membuat perbandingan dengan menggunakan "if-else" statement, kemudian display mengikut syarat yang tertera dalam yang table yang telah ditunjukkan. Sebagai contoh jika kita masukkan 'A' maka ianya akan display '2'.

Solution :

import java.util.*;
public class uva10921 {
public static void main(String [] args) {
Scanner scn = new Scanner(System.in);
while(scn.hasNextLine()) {
String s = scn.nextLine();
for(int y=0;y<s.length();y++) {
if(s.charAt(y)=='A' || s.charAt(y)=='B' || s.charAt(y)=='C')
System.out.print("2");
else if(s.charAt(y)=='D' || s.charAt(y)=='E' || s.charAt(y)=='F')
System.out.print("3");
else if(s.charAt(y)=='G' || s.charAt(y)=='H' || s.charAt(y)=='I')
System.out.print("4");
else if(s.charAt(y)=='J' || s.charAt(y)=='K' || s.charAt(y)=='L')
System.out.print("5");
else if(s.charAt(y)=='M' || s.charAt(y)=='N' || s.charAt(y)=='O')
System.out.print("6");
else if(s.charAt(y)=='P' || s.charAt(y)=='Q' || s.charAt(y)=='R' || s.charAt(y)=='S')
System.out.print("7");
else if(s.charAt(y)=='T' || s.charAt(y)=='U' || s.charAt(y)=='V')
System.out.print("8");
else if(s.charAt(y)=='W' || s.charAt(y)=='X' || s.charAt(y)=='Y' || s.charAt(y)=='Z')
System.out.print("9");
else if(s.charAt(y)=='1')
System.out.print("1");
else if(s.charAt(y)=='0')
System.out.print("0");
else if(s.charAt(y)==' ' )
System.out.print(" ");
else if(s.charAt(y)=='-')
System.out.print("-");
}
System.out.println("");
}
}
}
483 - Word Scramble

483 - Word Scramble

Problem Link

Cara nak selesaikan soalan ini adalah dengan pisahkan perkataan-perkataan dalam ayat itu dengan menggunakan "split" lepas tu kita pecahkan perkataan tersebut kepada karakter-karakter dan kita display karakter yang paling hujung sekali sehinggalah karakter dengan index 0.

Solution :

import java.util.*;
public class uva483 {
public static void main(String [] args) {
Scanner scn = new Scanner(System.in);
while(scn.hasNextLine()) {
String s = scn.nextLine();
String [] st = s.split(" "); 
for(int x=0;x<st.length;x++) {
for(int y=st[x].length()-1;y>=0;y--)
System.out.print(st[x].charAt(y));
if(x != st.length-1)
System.out.print(" ");
}
System.out.println("");
}
}
10082 - WERTYU

10082 - WERTYU

Problem Link

Caranya sangat senang iaitu dengan menggunakan  "if-else" statement. Sebagai contoh jika huruf 'S' di masukkan, maka ianya akan keluarkan output 'A'. Yang penting jangan lupa letak 'space' sekali.

Solution :

import java.util.*;
public class uva10082 {
public static void main(String [] args) {
Scanner scn = new Scanner(System.in);
while(scn.hasNextLine()) {
String s = scn.nextLine();
for(int x=0;x<s.length();x++) {
char c = s.charAt(x);
if(c == 'W')
System.out.print('Q');
else if(c == ' ')
System.out.print(' ');
else if(c == 'E')
System.out.print('W');
else if(c == 'R')
System.out.print('E');
else if(c == 'T')
System.out.print('R');
else if(c == 'Y')
System.out.print('T');
else if(c == 'U')
System.out.print('Y');
else if(c == 'I')
System.out.print('U');
else if(c == 'O')
System.out.print('I');
else if(c == 'P')
System.out.print('O');
else if(c == '[')
System.out.print('P');
else if(c == ']')
System.out.print('[');
else if(c == '\\')
System.out.print(']');
else if(c == 'S')
System.out.print('A');
else if(c == 'D')
System.out.print('S');
else if(c == 'F')
System.out.print('D');
else if(c == 'G')
System.out.print('F');
else if(c == 'H')
System.out.print('G');
else if(c == 'J')
System.out.print('H');
else if(c == 'K')
System.out.print('J');
else if(c == 'L')
System.out.print('K');
else if(c == ';')
System.out.print('L');
else if(c == '\'')
System.out.print(';');
else if(c == 'X')
System.out.print('Z');
else if(c == 'C')
System.out.print('X');
else if(c == 'V')
System.out.print('C');
else if(c == 'B')
System.out.print('V');
else if(c == 'N')
System.out.print('B');
else if(c == 'M')
System.out.print('N');
else if(c == ',')
System.out.print('M');
else if(c == '.')
System.out.print(',');
else if(c == '/')
System.out.print('.');
else if(c == '1')
System.out.print('`');
else if(c == '2')
System.out.print('1');
else if(c == '3')
System.out.print('2');
else if(c == '4')
System.out.print('3');
else if(c == '5')
System.out.print('4');
else if(c == '6')
System.out.print('5');
else if(c == '7')
System.out.print('6');
else if(c == '8')
System.out.print('7');
else if(c == '9')
System.out.print('8');
else if(c == '0')
System.out.print('9');
else if(c == '-')
System.out.print('0');
else if(c == '=')
System.out.print('-');
}
System.out.println("");
}
}
}

272 - TEX Quotes

272 - TEX Quotes

Problem Link

Pada mulanya ingatkan guna StringTokenizer tapi tak boleh sebab ada tak tahu nak display balik macam mana nanti, nak tukar ' " ' ke ' ``' pun susah nanti. Jadi setelah cari kat internet, ada jumpa caranya. Caranya dengan menggunakan character. kita akan bandingkan character demi character, jika character tersebut mempunyai karakter ' " ' untuk kali pertama maka kita tukarkan ia kepada ' `` ' sambil kita tambahkan nilai pada satu variable yang menentukan sama ada itu karakter pertama atau kedua. dengan menggunakan teknik mencari baki dari operasi pembahagian(modulus). jika bakinya kosong, maka ianya kedua, dan sebaliknya pertama. :)

Solution :

import java.util.*;
public class uva272 {
public static void main(String [] args) {
Scanner scn = new Scanner(System.in);
String ls = System.getProperty("line.separator");
scn.useDelimiter(ls);
int b=1;
while(scn.hasNext()) {
String s = scn.next();
for(int x=0;x<s.length();x++) {
char c =  s.charAt(x);
if(c == '"') {
if(b%2==1) {
System.out.print("``");
b++;
}
else {
System.out.print("''");
b++;
}
}
else 
System.out.print(c);
}
System.out.println("");

}
}
}