PDA

View Full Version : *** أول سؤال في البرمجة ***<< اختبر قدراتك في البرمجة


مبرمج الإمارات
07-02-2006, 04:51 PM
إلى جميع عشاق البرمجة.... أخبركم أن مبرمج الإمارات هنا :glasses2: << :confused: >> :p ...



طبعا كلكم تتريون هالموضوع عشان تختبرون قدراتكم في البرمجة ( يكفي امتحانات الجامعة :ranting: ).. المهم :



اليوم عندي لكم سؤال سههههههههل والغرض من سهولتها أن أنا راح أقيم برامجكم عن طريق سيرفر لموقع خاص لحل المسائل البرمجية.... والموقع هذا يعطيك الأسئلة بالتدرج ... يعني عشان تشوف السؤال التالي.. لازم تحل السؤال الي قبله وهكذا...



ولأني أبا أريحكم قلت... راح أعطيكم الأسئلة وانتوا تحلوها وبعدين ترسولي الكود وأنا أجربه في الموقع وأخبركم ببالنتيجة :p



طبعا في شروط للبرامج الي راح ترسلولي إياها وهي باختصار كالتالي:

1- الموقع يقبل البرامج باللغات التالي: C/C++, PASCAL, and Java وللابتعاد عن الاشكاليات.. استعملوا ال++C :D

2- الكومبايلرات اليديدة تستعمل 32 بت للانتجر أما البورلاند فيستعمل 16 بت... فانتبهوا لهالنقطة

3- مدخلات ومخرجات البرامج (input and output ) تكون من ملفات تحدد في كل مسألة << يقرأ المدخلات من ملف ويخزن المخرجات في ملف آخر ( file stream (ifstrem

4- دايما استعملوا return 0 لإنهاء برامجكم..

5- البرنامج لازم يكون قادر على أنه يشتغل ويخلص في خلال ثانية واحدة فقط

6- حجم الستاك والكيو لا يتعدى ال 1MB

7- أكبر حجم للمصفوفة (أرراي) هو 1000*1000 (يعني 1000000 خلية )

8- ملفات الدخل والخرج دائما تنتهي بسطر فاضي أي "n\" ..

9- الملفات الي ترسلولي إياها هي ملفات الكود وليس ملفات الexe

9- للتفاصيل.. اقرأ النسخة الانجليزية من الموقع: << كأني طولت علييكم :cry1:



Submitting Solutions



The USACO Training Program features an automatic grading system for your homework problems. You submit your programs from the problem page itself; they are compiled and graded; the results are conveyed back to you -- all within a few seconds.

C/C++, PASCAL, and Java are available. This system uses the GNU GCC compilation suite for C/C++ programs and the Free Pascal system for Pascal programs. The Java compiler is gjc as this is written and is soon to be upgraded.

The grading system compilers are those often used at the IOI (though Java is not used at the international championships).

These newer compilers uses 32 bit int's; the Borland compilers use 16 bit int's. DO NOT GET IN TROUBLE BECAUSE OF THIS!

Submit solutions via the web by typing the name of the file containing the source code into the 'Submit a file:' box at the bottom of problem description pages..

Program submissions require simple Header comments: your ID (i.e., your USACO login name), the name of the program (which will be given in each programming assignment, and the language used. See the examples below to get the idea.

Every training page problem has input and output. Currently, the input appears in a file named 'probname.in' (e.g., if the problem name is 'ride', then the input filename is 'ride.in'). Output must be written to a file named 'probname.out' (i.e., 'ride.out' for the 'ride' problem).
The First Challenge



The simplest programming challenge is named 'test' and requires you to read a pair of small integers from a single input line in the file 'test.in' and print their sum to the file 'test.out'.



Below is a simple solution in the 'C' programming language. Note the use of 'exit (0);', which is usually required to exit properly. /*ID: your_id_hereLANG: CTASK: test*/#include <stdio.h>main () { FILE *fin = fopen ("test.in", "r"); FILE *fout = fopen ("test.out", "w"); int a, b; fscanf (fin, "%d %d", &a, &b); /* the two input integers */ fprintf (fout, "%d\n", a+b); exit (0);}






Below is a simple solution in the C++ programming language. Note the use of 'return (0);', which is usually required to exit properly. /*ID: your_id_herePROG: testLANG: C++*/#include <iostream>#include <fstream>#include <string>using namespace std;int main() { ofstream fout ("test.out"); ifstream fin ("test.in"); int a, b; fin >> a >> b; fout << a+b << endl; return 0;}






Below is a simple solution in the PASCAL programming language: {ID: your_id_herePROG: testLANG: PASCAL}Program Test;Var fin, fout: text; a, b: word;Begin Assign(fin, 'test.in'); Reset(fin); Assign(fout, 'test.out'); Rewrite(fout); Readln(fin, a, b); Writeln(fout, a+b); Close(fout);End.






And here is the same program, this time in JAVA. Note that the program presumes the file opens will succeed, which they will: /*ID: your_id_hereLANG: JAVATASK: test*/import java.io.*;import java.util.*;class test { public static void main (String [] args) throws IOException { // Use BufferedReader rather than RandomAccessFile; it's much faster BufferedReader f = new BufferedReader(new FileReader("test.in")); // input file name goes above// BufferedWriter out = new BufferedWriter("test.out"); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("twalk.out"))); String s = f.readLine(); // gets entire line int i1 = Integer.parseInt(s.split(" ")[0]); // first piece becomes an integer int i2 = Integer.parseInt(s.split(" ")[1]); // second piece becomes an integer out.write(i1+" "+i2); // output result out.close(); // close the output file System.exit(0); // don't omit this! }}





You can try as many different things (subject to the caveats below) as you like to see how the grading system works. Theoretically, you can't break it or crash it. If you see a problem, please let me know.

The restrictions are few:

One second runtime limit unless other specified (700 MHz Pentium III)
About 16MB datasize limit
About 1MB stacksize limit
Be sure your program exits with status 0
Be sure you print complete lines (with terminating newline), not just a few words or numbers
Don't use files other than the specified input, output, and auxiliary files
Other common sense rules that need not be listed

The rules are simple:

Don't try to cheat.
Don't just print the answers, you must calculate them in your program. If you just print answers, your login ID might be removed.
Don't try to look at other files on the system or use other schemes to break security
Don't try to break common sense rules of privacy
Please report anomalous behavior to me right away (<kolstad@delos.com> (kolstad@ace.delos.com))
Have as much fun as possible
Earn a trip to the IOI and other exotic contests!

Some hints:

Both stderr and stdout are returned to you when errors occur
Feel free to ask questions and send in comments
Your reported output has `_'s substituted for spaces
Include this comment if you use try/catch/throw in C++: /*pragma handle-exceptions*/

Compiler comments (please send in new compiler comments as you find them):

We're using g++ (a.k.a. djgpp on PCs), Free Pascal, and gjc
In C/C++, ints are 32 bits (char is 8; short is 16; long is 32; long long is 64)
some libraries have new names; some have different or missing functions
stricmp doesn't exist; use strcmp for string compares
strrev does not exist
neither itoa nor ltoa exists (use sprintf instead)
No need for huge declarations - pointers already go everywhere
Pascal users: be sure to "close" your output file or the output might not appear








الرجاااااء يكون الكود مرتب بحيث إني أقدر أغيره في حال وجود بعض الأخطاء الطفيفة الناتجة عن تغير الكومبايلر.


والسؤال في الرد التالي على الموضوع....

مبرمج الإمارات
07-02-2006, 04:58 PM
المسألة في المرفقات

طبعا هذا السؤال سهل جدا والغرض منه تجربة إرسال حلولكم للسيرفر لتقييمها...

وإذا اتوفقتوا في هالسؤال... راح أبدأ أعطيكم المسائل الي تبا شغل :black:



أي مشاكل في فهم السؤال... خبروني ولا تستحو....




مع أجمل تحية

sayedco
08-02-2006, 05:18 AM
شوي شوي علينا يا خوك :D

ترا آنا ما أعرف أحدد حجم الستاك و الكيو :sss:

و مثل ما قلتلك آنا مبتدأ تقريباً

و بنشوف المسألة بعد فترة النقاهة ، يمكن بعد ما أحل شي << معذور مبتدأ

مبرمج الإمارات
08-02-2006, 07:10 PM
سايدكو:
لا تخاف ... مسألة الستاك والكيو هذي انساها.... وانسى كل الشروط بعد

انت بس حل السؤال بكود مرتب وحلو... وعطني اياه وأنا برتب لك الكود للموقع :D



في خدمتكم.... بس راوونا همتكم :smart:

WRX
09-02-2006, 04:33 AM
فكرة اكثر من رائعة حبيبي....وان شاء الله راح اكووون معاكم بس اول ما ارجع من السفر


انا قلت لازم اسجل حضوري اول...:p

مبرمج الإمارات
09-02-2006, 11:44 PM
مشكور أخوي wrx على تسجيل حضورك... :)

وفي انتظار عودتك سالما من السفر ... :-)








وبن باقي الأعضااااء :ranting:

مبرمج الإمارات
10-02-2006, 05:26 PM
:sleep: << يبدو أن القسم مهجور !!

xenon
12-02-2006, 07:27 PM
فكرة حلوة يا مبرمج الامارات

ولو اني ما قريت المسألة :D


لكن ان شاء الله باقراها واذا عرفت احلها بارسلك الحل باقرب وقت :cool:

xenon
12-02-2006, 07:56 PM
على فكرة انا احمل الشي الكثير من
الحقد على نظام التصحيح هذا :D (ابو اللغة الي شبكت غلط)

الترم الماضي كان عندي مادة برمجة بالجافا وكان عندنا هومورك
المهم حليت الاسئلة وخلصت منها ووزعتها على الشباب (حركات نشامى :knight: )

طبعا قلتلهم غيرو في الستايل واسماء المتغيرات
واحد الله يصلحه سوى فتك(يعني فاهم) وقام غير تغييرات هبلة وبسيطة

لمن نزلت النتايج اشوف صفر

بعدين عرفت انهم كانوا يستخدموا هذا النظام

xenon
12-02-2006, 09:22 PM
تفضل اخوي مبرمج الامارات هذا كود البرنامج بالجافا

ياليت تحط النتيجة باسرع وقت :eek: :eek:

على فكرة الموقع ايش كان اسمه :think: :D

مبرمج الإمارات
13-02-2006, 08:03 PM
مشكور أخوي زينون على التفاعل... والله يعين سيرفرات التصحيح عليك...

خاصة أن الموقع ( http://ace.delos.com/usacogate/ ) طلع لك هالمشاكل في البرنامج :cry1:



1- المشاكل كانت في تسمية ملفات الإدخال والإخراج..ز انت كنت مسونهم ride.in.txt والمفروض يكون ride.in وبسس
2- كنت حاط علامات ( !! ) زائدة في ملف الإخراج ما أدري ليش حاطهم !!!!



على العموم أنا عدلت هالأخطاء في الكود وكانت النتيجة كالتالي:


TASK: ride
LANG: JAVA

Compiling...
Compile: OK

Executing...
sending data (ride) ride /home/kolstad/trainweb


Test 1 OK [0.226666666666667 secs]
Test 2 OK [0.225333333333333 secs]
Test 3 OK [0.226666666666667 secs]
Test 4 OK [0.226666666666667 secs]
Test 5 OK [0.228 secs]
Test 6 OK [0.225333333333333 secs]
Test 7 OK [0.227333333333333 secs]
Test 8 OK [0.228 secs]
Test 9 OK [0.226 secs]
Test 10 OK [0.229333333333333 secs]

All tests OK.Your program ('ride') produced all correct answers! Congratulations!



Here are the test data inputs:

------- test 1 -------
COMETQ

HVNGAT

------- test 2 -------

STARAB

USACO

------- test 3 -------

EARTH

LEFTB

------- test 4 -------

PULSAR

VENUS

------- test 5 -------

KANSAS


UTAH

------- test 6 -------

APPLE

URSA

------- test 7 -------

MSFT


MARS

------- test 8 -------

PLUTO

BKHOLE


------- test 9 -------
COWSBC


RIGHT
------- test 10 -------

DRKMTR

SNIKER




(( أي مشاكل في فهم النتيجة.. أنا حاضر ))

على فكرة سرعة البرنامج وايد بطيئة...:cry1: ... حاول تعديله :)



يالله يا شباب.. من ينزل برنامج أسرع :eek:

xenon
14-02-2006, 01:13 AM
All tests OK.Your program ('ride') produced all correct answers! Congratulations!
نتيجة حلوة بالنسبة لي :D :D

Test 1 OK [0.226666666666667 secs]
على فكرة سرعة البرنامج وايد بطيئة... ... حاول تعديله
:sss: :sss:

- المشاكل كانت في تسمية ملفات الإدخال والإخراج..ز انت كنت مسونهم ride.in.txt والمفروض يكون ride.in وبسس
2- كنت حاط علامات ( !! ) زائدة في ملف الإخراج ما أدري ليش حاطهم !!!!
بالنسبة للخطأ الاول ضروري اكتب txt بعد اسم الملف والا راح يكون كومبايل ارور
ام الخطأ الثاني تقدر تقول لقافة مني :D

وشكرا لك على مجهودك

مبرمج الإمارات
16-02-2006, 02:33 AM
وداعاً يا سوالف

http://www.swalif.net/sforum1/showthread.php?t=219161