Presentation is loading. Please wait.

Presentation is loading. Please wait.

Online Judge System Tom Chao Zhou CSC2100B Data Structures Tutorial 2.

Similar presentations


Presentation on theme: "Online Judge System Tom Chao Zhou CSC2100B Data Structures Tutorial 2."— Presentation transcript:

1 Online Judge System Tom Chao Zhou CSC2100B Data Structures Tutorial 2

2

3 Online Judge Writing Your Assignment Program.  Write your program using your favorite editor, e.g. vi, vim, pico, emacs, Visual Studio 2008, etc. Add a header at the first line of your program.

4 Online Judge /* CSC2100@ 09123456 a1234567 assg0_question0 */ #include int main(int argc, char **argv) { int a, b; printf("Please enter two numbers: \n"); scanf("%d %d", &a, &b); printf("The numbers you entered are %d and %d \n", a, b); printf("And their sum is %d \n", a + b); return 0; }

5 Online Judge /* CSC2100@ 09123456 a1234567 assg0_question0 */ Course Code: CSC2100@ Student ID: 09123456 Login ID: a1234567 Problem ID: assg0_question0

6 Online Judge Submitting Your Program  Compile and test your program in Unix (Linux, Sparc) To Compile in Unix:  gcc –o myprogram myprogram.c To Run: ./myprogram  Submit to Online Judge when ready Login to a sparc(or linux) machine mail csc2100@pc89072.cse.cuhk.edu.hk < myprogram.ccsc2100@pc89072.cse.cuhk.edu.hk  Wait for reply in your CSE mailbox  For those who are not CSE students, send your student id and name to TA before this Friday(29, Jan) to get an account. (czhou@cse.cuhk.edu.hk)

7 Online Judge Online Judge Reply Messages Accepted  Congratulation Submission Error  Check your header line Compile Error

8 Online Judge Runtime Error  Time Limit Exceeded Check your algorithm. Infinite loops?  Output Limited Exceeded Check your algorithm. Infinite loops?  Float Point Exceptions Division by 0  Segmentation Fault,... Check your code, e.g. errors in pointers. Wrong Answer. Presentation Error.

9 Online Judge A word about ”Presentation Error” Make sure your output is EXACTLY the same as the specification, (or sample program, if provided).  Check for upper case / lower case letters.  Check for extra spaces / extra blank lines. There should be no extra spaces at the end of a line, and no extra blank lines at the end of the outputs.

10 Online Judge Demostration Question Id: 2010A0Q0 Write a program to calculate the products of two integers.  Input the number of products to be computed.  While the number of products is not exceeded, do: Input two integers. Display their product.  You can assume the inputs are within the range 0 < x < 10000. Sample inputExpected output 3P: 2 1 2P: 12 3 4 P: 30 5 6

11

12 Scanf Printf type Input dType signed int represented in base 10. Digits 0 through 9 and the sign (+ or -). iType signed int. The base (radix) is dependent on the first two characters. If the first character is a digit from 1 to 9, then it is base 10. If the first digit is a zero and the second digit is a digit from 1 to 7, then it is base 8 (octal). If the first digit is a zero and the second character is an x or X, then it is base 16 (hexadecimal). oType unsigned int. The input must be in base 8 (octal). Digits 0 through 7 only. uType unsigned int. The input must be in base 10 (decimal). Digits 0 through 9 only. x, XType unsigned int. The input must be in base 16 (hexadecimal). Digits 0 through 9 or A through Z or a through z. The characters 0x or 0X may be optionally prefixed to the value. e, E, f, g, G Type float. Begins with an optional sign. Then one or more digits, followed by an optional decimal-point and decimal value. Finally ended with an optional signed exponent value designated with an e or E. sType character array. Inputs a sequence of non-whitespace characters (space, tab, carriage return, new line, vertical tab, or formfeed). The array must be large enough to hold the sequence plus a null character appended to the end. scanf(“%d”,&x) printf(“%d”,x)

13 scanf printf modifier scanf type Effect hd, i, o, u, x The argument is a short int or unsigned short int. ld, i, o, u, x The argument is a long int or unsigned long int. le, f, gThe argument is a double. Le, f, gThe argument is a long double.

14 /* CSC2100@ 080238xx loginid WRONG-QID */ #include int main(int argc, char **argv) { short a = 0; short b = 0; short p; int i=0; int count; scanf("%d", &count); while (i < count) { scanf("%hd %hd", &a, &b); p=a*b; printf("P: %hd \n", p); } return 0; } //Submission Error: Please check the header format of your program. //Attemp 1

15 /* CSC2100@ 080238xx loginid 2010A0Q0 */ #include int main(int argc, char **argv){ short a = 0; short b = 0; short p; int i=0; int count; scanf("%d", &count); while (i < count) { scanf("%hd %hd", &a, &b); p=a*b; printf("P: %hd \n", p); } return 0; } //Runtime Error: Output Limit Exceeded. //Attemp #2

16 /* CSC2100@ 080238xx loginid 2010A0Q0 */ #include int main(int argc, char **argv){ short a = 0; short b = 0; short p; int i=0; int count; scanf("%d", &count); while (i < count) { scanf("%hd %hd", &a, &b); p=a*b; printf("P: %hd \n", p); i++; } return 0; } //Wrong Answer: Please check your program. //Attemp #3 //short 16bits – 65535 //int 32 bits – 4*10^9 //long long 64 bits – 1*10^19

17 /* CSC2100@ 080238xx loginid 2010A0Q0 */ #include int main(int argc, char **argv){ short a = 0; short b = 0; int p; int i=0; int count; scanf("%d", &count); while (i < count) { scanf("%hd %hd", &a, &b); p=a*b; printf("P: %d \n", p); i++; } return 0; } //Presentation Error //Attemp #4

18 /* CSC2100@ 080238xx loginid 2010A0Q0 */ #include int main(int argc, char **argv){ short a = 0; short b = 0; int p; int i=0; int count; scanf("%d", &count); while (i < count) { scanf("%hd %hd", &a, &b); p=a*b; printf("P: %d\n", p); i++; } return 0; } //Accepted: Congratulations! //Attemp #5

19 Check your score:  http://pc89072.cse.cuhk.edu.hk/~csc2100/score.html http://pc89072.cse.cuhk.edu.hk/~csc2100/score.html Method to calculate your score:  /* To be reconfirmed */  /* Will be adjusted for each assignment */  /* Note: The score is for reference only, */  /* and does not reflect your final grade */  my @award = (0, 4, 3, 2, 1, 0, 0, 0, 0, 0);  the 0th entry is no use, the 1st entry is the number of award times in the 1st day.  pen = # of submissions -1-award[x]; //x is the day when you successfully finish the program  if (pen<0){  pen = 0;  }  mark = 30 + (70-$pen*5);

20 Check the question id on the course page. Programming Asgn1:  116  118

21 Q & A


Download ppt "Online Judge System Tom Chao Zhou CSC2100B Data Structures Tutorial 2."

Similar presentations


Ads by Google