الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

تصحيح كود ( تحديد اللغة ) language Recognizer

بدأه طالبة مجتهدة 2012 في 8 نوفمبر 2012 · 8 رد · 1,044 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم و رحمة الله

عندي لمشروع مادة الداتا ستركشر المطلوب عمل هذا البرنامج

CDE15753.jpg

و هذا الكود للبرنامج اششتغل تمام كل المطلوب ما عادا اخر مطلوب من السؤال

اللي هوا مقارنة حروف اللغة المدخلة مع حروف الكلمة المدخلة

هذا الكود

import java.util.Scanner;

import java.io.*;
public class Class1
{
 int top=-1;
 char stack[]=new char[10];

 public static void push(Class1 s , char a)
 {
   s.top++;
   s.stack[s.top]=a;
  }
 public static char pop(Class1 s)
 {
  char a;
  a=s.stack[s.top];
  s.top--;
  return (a);
  }
 public static void main (String[]args) throws Exception
 {
  Class1 s1=new Class1();
  Class1 s2=new Class1();
  Class1 s3=new Class1();
  Scanner input =new Scanner(System.in);
  char z;
  int a,a1,n,r=0;
  char ch,ch1,ch2;
    System.out.println("========================================================================= ");  
System.out.println("Enter 10 letters for the language , , , WITHOUT SPACES BETWEEN THE LETTERS");  
for(int i=0;i<10;i++)
  {
   ch=(char) System.in.read();
   s1.push(s1,ch);
  }
  System.out.println("========================================================================= ");
System.out.println("The valid characters of your language are:");  
for(int i=1;i<=10;i++)
  {
   System.out.print(i);  
    System.out.print(") ");  
   System.out.println( s1.pop(s1));  

 }
  System.out.println("========================================================================= ");
System.out.println("Enter the number of the letters of the word you want to check");  
	n=input.nextInt();
ch=(char)System.in.read();
  n=n-10;
System.out.println("========================================================================= ");
System.out.println("Enter the word you need to check");  
for(int i=0;i<10;i++)
  {
   ch=(char) System.in.read();
   s2.push(s2,ch);
  }
 for(int i=0;i<n;i++)
 {
   ch1=s2.pop(s2);
   for(int j=0;j<n;j++)
   {
     ch2=s1.pop(s1);
     if(ch1==ch2)
       r++;
    s3.push(s3,ch2);
   }
  }
 if(r==n)
 {
   System.out.println("========================================================================= ");
  System.out.println("The word is part of the language");
  }
 else
 {
   System.out.println("========================================================================= ");
  System.out.println("The word is not a part of the langauge");
  }
}
}

و هذا الاوت بوت

المشكلة محددة بالخط الاحمر

لما ادخلت حروف من ضمن اللغة اللي ادخلتها يطلع انه not a part

ZKD16353.jpg
#2

لنبدأ بمنطق البرنامج وقبل كل شيئ وقبل الاجابه على سؤالك ، اريد معرفة لماذا هناك داله pop تاخذ معامل؟ في العادة الداله pop لا تاخذ اي معاملات

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#3

بعد اذن الأخ الغالي mental-driller

... بخصوص مشكلة Not a part ، أليس من البديهي أن تظهر هاي المشكلة ؟؟ من خلال قراءتي للكود لم أجد أي String Vector او أي شي يدل على تخزين الكلمات ، أضف على ذلك أننا لا نعرف ماهي اللغات المطلوبة والمستعملة 'هل الانجليزية ، العربية ، الفرنسية ؟؟' على ما أعتقد انها ستكون قاعدة بيانات كبيرة لو أردتي ادخال كلمات اللغات الثلاثة 'الحالة العامة' أما في حالتك أنت فيقتصر الامر على 10 حروف فقط

الجدير بالذكر ان مشكلتك متعلقة بالـ NLP او ما يسمى بــ "معالجة اللغات الطبيعية Natural Language Processing" وهو أحد فروع الذكاء الاصطناعي :happy:

طلب : أريد أن أرى كل تمارين الصفحة من فضلك 'من البداية الى النهاية'

شكرا :)

1

556891961.gif

I am learning from you

it is the programmer eye

#4
اقتباس
لماذا هناك داله pop تاخذ معامل؟

لانه عندنا 3 ستاك بالكود ة

حددت له في اي ستاك راح يعمل بوش و اي ستاك يعمل بوب

خطأ كدا ؟؟

----------------------------

مشروع المادة مطلوب بس هذا البرنامج

و هذي المواضيع الثانية للمشاريع

https://www.dropbox.com/s/zxm6138zpbvry83/20120905_192742.jpg?m

و

https://www.dropbox.com/s/9z1eqlbit2fw7a2/20120905_192753.jpg?m

1
#5

شكرا كثيييييييير :)

556891961.gif

I am learning from you

it is the programmer eye

#6

الا يمكنك عمل التالي

s1.pop();
s2.pop();
s3.pop();

بحيث تعرفي الفئه Stack وتكون الداله pop و push ضمن هذه الفئه. أما استخدام pop كداله ستاتيكيه يعيد للاذهان الــ Procedural Programming و هذا غير مستحسن في لغة كائنية التوجيه مثل جافا.

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#7

هذا تعديل بسيط على كودك، قمت باجراء بعض العمليات الجراحيه للكود. لست متاكدا من الكود يعمل في كل الحالات ولكن جربته على بعض الحالات وعمل بشكل جيد. طبعا لازال الكود يحتاج الى المزيد من التنقيح.

import java.util.Scanner;

class Stack {

    private int top = -1;
    private char stack[] = new char[10];

    public void push(char a) {
        stack[++top] = a;
    }

    public char pop() {
        return (char) stack[top--];
    }

    public void refill() {
        top = stack.length - 1;
    }

    public void reset() {
        top = -1;
    }
}

public class Class1 {

    public static void main(String[] args) throws Exception {
        Stack s1 = new Stack();
        Stack s2 = new Stack();
        Stack s3 = new Stack();

        boolean isPartOf = false;

        Scanner input = new Scanner(System.in);
        int n, r = 0;
        char ch, ch1, ch2;

        System.out.println("========================================================================= ");
        System.out.println("Enter 10 letters for the language , , , WITHOUT SPACES BETWEEN THE LETTERS");

        for (int i = 0; i < 10; i++) {
            ch = (char) System.in.read();
            s1.push(ch);
        }

        System.out.println("========================================================================= ");
        System.out.println("The valid characters of your language are:");

        for (int i = 0; i < 10; i++) {
            System.out.print(i + 1);
            System.out.print(") ");
        }

        System.out.println("========================================================================= ");
        System.out.println("Enter the number of the letters of the word you want to check");

        n = input.nextInt();

        System.out.println("========================================================================= ");
        System.out.println("Enter the word you need to check");

        for (int i = 0; i < n; i++) {
            ch = (char) System.in.read();
            s2.push(ch);
        }
        for (int i = 0; i < n; i++) {
            ch1 = s2.pop();
            s1.refill();
            for (int j = 0; j < 10; j++) {
                ch2 = s1.pop();
                if (ch1 == ch2) {
                    isPartOf = true;
                    r++;
                    s3.push(ch2);
                    System.out.println("ch2 = " + ch2);
                } else if (isPartOf) {
                    isPartOf = false;
                    break;
                }
            }
        }
        if (isPartOf) {
            System.out.println("========================================================================= ");
            System.out.println("The word is part of the language");
        } else {
            System.out.println("========================================================================= ");
            System.out.println("The word is not a part of the langauge");
        }
    }
}
1

No intellectual battle was ever won through retreat
You do not watch Gintama? Dude, you are missing a lot!


صورةmsrgb1485.gif ocajavase7programmerclr.gif

#8

شكراااااُ على تعديل الكود

جزاكم الله خير

#9

هذا الكود بعد اخر تعديل

.

import java.util.Scanner;

class Stack {

    private int top = -1;
    private char stack[] = new char[10];

    public void push(char a) {
        stack[++top] = a;
    }

    public char pop() {
        return (char) stack[top--];
    }

    public void refill() {
        top = stack.length - 1;
    }

    public void reset() {
        top = -1;
    }
}

public class Class1 {

    public static void main(String[] args) throws Exception {
        Stack s1 = new Stack();
        Stack s2 = new Stack();
        Stack s3 = new Stack();

        boolean isPartOf = false;

        Scanner input = new Scanner(System.in);
        int n, r = 0;
        char ch, ch1, ch2;

        System.out.println("========================================================================= ");
        System.out.println("Enter 10 letters for the language , , , WITHOUT SPACES BETWEEN THE LETTERS");

        for (int i = 0; i < 10; i++) 
        {	
            ch = (char) System.in.read();
            s1.push(ch);
        }


        System.out.println("========================================================================= ");
        System.out.println("The valid characters of your language are:");

        for (int i = 0; i < 10; i++) {
            System.out.print(i + 1);
            System.out.println(") ");
        }

        System.out.println("========================================================================= ");
        System.out.println("Enter the number of the letters of the word you want to check");

        n = input.nextInt();

        System.out.println("========================================================================= ");
        System.out.println("Enter the word you need to check");

        for (int i = 0; i < n; i++) {
            ch = (char) System.in.read();
            s2.push(ch);
        }
        for (int i = 0; i < n; i++) {
            ch1 = s2.pop();
            s1.refill();
            for (int j = 0; j < 10; j++) {
                ch2 = s1.pop();
                if (ch1 == ch2) {
                    isPartOf = true;
                    r++;
                    s3.push(ch2);
                    System.out.println("ch2 = " + ch2);
                } else if (isPartOf) {
                    isPartOf = false;
                    break;
                }
            }
        }
        if (isPartOf) {
            System.out.println("========================================================================= ");
            System.out.println("The word is part of the language\n");
        } else {
            System.out.println("========================================================================= ");
            System.out.println("The word is not a part of the langauge\n");
        }
    }
}

للاسف لا يعمل بكل الحالات :(

v4d80495.jpg

مواضيع مشابهة