Skip to content

Instantly share code, notes, and snippets.

View husnain-iqbal's full-sized avatar

Husnain Iqbal husnain-iqbal

  • Lahore, Pakistan
View GitHub Profile
@husnain-iqbal
husnain-iqbal / gist:ddbac2992dddd0c8bd97
Created February 16, 2016 06:37
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int a0 = 0; a0 < t; a0++){ int n = in.nextInt(); int temp = n; int answer = 0; while(temp>0){ int digit = temp%10; …
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
@husnain-iqbal
husnain-iqbal / gist:e8a3123137f38ff20fde
Created February 16, 2016 04:13
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int a0 = 0; a0 < t; a0++){ int n = in.nextInt(); int k = in.nextInt(); int a[] = new int[n]; int studentsOnTime = 0…
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
@husnain-iqbal
husnain-iqbal / gist:aa1fb6f25369ff52b1aa
Created February 15, 2016 16:50
Given a time in AM/PM format, convert it to military (24-hour) time. Note: Midnight is 12:00:00AM on a 12-hour clock and 00:00:00 on a 24-hour clock. Noon is 12:00:00PM on a 12-hour clock and 12:00:00 on a 24-hour clock. Input Format A time in 12-hour clock format (i.e.: hh:mm:ssAM or hh:mm:ssPM), where 01≤hh≤1201≤hh≤12. Output Format Convert an…
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
@husnain-iqbal
husnain-iqbal / gist:3a146841cc80b98ed43b
Created February 15, 2016 16:27
Your teacher has given you the task of drawing a staircase structure. Being an expert programmer, you decided to make a program to draw it for you instead. Given the required height, can you print a staircase as shown in the example? Input You are given an integer NN depicting the height of the staircase. Output Print a staircase of height NN th…
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
@husnain-iqbal
husnain-iqbal / gist:963bf7f7e6d0130cbe44
Created February 15, 2016 16:02
Given an array of integers, calculate which fraction of the elements are positive, negative, and zeroes, respectively. Print the decimal value of each fraction. Input Format The first line, NN, is the size of the array. The second line contains NN space-separated integers describing the array of numbers (A1,A2,A3,⋯,ANA1,A2,A3,⋯,AN). Output Forma…
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
@husnain-iqbal
husnain-iqbal / gist:627c48c77acfbe3bc779
Created February 15, 2016 15:25
Given a square matrix of size N×NN×N, calculate the absolute difference between the sums of its diagonals. Input Format The first line contains a single integer, NN. The next NN lines denote the matrix's rows, with each line containing NN space-separated integers describing the columns. Output Format Print the absolute difference between the two…
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.lang.*;;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
@husnain-iqbal
husnain-iqbal / gist:d5874b6cb13633bab6f1
Created February 15, 2016 14:45
You are given an array of integers of size NN. You need to print the sum of the elements in the array, keeping in mind that some of those integers may be quite large. Input The first line of the input consists of an integer NN. The next line contains NN space-separated integers contained in the array. Constraints 1≤N≤101≤N≤10 0≤A[i]≤10100≤A[i]≤1…
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
@husnain-iqbal
husnain-iqbal / gist:02e2f5c2f96f28ff2ef2
Created February 15, 2016 14:40
You are given an array of integers of size NN. Can you find the sum of the elements in the array? Input The first line of input consists of an integer NN. The next line contains NN space-separated integers representing the array elements. Sample: 66 11 22 33 44 1010 1111 Output Output a single value equal to the sum of the elements in the array.…
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {