Monday, July 23, 2018

Programming Problem Terminology for Problem Designers

Programming Problem Terminology for Problem Designers
What problems will work?
1. Read input from stdin and output to stdout.
2. Name the class as Main in Java.
3. Program must contain a main() method.
4. Evaluate programs based on the test cases which include input and the corresponding output.
5. For each programming problem, all the test cases corresponding to that problem will be run.
Score = (number of successes/ total number of test cases) *100%
6. Each test case would be run against a fixed time out (which is 8 sec for now and have to be determined). The size of the input and output is not limited.

Exam Instructions for Examinee:
In Programming section if you use Java,
Name the class as Main. Your program must contain a public static void main(string[] args)  method which reads input from stdin and output to stdout
If you use C# your class must contain public static void Main(string[] args) which reads input from stdin and output to stdout

Sample Problem:
You have got a range of numbers between 1 to N, where one of the numbers is repeated. You need to write a program to find out the duplicate number.


Sample Test cases:
Data Set Input Output
1 0 3 2 7 9 9 4    9
2 80 3 2 9 99 7 0 1 7 79 44 33 56 67 89 88 78 63 34 32 38 47 8 4 27965  43752  15488  18410  41356  37480  8678  13635  31532  29352  40413  23158  4347  29432  46659  45783  32156  7
3 22477  16608  14208  3579  38156  41  49523  8884  31114  38254  6133  6032  6838  42650  42457  11380  30785  30295  35461  17199  8311  2266  43719  8851  43966  27635  12256  45083  38490  17856  26463  5246  39137  42821  10349  46336  29396  3131  44969  8708  9429  37687  41780  44158  36055  31252  19186  23944  21798  6550  27276  49463  29064  39584  5060  5086  19460  35477  20883  44276  41113  11393  17411  41193  3786  23743  37030  28463  457  44770  19311  14069  17036  32872  11035  26694  13583  2496  41488  44868  29165  28540  6325  16504  13702  10539  23515  20496  8814  4372  35492  31559  23388  12119  34484  22477  8220  29380  49738  48480  29071  14781  26890  47515  23151  30856  30108  19888  13464  11831  25887  27965  43752  15488  18410  41356  37480  8678  13635  31532  29352  40413  23158  4347  29432  46659  45783  32156  28270  21977  19995  12963  16438  16610  27607  35385  36271  10223  44212  31022  11220  13888  10717  21864  15745  10489  3966  5303  42395  21729  6987  15560  18631  34321  49745  39271  30996  35842  24049  36385  12182  45227  23355  2517  34566  6434  11775  42280  4473  21119  43460  24103  28334  40792  23764  37701  46719  35502  10661  46243  28658  22477




Sample Answer:
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {
   public static void findDuplicateNumber(int[] ar) {
        Arrays.sort(ar);

        for (int i = 1; i < ar.length; i++) {
            if (ar[i] == ar[i - 1]) {
                System.out.println(ar[i]);
                break;
            }
        }      
    }  
    public static void main(String a[]){
        Scanner scan = new Scanner(System.in);
        List numbers = new ArrayList();
        while (scan.hasNextInt()) {
            numbers.add(scan.nextInt());
                }
       
        int[] arr=new int[numbers.size()];
       
        for(int x=0;x
               arr[x]=numbers.get(x);        
        }
       findDuplicateNumber(arr);
            }
}







Sample Answer 2

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import   java.lang.Math.*;

public class Main {

  public static void smallestDistance(int ints[]) {

                        int index = 0;

                        for (int i = 1; i < ints.length - 1; i++) {
                                    if (Math.abs(ints[index] - ints[index + 1]) > Math.abs(ints[i]
                                                            - ints[i + 1])) {
                                                index = i;
                                    }
                        }
                        System.out.println(index);
            }
           
    public static void main(String a[]){
        Scanner scan = new Scanner(System.in);
        List numbers = new ArrayList();
        while (scan.hasNextInt()) {
            numbers.add(scan.nextInt());
                }
       
        int[] arr=new int[numbers.size()];
       
        for(int x=0;x
               arr[x]=numbers.get(x);        
        }
        smallestDistance(arr);
            }
}

No comments:

Post a Comment