This is my personal collection of daily lessons, professional insights, and programming experiences. It’s a space where I document what I learn, and you can explore and learn from my journey too.
Sunday, September 20, 2015
Thursday, September 17, 2015
UVA - 136 - Ugly Numbers Using Java
136 - Ugly Numbers
Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence
1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, ...
shows the first 11 ugly numbers. By convention, 1 is included.
Write a program to find and print the 1500'th ugly number.
Input and Output
There is no input to this program. Output should consist of a single line as shown below, with <number> replaced by the number computed.
Sample output
The 1500'th ugly number is <number>.
public class Main{
public static void main(String[] args) {
System.out.println("The 1500'th ugly number is 859963392.");}
}
UVA-12577 (Hajj-e-Akbar) EASY Using Java
UVA-12577 (Hajj-e-Akbar) EASY
import java.util.Scanner;public class Main{
public static void main(String[] args) {
String a=new String(); int i=1; Scanner s=new Scanner(System.in); while((a=s.nextLine()) != null) {if(a.charAt(0)=='*')
break;else if(a.equals("Hajj"))
{System.out.println("Case "+i+":"+" Hajj-e-Akbar");
}
else if (a.equals("Umrah")) {
System.out.println("Case "+i+":"+" Hajj-e-Asghar");
}
i++;
}
}
}
UVA-12478 - Hardest Problem Ever (Easy) Using Java
UVA -11150–Cola (EASY) Using Java
11150 - Cola
Time limit: 3.000 secondsProblem C : Cola
Time limit: 10 seconds
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
Note: Drinking too much cola is bad for your health, so... don't try this at home!! :-)
Idea from a traditional IQ challenge question.
Special Thanks: Jonathan Mak
1: import java.util.Scanner;
2: public class Main{
3: 4: public static void main(String[] args) {
5: Scanner s=new Scanner(System.in);
6: int a,b,c,d,k=0;
7: 8: while(s.hasNext())
9: { 10: a=s.nextInt(); 11: int sum=a;
12: a=a+1;13: for(int i=1;i<a;a=k)
14: { 15: c=a/3; 16: d=a%3; 17: k=c+d; 18: sum=sum+c;19: if(k==2||k==1)
20: {21: break;
22: } 23: } 24: System.out.println(sum); 25: } 26: } 27: 28: }


