providing in puts to code vita

Upload: abhishek-jay-kumar

Post on 04-Apr-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 Providing in Puts to Code Vita

    1/6

    Providing Inputs to CodeVita

    Contents

    Background .......................................................................................................................................... 2

    Pre-requisites before deep-diving into understanding input specifications ............................................ 2

    Understanding input specifications ....................................................................................................... 3

    Important Points ................................................................................................................................... 6

  • 7/31/2019 Providing in Puts to Code Vita

    2/6

    BackgroundThe purpose of this document is to help CodeVita participants understand how to provide inputs to

    CodeVita Code Evaluation Platform. Far too many submissions from Practice round have ended in

    Compile Time errors and Run Time errors. In that sense, consider this document as a continuation to

    previous document titled Common Mistakes in using CodeVita Code Evaluation Platform. This

    earlier document is available for download from CodeVita portal (http://tcscodevita.com) as well as

    on Campus Commune at https://nextstep.tcs.com

    This document provides a sample problem text and provides its solution in C/C++/Java and C#. This

    will help participants to understand how to provide input to CodeVita.

    Pre-requisites before deep-diving into understanding input specifications

    1. You should have read and understood the following documentsa. CodeVita User Manualb.

    Common Mistakes in using CodeVita Code Evaluation Platform

    2. You have understood the problem statement correctly i.e.a. Understood how to give inputs to this particular problemb. Understood what should be the output formatc. Understood what is to be computed from your program

    3. You are aware that CodeVita platforma. Compiles your source code (provided in single source file) and runs a battery of test

    cases against it.

    b. For running a battery of test cases against your program, CodeVita platform requiresthat input specifications are adhered to.

    c. After a test case has been run, CodeVita platform needs to decide if the output fromyour program is the correct output. For this reason, output specifications need to be

    adhered to

    4. You are aware that no human user sees the program and everything from compilingprograms to declaring status, is automated.

    5. You understand what different status messages that CodeVita provides, mean.

  • 7/31/2019 Providing in Puts to Code Vita

    3/6

    Understanding input specifications

    Lets understand the specification in context of a problem. The problem is as stated below.

    Problem C

    Sum Of Number(Simple Problem)

    Problem Statement:

    Write a program to calculate the sum of n numbers and print the sum.

    Input Format

    Line 1 An integer n - the number of integers to be

    added.

    Line 2 Various integers.

    Output Format

    Line 1 Single integer which corresponds to sum,

    followed by a new line

    Sample Inputs and Outputs

    Sr.No Input Output

    1 3

    1

    2

    3

    6

    2 3

    10

    10

    10

    30

    (Note:-Please do not forget to end your program with a new line, else you may get a Compile

    Time Error from the Code Evaluation Engine)

  • 7/31/2019 Providing in Puts to Code Vita

    4/6

    The solutions to these problems which adhere to the input specification are written as shown below

    C

    #include

    #include

    int main()

    {

    int *p,n,i,sum=0;

    scanf("%d",&n);

    p=(int*) malloc(n*sizeof(int));

    for(i=1;i>n;

    int *p;

    p=new int[n];

    for(int i=0;i>p[i];

    sum+=p[i];

    }

    cout

  • 7/31/2019 Providing in Puts to Code Vita

    5/6

    Java

    import java.io.*;

    import java.util.Scanner;

    public class SumOfNumber {

    public static void main(String args[])

    {

    int n,sum=0,arr[];

    Scanner sc=new Scanner(System.in);

    n= sc.nextInt();

    arr = new int[n];

    for(int i=0; i

  • 7/31/2019 Providing in Puts to Code Vita

    6/6

    Note: - The above snippets are submitted by CodeVita participants who correctly understood and

    implemented the input specification. All these programs areAcceptedin the system.

    Important Points

    1. Note how, C/C++ programs return 0 and end with a new line character.2. Note how programs do not verbosely accept input i.e. there is no text like How many

    numbers you want to add? etc. The inputs specifications do not mention asking verbose

    questions. These programs do not ask those questions, but still read the input correctly,

    because they adhere to the specification.

    3. Similarly, for programs which need absolute path of a file as inputs, do not print text likeEnter absolute file path of the input file.

    4. Note how, all the program start execution and then block on inputs usinga. scanf() in Cb. cin in C++c. Scanner.nextXXX() in Java and,d. Console.ReadLine() in C#CodeVita platform expects the program to be running for it to provide the inputs. Your

    program has to be in a running state before CodeVita engine can give input(s) to it. If your

    program expects command-line arguments, then as soon as the program is launched, it willthrow exceptions (because CodeVita does not provide inputs as command line arguments)

    and you will receive a Run-Time Error status message.

    5. Once you read inputs from console, it is your responsibility to use appropriate functionsfrom your language to convert it into data types needed to solve the problem.

    6. Some of the CodeVita problems ask you to read the input file name from console. Youshould use techniques mentioned in points 4 & 5 above and then use appropriate file

    handling functions to read the files. You will never be asked to write to your output a file.

    Output always has to be printed to the console in specified format.