Close
Faqja 0 prej 2 FillimFillim 12 FunditFundit
Duke shfaqur rezultatin -9 deri 0 prej 14
  1. #1
    Analog Brain Maska e josif
    Anėtarėsuar
    26-02-2004
    Vendndodhja
    madagaskar
    Postime
    245

    Sfida : Algjebra E Pohimeve

    Problemi:

    Ne kete sfide jane te ftuar te gjithe admiruesit e informatikes te implementojne nje program i cili vlereson nje shprehje ne algjebren e pohimeve dhe kthen tabelen e vertetesise .

    --------------------------------------------------------------------------
    Operatoret e vlefshem jane

    AND (dhe)-> "a AND b",(qe do te shkruhet shkurt a & b)
    OR (ose) -> "a OR b",(qe do te shkruhet shkurt a | b)
    NOT (jo) -> "NOT a",(qe do te shkruhet shkurt -a)
    EQUAL(baraz)-> "a EQUAL b" (qe do te shkruhet shkurt a = b)
    IMPLY(nese ... atehere) -> "a IMPLIES b" (qe do te shkruhet shkurt a > b)

    Operatoret kane keto veti:

    Kodi:
     a   b   -a    a & b   a | b         a = b       a > b
     
     0   0    1     0         0          1          1
     0   1    1     0         1          0          0
     1   0    0     0         1          0          1
     1   1    0     1         1          1          1
    ------------------------------------------------------------------------------


    Per me teper ndiqni shembullin e meposhtem:

    Inputi:
    -(a | b) = ( -b & c)

    Outputi:

    a b c Rezultati

    0 0 0 0
    0 0 1 1
    0 1 0 1
    0 1 1 1
    1 0 0 1
    1 0 1 0
    1 1 0 1
    1 1 1 1


    Shenim :
    1. Ne implementimin tim cdo shprehje perfshihet ne kllapa per arsye lehtesimi.
    2. Programi duhet te zgjidhe edhe shprehje "pambarimisht" te gjata !
    Ndryshuar pėr herė tė fundit nga edspace : 14-03-2005 mė 13:27
    He walks among us, but He is not one of us ...

  2. #2
    Programues Softueresh Maska e edspace
    Anėtarėsuar
    04-04-2002
    Vendndodhja
    Filadelfia, SHBA
    Postime
    2,565
    Goxha sfidė ke formuluar Josif.

    Do ishte mirė te jepje disa shėmbuj mė shumė pėr pėrdorimin e saktė tė kllapave.
    (a & b ) | (c & d) apo.... ((a & b ) | (c & d))

    Ka kufizim pėr numrin e variablave qė mund tė ketė njė shprehje?
    Po tė kem kohė, mbase bėj diēka. Po nuk shkruajta programin tim, do bėj patjetėr komente pėr programin tėnd. Testoje mirė se nuk ka mėshirė nė forumin e programimit
    Edi

  3. #3
    Analog Brain Maska e josif
    Anėtarėsuar
    26-02-2004
    Vendndodhja
    madagaskar
    Postime
    245
    *) Perdorimi i kllapat eshte i lire, por per mua ka rendesi qe te punoje me kllapa.
    Nese punon ne te dyja nuk ka problem.
    *) Mund te kete "pambarimisht shume variabla" :-)

    ----------------------
    Per efekt te te qenurit perfekt, zgjidhja qe kam rreth ketij problemi eshte nje zgjidhje e nje eksperti te nivelit shume shume te larte, ish mesuesit tim te "C programming":

    Dr. Gokturk U.
    MET University. Ankara, Turkey
    (ex-chairman of the International Olimpiad in Informatics)
    -----------------------

    Per arsye diskutimi do ta paraqes me vone. Do te mundohet te paraqis edhe nje zgjidhjen time.

    Ps: Kjo ka qene nje detyre zyrtare ne simestrin "Spring 2003-2004". Detyra qe dorezove atehere i kalonte 300 rreshtat dhe kishte pak elegance,gjithsesi ishte funksionale dhe u vleresua me noten 85/100.
    Ndryshuar pėr herė tė fundit nga josif : 16-03-2005 mė 13:08
    He walks among us, but He is not one of us ...

  4. #4
    i/e regjistruar
    Anėtarėsuar
    10-09-2004
    Postime
    2,389
    Interesante kjo, Josif.

    Mbase do jete shume e veshtire, por qe ja vlen te merresh me te, ja vlen.

    Megjithese s'me ngjan nga ato qe u behet dermani me Ceng230...

    T'pershndes!

  5. #5
    Analog Brain Maska e josif
    Anėtarėsuar
    26-02-2004
    Vendndodhja
    madagaskar
    Postime
    245
    Hint i rendesishem:

    Kini parasysh se duhet te gjeni vlerat e te gjitha instancave, duke "zevendesuar variablat me vlerat perkatese" ne ate instance !!
    He walks among us, but He is not one of us ...

  6. #6
    Analog Brain Maska e josif
    Anėtarėsuar
    26-02-2004
    Vendndodhja
    madagaskar
    Postime
    245
    Xeno gjithsesi mund te gjesh edhe sfida me te lehta ne:

    http://www.ceng.metu.edu.tr/~ceng140/C_HW_book.pdf
    He walks among us, but He is not one of us ...

  7. #7
    i/e regjistruar
    Anėtarėsuar
    10-09-2004
    Postime
    2,389

    Thumbs up Ok.

    Falemnderit per linkun.

  8. #8
    Analog Brain Maska e josif
    Anėtarėsuar
    26-02-2004
    Vendndodhja
    madagaskar
    Postime
    245
    Ky programi:

    Kodi PHP:

    #include<stdio.h>
    #include<stdlib.h>
    #include<ctype.h>

    #define BUCKET_SIZE 100


    #define NOT_USED(c)         (Characters[c] = -1)
    #define PUT_VALUE(c,x)      (Characters[c] = (x))
    #define GET_VALUE(c)        (Characters[c])
    #define IS_NOT_USED(c)      (Characters[c] == -1)


    char *The_Formula;
    int  Characters[128];

    calculate(operator,left_value,right_value)
    {
      switch (
    operator)
      {
       case 
    '&' : return(left_value && right_value);     break;
       case 
    '|' : return(left_value || right_value);     break;
       case 
    '>' : return(!left_value || right_value);    break;
       case 
    '=' : return(left_value == right_value);     break;
      }
     }

     
    int parse(char *s)     /* consumes the WFPLF, leaves now at the unconsumed character */
     
    {
      
    register int current_char;
      
    int left_value,right_value,operator;

      static 
    char *now;

      if (
    s!=NULLnow s;  /* else now remains as it is => presumably it is a recursive call */
      
    current_char = *now;
      
    now++;   /* immediatelly consume this char:may be further recursive parse() will occur*/
      
    if (islower(current_char))   return GET_VALUE(current_char);
      else
        switch (
    current_char)
        {
         case 
    '-' : return (!parse(NULL));           break;
         case 
    '(' left_value  parse(NULL);
                    
    operator    = *now++;     /* consume the operator */
                    
    right_value parse(NULL);
                    
    now++;     /* consume the ')' */
                    
    return(calculate(operator,left_value,right_value));      break;
        }
     }

     
    char *read_in_WFPLF(void)
     {
      
    int c;
      
    char *formula=NULL;
      
    char *position;
      
    int  counter=0;
      
    long int mem_size_now=0;

      while ((
    c=getchar())!=EOF)
         {
          if (!
    isspace(c))
            { if (!
    counter) { mem_size_now += BUCKET_SIZE;     /* the following statement may change */
                              
    formula = (char *) realloc(formula,mem_size_now); /* content of formula*/
                              
    position formula + (mem_size_now BUCKET_SIZE);
                              
    counter BUCKET_SIZE-1; }
              *
    position c;
              
    position++;
              
    counter--; }
         }
      *
    position 0;
      return 
    formula;
     }

     
    int preprocess_WFPLF(char *s)   /* finds the used letters in WFPLF stores them with 0, returns */
     
    {                               /* count of letters */
      
    int i;

     
    int letter_count=0;

      for(
    i='a'i<='z'i++) NOT_USED(i);
      for (; *
    ss++) if (islower(*s) && IS_NOT_USED(*s))
                        { 
    PUT_VALUE(*s,0);
                          
    letter_count++; }
      return 
    letter_count;
     }

     
    void set_instance(long int n,int letter_count)
     {
      
    int i='z';

      for (; 
    letter_countletter_count--, >>=1)                   /* >> can be subst. by (/2) */
         
    { for(; IS_NOT_USED(i); i--);            /* Find next used character */
           
    PUT_VALUE(i,n&1); //  printf("[%c:%d]",i,n&1);
           
    i--; }                                 /* we have used this character */
     
    }

     
    void print_heading()
     {
      
    int i;
      for (
    i='a'i<='z'i++) if (!IS_NOT_USED(i)) printf("%c ",i);
      
    printf("R\n");
     }

     
    void print_truth_value(int i)
     {
       
    printf("%c ",  'T' 'F');
     }

     
    void print_instance()
     {
      
    int i;
      for (
    i='a'i<='z'i++) if (!IS_NOT_USED(i)) print_truth_value(GET_VALUE(i));
     }

     
    main(void)
     {
      
    int letter_count;
      
    long int instance;

      
    The_Formula read_in_WFPLF();
       
    letter_count preprocess_WFPLF(The_Formula);
     
    // For debug:                   printf("%s  << contains %d vars\n",The_Formula,letter_count);
      
    print_heading();
      for (
    instance = (1<<letter_count)-1;  instance >= 0;  instance--) /* << can be subst. by (2*) */
         
    set_instance(instance,letter_count);
     
    // For debug:                   printf("%ld.",instance);
           
    print_instance();
           
    print_truth_value(parse(The_Formula));
           
    printf("\n"); }
      return(
    0);
     } 
    He walks among us, but He is not one of us ...

  9. #9
    mos e luaj; I DEBUAR! Maska e qoska
    Anėtarėsuar
    17-05-2004
    Vendndodhja
    tirane
    Postime
    837
    e para tregohu i sinqerte thuaj qe nuk eshte e shkruar nga ty
    Pastaj kaq budallenj i di njerezit qe se kuptojne kur ndryshon stili i te shkruarit nga nje program ne tjetrin

  10. #10
    Programues Softueresh Maska e edspace
    Anėtarėsuar
    04-04-2002
    Vendndodhja
    Filadelfia, SHBA
    Postime
    2,565
    Kodi tėnd apo i profesorit ėshtė ai mė lart?

    Nėse ėshtė kodi i profesorit, tė paskam kritikuar kot se fajin e paska profesori. Thuaji tė vejė prapė nė shkollė se ėshtė turp tė shkruaj kod si ai mė lart. Mbase punon shkėlqyer por ėshtė kod i papranueshėm pėr mėsimdhėnie.
    Edi

Faqja 0 prej 2 FillimFillim 12 FunditFundit

Regullat e Postimit

  • Ju nuk mund tė hapni tema tė reja.
  • Ju nuk mund tė postoni nė tema.
  • Ju nuk mund tė bashkėngjitni skedarė.
  • Ju nuk mund tė ndryshoni postimet tuaja.
  •