Şimdi Ara

C++ ile Harf Matrisi Oluşturma.

Bu Konudaki Kullanıcılar:
2 Misafir (1 Mobil) - 1 Masaüstü1 Mobil
5 sn
5
Cevap
0
Favori
208
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
0 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • Merhabalar


    Harf isimli 5x10 boyutlu elemanları ingilizce bir büyük ve bir küçük olacak şekilde harflerden (A’dan Z’ye ve a’dan z’ye) rasgele oluşan bir matris oluşturmam lazım.



    Resimdeki gibi gözükmesi lazım Harf sadece bir kere kullanılması lazım. Matris 5x10 olması lazım. C++

    C++ ile Harf Matrisi Oluşturma.









  • #include<stdio.h>

    #include<conio.h>

    #include<stdlib.h>

    #include<time.h>


    #define MIN_B 65

    #define MAX_B 90

    #define MIN_S 97

    #define MAX_S 122


    #define ROW 5

    #define COLUMN 10


    int isLetterUsed(char letterchar usedLetters[]) {


        for(int i=0;i<ROW*COLUMN;i++) {

            if(letter == usedLetters[i])

                return 1;

        }


        return 0;

    }


    void fillLetters(char letters[][COLUMN]) {

        char letter = MIN_B;

        char tempLetters[ROW*COLUMN];

        int count = 0;


        while(1) {


            if(count >= ROW*COLUMN)

                break;


            if(count%2 == 0) {

                char letterBig = (rand() % (MAX_B - MIN_B + 1)) + MIN_B;

                if(isLetterUsed(letterBig, tempLetters))

                    continue;

                tempLetters[count] = letterBig;

            }

            else {

                char letterSmall = (rand()%(MAX_S - MIN_S + 1)) + MIN_S;

                if(isLetterUsed(letterSmall, tempLetters))

                    continue;

                tempLetters[count] = letterSmall;

            }


            count++;

        }


        count = 0;


        for(int i=0;i<ROW;i++) {

            for(int j=0;j<COLUMN;j++) {

                letters[i][j] = tempLetters[count++];

            }

        }

    }


    void printLetters(char letters[][COLUMN]) {

        for(int i=0;i<ROW;i++) {

            for(int j=0;j<COLUMN;j++) {

                printf("%c "letters[i][j]);

            }

            printf("\n");

        }

    }


    void sortLetters(char letters[][COLUMN]) {

        char tempLetters[ROW*COLUMN];

        int index = 0;


        for(int i=0;i<ROW;i++) {


            for(int j=0;j<COLUMN;j++) {

                tempLetters[index++] = letters[i][j];

            }

        }

        int small = 0;


        for(int i=0;i<ROW*COLUMN;i++) {

            small = i;

            for(int j=i;j<ROW*COLUMN;j++) {

                if(tempLetters[small] > tempLetters[j])

                    small = j;

            }

            char temp = tempLetters[small];

            tempLetters[small] = tempLetters[i];

            tempLetters[i] = temp;

        }


        index = 0;


        for(int i=0;i<ROW;i++) {

            for(int j=0;j<COLUMN;j++) {

                letters[i][j] = tempLetters[index++];

            }

        }

        

    }


    void main(int argcchar **argv) {

        srand(time(NULL));

        char letters[ROW][COLUMN];


        fillLetters(letters);

        printf("First state : \n");

        printLetters(letters);


        sortLetters(letters);


        printf("Last state : \n");

        printLetters(letters);

    }





  • quote:

    Orijinalden alıntı: Mr.Tiger

    #include<stdio.h>

    #include<conio.h>

    #include<stdlib.h>

    #include<time.h>


    #define MIN_B 65

    #define MAX_B 90

    #define MIN_S 97

    #define MAX_S 122


    #define ROW 5

    #define COLUMN 10


    int isLetterUsed(char letterchar usedLetters[]) {


        for(int i=0;i<ROW*COLUMN;i++) {

            if(letter == usedLetters[i])

                return 1;

        }


        return 0;

    }


    void fillLetters(char letters[][COLUMN]) {

        char letter = MIN_B;

        char tempLetters[ROW*COLUMN];

        int count = 0;


        while(1) {


            if(count >= ROW*COLUMN)

                break;


            if(count%2 == 0) {

                char letterBig = (rand() % (MAX_B - MIN_B + 1)) + MIN_B;

                if(isLetterUsed(letterBig, tempLetters))

                    continue;

                tempLetters[count] = letterBig;

            }

            else {

                char letterSmall = (rand()%(MAX_S - MIN_S + 1)) + MIN_S;

                if(isLetterUsed(letterSmall, tempLetters))

                    continue;

                tempLetters[count] = letterSmall;

            }


            count++;

        }


        count = 0;


        for(int i=0;i<ROW;i++) {

            for(int j=0;j<COLUMN;j++) {

                letters[i][j] = tempLetters[count++];

            }

        }

    }


    void printLetters(char letters[][COLUMN]) {

        for(int i=0;i<ROW;i++) {

            for(int j=0;j<COLUMN;j++) {

                printf("%c "letters[i][j]);

            }

            printf("\n");

        }

    }


    void sortLetters(char letters[][COLUMN]) {

        char tempLetters[ROW*COLUMN];

        int index = 0;


        for(int i=0;i<ROW;i++) {


            for(int j=0;j<COLUMN;j++) {

                tempLetters[index++] = letters[i][j];

            }

        }

        int small = 0;


        for(int i=0;i<ROW*COLUMN;i++) {

            small = i;

            for(int j=i;j<ROW*COLUMN;j++) {

                if(tempLetters[small] > tempLetters[j])

                    small = j;

            }

            char temp = tempLetters[small];

            tempLetters[small] = tempLetters[i];

            tempLetters[i] = temp;

        }


        index = 0;


        for(int i=0;i<ROW;i++) {

            for(int j=0;j<COLUMN;j++) {

                letters[i][j] = tempLetters[index++];

            }

        }

        

    }


    void main(int argcchar **argv) {

        srand(time(NULL));

        char letters[ROW][COLUMN];


        fillLetters(letters);

        printf("First state : \n");

        printLetters(letters);


        sortLetters(letters);


        printf("Last state : \n");

        printLetters(letters);

    }

    Eyvallah Reis C++ az bilgim var ama takılı kalmıştım biryerde teşekkürler yardımcı olduğun içinC++ ile Harf Matrisi Oluşturma. 





  • Emachintag E kullanıcısına yanıt
    Rica ederim. =)

    < Bu ileti Android uygulamasından atıldı >
  • Yapay Zeka’dan İlgili Konular
    Daha Fazla Göster
    
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.