Blog Post

UTS 2012 Programming Competition – Q1, Q2, Q3

🗓 August 28, 2012 :: 🕑 2 min read :: 👏 0 💬 0

A couple weeks ago, I attended the UTS Programming Competition as a group of three. Although we didn’t go quiet as well but it wasn’t too bad either. We had four hours to solve as many questions from the 8 questions given and the time we took to solve them were accumulated into points. It was definitely an interesting experiences and I would definitely attend it again.

Below are the questions from this years Programming Competition and my solution for the first three questions implemented in Java. Will post up rest of my solutions in a another post.

Question 1

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class problem1 { public static void main (String[] args) throws IOException { int n; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); n = Integer.parseInt(br.readLine()); if (n >= 1 || n <= 80) { for (int i = 1; i <= n; i++){ for (int j = 0; j < i; j++ ){ System.out.print("*"); } System.out.print("\n"); } } } }

Question 2

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class problem2 { public static void main (String[] args) throws IOException { int n; String s; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while ((s = br.readLine()) != null) { n = Integer.parseInt(s); if (n >= 1 || n <= 9999999) { int sum = 0; int len = s.length(); for (int i = 0; i < len; i++) { sum += Character.getNumericValue(s.charAt(i)); } if (n % sum == 0) { System.out.println(s + " GREAT JOY"); } else { System.out.println(s + " sadness"); } } } } }

Question 3

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class problem3 { public static void main (String[] args) throws IOException { int nPages, nLines; String page, line; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while ((page = br.readLine()) != null) { nPages = Integer.parseInt(page); if (nPages >= 1 || nPages <= 100) { for (int i = 0; i < nPages; i++ ){ nLines = Integer.parseInt(br.readLine()); for (int j = 1; j <= nLines; j++){ line = br.readLine(); if (line.toLowerCase().contains("molly")){ System.out.println(j); } } } System.exit(0); } } } }
Ben Shi

A couple weeks ago, I attended the UTS Programming Competition as a group of three. Although we didn’t go quiet as well but it wasn’t too…

https://hbish.com/uts-2012-programming-competition-q1-q2-q3/


Fetching Replies...