CodeJudge



Introduction


CodeJudge is an online judge system maintained by Code Club board team. Here we have a collection of programming problems for practice purposes, which can be solved in one of the following languages: Java, C, C++, Python. Moreover, Codejudge will be used as the environment to organize programming contests.


Read this document carefully, and for any question please email us. Note that the content of this document or some instructions may change over time as the website develops. In such cases all members will be notified.

Registration  and log in


Please register to the website by using your real name, surname and school email address  (this information will not be visible to other users). The choice of our username is up to you, but you can not change it later on. In case you are already registered but you forgot your password, please email us so we can provide you another password.

Problem archive


In the problem archive you can find the list of all problems available to solve. After choosing the problem and clicking Solve button, you can see all the specifications of the problem, such as problem statement, time limit and allowed programming languages.

Contest
In the contest section you will be able to see all the current contest problems until the contest time ends. After the contests is over and the winners are announced, all the contest questions will be added to the problem archive. Before participating in a contest, read carefully the instructions on how to submit your solutions.


How to submit your solution


During the contests, keep in mind the following things:


Before starting to code:
  • Make sure you fully understand the problem statements and what the question asks.
  • If you have questions, please ask.


Before submitting your solution:


  • Make sure to save it in your computer.
  • Test your program by giving as input the sample input in the problem statements. If your program does not give the correct output, then try to debug it.
  • Design some other test cases by your own test your program with them. Try to include some corner test cases as well.
  • Do not forget to choose the correct language while submitting.


After submission:


  • If your solution is accepted, congratulations!
  • If you get wrong answer or time limit, you most probably have a bug. Try to figure it out by designing some more test cases.
  • If you get some strange error message, please contact us.

Your solution to the problem will be evaluated by the online judge by running it with several test cases. Therefore, your program should be prepared to get multiple test cases as an input. Below we will give a sample problem, and we will explain how you should get the input in each programming language.




Description: Given a list of numbers, return the sum of all of them.
Input: The first line of the input is a number T (0<T<=10): the number of test cases. Each test case input is formatted as follows: First line is N (0<N<=100), the number of elements in the list. The following line contains the N elements of the list.
Output: For each test case, print the sum of the elements.
Sample Input:
3
4
3 4 5 3
2
2 1
1
4
Sample Output:
15
3
4


Let’s take a closer look at the sample input:
3                         => T, the number of test cases
4                          => N for test case 1
3 4 5 3                 => the elements of the list, whose sum is 15
2                          => N for test case 2
2 1                       => the elements of the list, whose sum is 15
1                          => N for test case 3
4                          => the elements of the list, whose sum is 15


The following sections will describe how to code your program so that it can get the input formatted in this given way.


Java
In Java, your class name should be Solution.


import java.util.Scanner;


public class Solution{
  public static void main(String[] args){
      // create a scanner object to get the input from the keyboard
      Scanner scanner = new Scanner(System.in);


      // get T, the number of test cases
      int T = scanner.nextInt();


      // a loop running for each test case
      for(int t=0; t<T; t++){
          // get N, the number of elements in the list
          int N = scanner.nextInt();


          // initialize the sum of the list as 0
          int sum = 0;


          // a loop running for each element of the list
          for(int i=0; i<N; i++){
              // get the next element in the list and add it to sum
              int curr = scanner.nextInt();
              sum += curr;
          }


          // print the resulting sum
          System.out.println(sum);
      }
  }
}


C++


#include<iostream>
using namespace std;
int main(){
      // get T, the number of test cases
      int T;
      cin>>T;


      // a loop running for each test case
      for(int t=0; t<T; t++){
      // get N, the number of elements in the list
      int N;
      cin>>N;


      // initialize the sum of the list as 0
      int sum = 0;


      // a loop running for each element of the list
      for(int i=0; i<N; i++){
      int curr;
      // get the next element in the list and add it to the sum
      cin>>curr;
      sum += curr;
      }
      // print the resulting sum
      cout<<sum<<endl;
      }
      return 0;
}


C


#include<stdio.h>
int main(){
      // get T, the number of test cases
      int T;
      scanf("%d", &T);


      // a loop running for each test case
      int t;
      for(t=0; t<T; t++){
      // get N, the number of elements in the list
      int N;
      scanf("%d", &N);


      // initialize the sum of the list as 0
      int sum = 0;


      // a loop running for each element of the list
      int i;
      for(i=0; i<N; i++){
      int curr;
      // get the next element in the list and add it to the sum
      scanf("%d", &curr);
      sum += curr;
      }
      // print the resulting sum
      printf("%d\n", sum);
      }
      return 0;
}


Python


T = int(input())            # get T, the number of test cases
for i in range(0, T):
n = int(input())     # get n, the number of elements in the list
L = input().split()  # create a list containing all the elements
sum = 0
for j in range(0, len(L)):    
sum = sum + int(L[j])   # add each element of the list to sum
print(sum)           # print sum

No comments:

Post a Comment