area an input here? Type yes or no.area est-elle une entrée ? Tapez oui ou non.area مدخل هنا؟ اكتب نعم أو لا.yes or no only.oui ou non.نعم أو لا.Input → Process → Output، ورسم تسلسل خطي بسيط، ثم كتابة خطوات C++ بالترتيب الصحيح.By the end of this section, you should be able to read a short problem statement, separate what is given from what is asked, map it to Input → Process → Output, sketch a straight-line flow, and write the matching C++ steps in order.
À la fin de cette section, vous devriez pouvoir lire un court énoncé, séparer ce qui est donné de ce qui est demandé, le transformer en Entrée → Traitement → Sortie, esquisser un flux linéaire, puis écrire les étapes C++ dans le bon ordre.
بنهاية هذا القسم، يجب أن تكون قادراً على قراءة مسألة قصيرة، وفصل ما هو معطى عمّا هو مطلوب، وتحويلها إلى Input → Process → Output، ورسم تسلسل خطي بسيط، ثم كتابة خطوات C++ بالترتيب الصحيح.
Good beginner problem solving starts before syntax. When you see a short statement, slow down and ask three questions in order: What information do I receive? What must I do with it? What result should appear at the end?
For straight-line problems, the workflow is simple and stable:
You are not learning clever tricks in this section. You are learning a reliable habit you can reuse on almost every beginner problem.
Une bonne résolution de problème commence avant la syntaxe. Quand vous voyez un court énoncé, ralentissez et posez trois questions dans l’ordre : quelles informations je reçois ? Que dois-je en faire ? Quel résultat doit apparaître à la fin ?
Pour les problèmes linéaires, la méthode reste simple et stable :
Dans cette section, vous n’apprenez pas une astuce. Vous apprenez une habitude fiable, réutilisable dans presque tous les exercices de débutant.
يبدأ حل المسائل الجيد قبل كتابة الصياغة البرمجية. عندما ترى مسألة قصيرة، تمهّل واسأل ثلاثة أسئلة بالترتيب: ما المعلومات التي أستقبلها؟ ماذا يجب أن أفعل بها؟ ما النتيجة التي يجب أن تظهر في النهاية؟
في المسائل الخطية، تبقى الطريقة بسيطة وثابتة:
Input وProcess وOutputفي هذا القسم أنت لا تتعلم خدعة. أنت تتعلم عادة موثوقة يمكنك إعادة استخدامها في معظم مسائل المبتدئين.
Input وProcess وOutput قبل كتابة الصياغة البرمجية.Before you write variables or operators, rewrite the problem in plain meaning. Separate what is already provided from what must be produced. Then map the statement to IPO: Input, Process, Output.
| Part of the statement | Question to ask | Rectangle example |
|---|---|---|
| Given | What values do I receive first? | length, width |
| Process | What formula or assignment uses those values? | area = length * width |
| Asked / Output | What final value should appear? | area |
The important habit is order. Input happens before Process. Process happens before Output. When your code or flowchart changes that order, the plan is probably wrong.
Avant d’écrire des variables ou des opérateurs, reformulez le problème avec son sens. Séparez ce qui est déjà fourni de ce qui doit être produit. Ensuite, transformez l’énoncé en IPO : Entrée, Traitement, Sortie.
| Partie de l’énoncé | Question à poser | Exemple du rectangle |
|---|---|---|
| Donné | Quelles valeurs je reçois d’abord ? | length, width |
| Traitement | Quelle formule ou affectation utilise ces valeurs ? | area = length * width |
| Demandé / Sortie | Quelle valeur finale doit apparaître ? | area |
L’habitude importante est l’ordre. L’Entrée vient avant le Traitement. Le Traitement vient avant la Sortie. Quand votre code ou votre organigramme change cet ordre, le plan est probablement faux.
قبل أن تكتب المتغيرات أو العوامل، أعد صياغة المسألة بمعناها البسيط. افصل بين ما هو موجود أصلاً وبين ما يجب إنتاجه. بعد ذلك حوّل نص المسألة إلى IPO: Input ثم Process ثم Output.
| جزء من نص المسألة | السؤال الذي تطرحه | مثال المستطيل |
|---|---|---|
| المعطى | ما القيم التي أستقبلها أولاً؟ | length, width |
| المعالجة | ما الصيغة أو التعيين الذي يستخدم هذه القيم؟ | area = length * width |
| المطلوب / المخرج | ما القيمة النهائية التي يجب أن تظهر؟ | area |
العادة الأهم هنا هي الترتيب. تأتي Input قبل Process، وتأتي Process قبل Output. عندما يغيّر الكود أو المخطط هذا الترتيب، فغالباً تكون الخطة غير صحيحة.
Suppose the statement says: read the rectangle length and width, compute the area, then print the area.
Do not start by guessing a cout line. First map the statement:
| Step | Meaning |
|---|---|
| Input | read length, width |
| Process | compute area = length * width |
| Output | print area |
Now the code almost writes itself. Read the two measurements first, compute area second, and print the result last. The plan and the code tell the same story in the same order.
Supposons que l’énoncé dise : lire length et width du rectangle, calculer l’aire, puis afficher l’aire.
Ne commencez pas par deviner une ligne cout. Commencez par traduire l’énoncé :
| Étape | Sens |
|---|---|
| Entrée | lire length, width |
| Traitement | calculer area = length * width |
| Sortie | afficher area |
Ensuite, le code s’écrit presque tout seul. Lisez d’abord les deux mesures, calculez area ensuite, puis affichez le résultat en dernier. Le plan et le code racontent la même chose dans le même ordre.
افترض أن نص المسألة يقول: اقرأ length وwidth للمستطيل، ثم احسب المساحة، ثم اطبع المساحة.
لا تبدأ بتخمين سطر cout. ابدأ أولاً بتحويل النص:
| الخطوة | المعنى |
|---|---|
Input |
اقرأ length, width |
Process |
احسب area = length * width |
Output |
اطبع area |
بعد ذلك يكاد الكود أن يكتب نفسه. اقرأ القياسين أولاً، ثم احسب area، ثم اطبع النتيجة أخيراً. الخطة والكود يرويان القصة نفسها وبالترتيب نفسه.
When you feel lost, return to the IPO map. If you cannot point to one Input step, one Process step, and one Output step, do not write more syntax yet.
Quand vous vous sentez perdu, revenez à la carte IPO. Si vous ne pouvez pas montrer une étape d’Entrée, une de Traitement et une de Sortie, n’écrivez pas encore plus de syntaxe.
عندما تشعر بالضياع، ارجع إلى خريطة IPO. إذا لم تستطع الإشارة إلى خطوة Input واحدة وخطوة Process واحدة وخطوة Output واحدة، فلا تكتب مزيداً من الصياغة البرمجية بعد.
These questions keep the answer shape narrow on purpose. Focus on identifying one role at a time: input, process, or output.
Ces questions gardent volontairement une forme de réponse étroite. Concentrez-vous sur un seul rôle à la fois : entrée, traitement ou sortie.
هذه الأسئلة تضيق شكل الإجابة عمداً. ركّز في كل مرة على دور واحد فقط: Input أو Process أو Output.
area an input here? Type yes or no.area est-elle une entrée ? Tapez oui ou non.area مدخل هنا؟ اكتب نعم أو لا.yes or no only.oui ou non.نعم أو لا.length then width.length puis width.length ثم width.area =.area =.area =.Some beginner problems need more than one process step. In that case, the safest approach is to name each intermediate value clearly and keep the assignments in the same order as the plan.
| Problem sentence | Good variable name | Why it helps |
|---|---|---|
| total number of seconds | totalSeconds |
reminds you this is the original input |
| number of full minutes | minutes |
tells you this is one computed result |
| leftover seconds | seconds |
shows this is the remainder after minutes are removed |
Process boxes in a flowchart correspond to assignments in code. If the second process step needs the original input, keep that input available. If the second step needs the first result, make sure the first assignment happens before it.
Certains problèmes de débutant demandent plus d’une étape de traitement. Dans ce cas, l’approche la plus sûre consiste à nommer clairement chaque valeur intermédiaire et à garder les affectations dans le même ordre que le plan.
| Phrase du problème | Bon nom de variable | Pourquoi c’est utile |
|---|---|---|
| nombre total de secondes | totalSeconds |
rappelle qu’il s’agit de l’entrée d’origine |
| nombre de minutes complètes | minutes |
montre qu’il s’agit d’un premier résultat calculé |
| secondes restantes | seconds |
indique qu’il s’agit du reste après les minutes retirées |
Les boîtes de Traitement d’un organigramme correspondent aux affectations dans le code. Si la deuxième étape a besoin de l’entrée d’origine, gardez cette entrée disponible. Si elle a besoin du premier résultat, assurez-vous que la première affectation se produit avant elle.
تحتاج بعض مسائل المبتدئين إلى أكثر من خطوة معالجة واحدة. في هذه الحالة تكون الطريقة الأكثر أماناً هي تسمية كل قيمة وسيطة بوضوح، ثم الحفاظ على ترتيب التعيينات كما في الخطة.
| جملة من المسألة | اسم متغير جيد | لماذا يساعد |
|---|---|---|
| العدد الكلي للثواني | totalSeconds |
يذكّرك بأن هذه هي قيمة الإدخال الأصلية |
| عدد الدقائق الكاملة | minutes |
يوضّح أن هذه أول نتيجة محسوبة |
| الثواني المتبقية | seconds |
يبيّن أنها الباقي بعد إزالة الدقائق |
تقابل صناديق Process في المخطط التعليمي أسطر التعيين في الكود. إذا كانت الخطوة الثانية تحتاج إلى الإدخال الأصلي فاحتفظ به متاحاً. وإذا كانت تحتاج إلى النتيجة الأولى، فتأكد من أن التعيين الأول يحدث قبلها.
Now the plan has two process steps instead of one. The statement is: read a total number of seconds, compute full minutes, compute leftover seconds, then print both values.
Map it carefully:
| IPO role | Step |
|---|---|
| Input | read totalSeconds |
| Process 1 | minutes = totalSeconds / 60 |
| Process 2 | seconds = totalSeconds % 60 |
| Output | print minutes, then seconds |
Notice that both process steps use the same original input. That is why totalSeconds stays unchanged after reading it. Each later line depends on it.
Cette fois, le plan contient deux étapes de traitement au lieu d’une. L’énoncé est : lire un nombre total de secondes, calculer les minutes complètes, calculer les secondes restantes, puis afficher les deux valeurs.
Traduisez-le avec soin :
| Rôle IPO | Étape |
|---|---|
| Entrée | lire totalSeconds |
| Traitement 1 | minutes = totalSeconds / 60 |
| Traitement 2 | seconds = totalSeconds % 60 |
| Sortie | afficher minutes, puis seconds |
Remarquez que les deux étapes de traitement utilisent la même entrée d’origine. C’est pourquoi totalSeconds reste inchangé après la lecture. Chaque ligne suivante en dépend.
الآن تحتوي الخطة على خطوتي معالجة بدلاً من خطوة واحدة. نص المسألة هو: اقرأ العدد الكلي للثواني، واحسب الدقائق الكاملة، ثم احسب الثواني المتبقية، وبعد ذلك اطبع القيمتين.
حوّلها بعناية:
دور IPO |
الخطوة |
|---|---|
Input |
اقرأ totalSeconds |
Process 1 |
minutes = totalSeconds / 60 |
Process 2 |
seconds = totalSeconds % 60 |
Output |
اطبع minutes ثم seconds |
لاحظ أن خطوتي المعالجة كلتيهما تستخدمان الإدخال الأصلي نفسه. لذلك يبقى totalSeconds دون تغيير بعد قراءته. فكل سطر لاحق يعتمد عليه.
When a problem has multiple process lines, keep the data story visible: original input, first computed value, second computed value, final output.
Quand un problème contient plusieurs lignes de traitement, gardez l’histoire des données visible : entrée d’origine, première valeur calculée, seconde valeur calculée, sortie finale.
عندما تحتوي المسألة على عدة أسطر معالجة، أبقِ قصة البيانات واضحة: الإدخال الأصلي، ثم أول قيمة محسوبة، ثم القيمة المحسوبة الثانية، ثم المخرج النهائي.
These exercises show the same IPO idea in two shapes: boxes and code. Keep the step order fixed, and notice whether each slot needs only a variable name or a full assignment.
Ces exercices montrent la même idée IPO sous deux formes : des boîtes et du code. Gardez l’ordre des étapes fixe et remarquez si chaque emplacement attend seulement un nom de variable ou une affectation complète.
تعرض هذه التمارين الفكرة نفسها بصورتين: مرة على شكل مخطط، ومرة على شكل كود. حافظ على ترتيب الخطوات ثابتاً، وانتبه هل المطلوب في كل موضع هو اسم متغير فقط أم سطر تعيين كامل.
temptemptempA swap is the classic example of an order problem. If you overwrite one variable too early, the old value disappears before the second assignment can use it.
| Order | Result |
|---|---|
left = right; then right = left; |
both variables end up the same |
save old left in temp, then overwrite left, then restore into right |
values are truly exchanged |
The key idea is simple: when a later step still needs an old value, save that old value first. A helper variable such as temp is not extra decoration. It protects information from being lost.
Un échange est l’exemple classique d’un problème d’ordre. Si vous écrasez une variable trop tôt, l’ancienne valeur disparaît avant que la seconde affectation puisse l’utiliser.
| Ordre | Résultat |
|---|---|
left = right; puis right = left; |
les deux variables finissent identiques |
sauvegarder l’ancien left dans temp, puis écraser left, puis restaurer dans right |
les valeurs sont réellement échangées |
L’idée clé est simple : lorsqu’une étape plus tardive a encore besoin d’une ancienne valeur, sauvegardez d’abord cette ancienne valeur. Une variable d’aide comme temp n’est pas de la décoration. Elle protège l’information contre la perte.
يُظهر التبديل بوضوح لماذا يهم ترتيب التعيين. فإذا كتبت فوق أحد المتغيرات قبل حفظ قيمته القديمة، فلن تجد هذه القيمة عندما تحتاجها في السطر التالي.
| ما الذي تفعله؟ | ماذا يحدث؟ |
|---|---|
left = right; ثم right = left; |
تصبح القيمتان متماثلتين، لأن القيمة القديمة لـleft ضاعت |
temp = left; ثم left = right; ثم right = temp; |
يتم التبديل فعلاً، لأن القيمة القديمة لـleft بقيت محفوظة داخل temp |
الفكرة الأساسية بسيطة: عندما تكون خطوة لاحقة ما زالت تحتاج إلى قيمة قديمة، احفظ هذه القيمة أولاً. فالمتغير المساعد مثل temp ليس شيئاً إضافياً، بل هو ما يمنع ضياع المعلومة.
To swap safely, read the three assignments as a chain of storage decisions:
temp = left; saves the old left value.left = right; moves the right value into left.right = temp; restores the saved old left value into right.This works because the old value is preserved before anything is overwritten. If you skip the first line, the later lines no longer have access to the original left.
Pour échanger sans erreur, lisez les trois affectations comme une chaîne de décisions de stockage :
temp = left; sauvegarde l’ancienne valeur de gauche.left = right; déplace la valeur de droite dans left.right = temp; restaure dans right l’ancienne valeur sauvegardée.Cela fonctionne parce que l’ancienne valeur est préservée avant tout écrasement. Si vous sautez la première ligne, les lignes suivantes n’ont plus accès au left d’origine.
لكي ترى فكرة التبديل بوضوح، اقرأ الأسطر الثلاثة كحركات تخزين متتابعة:
temp = left; يحفظ قيمة left القديمة.left = right; ينقل قيمة right إلى left.right = temp; يعيد القيمة القديمة المحفوظة إلى right.ينجح هذا لأننا حفظنا القيمة القديمة قبل أن نكتب فوق أي شيء. إذا حذفت السطر الأول، فلن يبقى أي مكان يحتفظ بقيمة left الأصلية.
The safest way to debug a swap is to trace values line by line. Ask after every assignment: what does each variable hold now?
La façon la plus sûre de vérifier un échange est de tracer les valeurs ligne par ligne. Après chaque affectation, demandez-vous : que contient chaque variable maintenant ?
أفضل طريقة لتصحيح التبديل هي تتبّع القيم سطراً بسطر. بعد كل تعيين، اسأل نفسك: ماذا يحمل كل متغير الآن؟
These questions connect directly to the previous block: the swap works only because the assignments happen in the right order. Read one line, update the stored values, then move to the next line.
Ces questions prolongent directement le bloc précédent : l’échange fonctionne seulement parce que les affectations arrivent dans le bon ordre. Lisez une ligne, mettez à jour les valeurs stockées, puis passez à la suivante.
ترتبط هذه الأسئلة مباشرة بالفقرة السابقة: ينجح التبديل فقط لأن التعيينات تأتي بالترتيب الصحيح. اقرأ سطراً واحداً، وحدّث القيم المخزنة، ثم انتقل إلى السطر التالي.
right keep the original value of left? Type yes or no.right garde-t-il la valeur d'origine de left ? Tapez oui ou non.right بالقيمة الأصلية لـleft؟ اكتب نعم أو لا.yes or no only.oui ou non.نعم أو لا.2 means the state after line 2, and rows 3, 4, and 5 mean the state after those code lines. Fill only the left and temp cells.2 représente l'état après la ligne 2 du code, et les lignes 3, 4 et 5 représentent l'état après ces lignes. Remplissez seulement les cellules left et temp.2 الحالة بعد السطر 2 من الكود، وتمثل الأسطر 3 و4 و5 الحالة بعد تلك الأسطر. املأ خلايا left وtemp فقط.| StepÉtapeالسطر | leftleftleft | rightrightright | temptemptemp |
|---|---|---|---|
| 2 | 7 | ||
| 3 | 7 | ||
| 4 | 7 | ||
| 5 | 3 |
Straight-line problem solving becomes easier when you keep one stable workflow: read the statement, separate given from asked, map IPO, then write the steps in the same order. If a later assignment still needs an older value, save that value before you overwrite it.
La résolution linéaire devient plus simple quand vous gardez une seule méthode stable : lire l’énoncé, séparer le donné du demandé, construire l’IPO, puis écrire les étapes dans le même ordre. Si une affectation plus tardive a encore besoin d’une ancienne valeur, sauvegardez cette valeur avant de l’écraser.
يصبح حل المسائل الخطية أسهل عندما تحافظ على طريقة ثابتة واحدة: اقرأ نص المسألة، وافصل بين المعطى والمطلوب، وابنِ خريطة IPO، ثم اكتب الخطوات بالترتيب نفسه. وإذا كانت خطوة لاحقة ما زالت تحتاج إلى قيمة أقدم، فاحفظ تلك القيمة قبل أن تكتب فوقها.
IPO وفي مخططها.temp.Quand une affectation risque d'écraser une valeur encore utile, sauvegardez-la d'abord dans temp.عندما يكون التعيين سيكتب فوق قيمة ما زلت تحتاجها، احفظها أولاً في temp.