|
|
נו אחי..מתי השאלה הבאה ?
מצטער, עיקוב קל.
שאלה הבאה:
כתוב תוכנית הקולטת למערך דו מימדי ערכים אך ורק לאלכסונים ואת שאר המקומות משאירה ריקים, מציגה אותו כך (בלי סימני השאלה כמובן, וערכים כרצונכם):
[5][?][1]
[?][8][?]
[0][?][9]
לאחר מכן, התוכנית מאפסת את המערך, וקולטת ערכים אך ורק למקומות שלא נמצאים באלכסונים ומציגה אותו שוב.
נערך לאחרונה על ידי B1ackSn0w; 28-09-2008 בשעה 18:08.
תכירו את שמוליק, אבא קנה לי
הוא אוהב במבה, ביסלי ואת עודד מנשה
נכתב במקור על ידי אושרי
הנה פתרתי:
*תיקון:
קוד:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { classProgram { staticvoid Main(string[] args) { int[,] a = new int[3, 3]; for (int i = 0; i < a.GetLength(0); i++) a[i, i] = int.Parse(Console.ReadLine()); for (int i = 0; i < a.GetLength(0); i++) if (i != a.GetLength(0) / 2|| a.GetLength(0)%2==0) a[i, a.GetLength(0) - 1 - i] = int.Parse(Console.ReadLine()); for (int i = 0; i < a.GetLength(0); i++) { for (int k = 0; k < a.GetLength(1); k++) Console.Write("[" + a[i, k] + "]"); Console.WriteLine(); } for (int i = 0; i < a.GetLength(0); i++) for (int k = 0; k < a.GetLength(0); k++) if (i != k && i + k != a.GetLength(0) - 1) a[i, k] = int.Parse(Console.ReadLine()); for (int i = 0; i < a.GetLength(0); i++) { for (int k = 0; k < a.GetLength(1); k++) Console.Write("[" + a[i, k] + "]"); Console.WriteLine(); } } } }
נערך לאחרונה על ידי C4pSLock; 01-10-2008 בשעה 15:16.
לא הבנתי בדיוק מתי הוא עושה את הבדיקה אז כתבתי שתי תוכניות.
תוכנית א'-בודק אחרי כל מספר שהוכנס אם הוא גדול ב3 מקודמו:
תוכנית ב'-גודל מערך מוגדר מראש והבדיקה נעשית אחרי שכל המספרים הוכנסו:קוד:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { classProgram { staticvoid Main(string[] args) { int[] a = newint[1]; a[0]=int.Parse(Console.ReadLine()); while (a[a.Length - 1] != 0) { Array.Resize(ref a, a.Length + 1); a[a.Length - 1] = int.Parse(Console.ReadLine()); if (a[a.Length - 2] + 3 == a[a.Length - 1]) Console.WriteLine("True"); } } } }
קוד:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { classProgram { staticvoid Main(string[] args) { int[] a = newint[5]; for (int i = 0; i < a.Length;i++ ) a[i] = int.Parse(Console.ReadLine()); int k = 1; for (; k < a.Length && a[k-1] + 3 == a[k]; k++) ; if (k == a.Length) Console.WriteLine("True"); else Console.WriteLine("False"); } } }
שאלה הבאה:
השלם, 2 נק':
חוקי האתגר משתנים!קוד:_ o _ _ i _ _ _
הראשון שיגיע ל- 7 נק' ינצח, לא 10!
נערך לאחרונה על ידי B1ackSn0w; 02-10-2008 בשעה 20:57.
תכירו את שמוליק, אבא קנה לי
הוא אוהב במבה, ביסלי ואת עודד מנשה
נכתב במקור על ידי אושרי
לי לא עולה כלום בראש..
תוסיף רמז מתי שתראה לנכון...
זה ייתן את התשובה:
קוד:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { classProgram { staticvoid Main(string[] args) { for (char i = 'a'; i <= 'z'; i++) { for (char k = 'a'; k <= 'z'; k++) { for (char j = 'a'; j <= 'z'; j++) { for (char h = 'a'; h <= 'z'; h++) { for (char g = 'a'; g <= 'z'; g++) { for (char f = 'a'; f <= 'z'; f++) { Console.WriteLine(i + "o" + k + j + "i" + h + g + f); } } } } } } } } }