Results 1 to 2 of 2

Thread:

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Jan:2012
    Location: Nowhere
    Posts: 1

    Exclamation

    . C/C++, , Send Report. crash-. . :

    , :
    ;
    ;
    ;
    ;
    .


    :
    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <conio.h>
    #include <windows.h>
    #include <dos.h>
    
    using namespace std;
    string line;
    char lineouttofile[1000];
    int brtz = 0;
    HANDLE hConsole;
    char **Mas; // Masiv
    int ReadFile ()
    {
           char imefile[10];
           cout<< "Ime na fail: ";
           cin >> imefile;
           ifstream myfile (imefile);
           if (myfile.is_open())
           {
                   while (! myfile.eof() )
                           {
                                   getline (myfile,line);
                                   cout << line << endl;
                           }
                   myfile.close();
           }
           else cout << "Unable to open file" << endl;
           return 0;
    }
    int WriteFile ()
    {
           int ii = 0;
           for (unsigned int i = 0; i<line.length()-3; i+=4)
           {
                   lineouttofile[i] = Mas[ii][0];
                   lineouttofile[i+1] = Mas[ii][1];
                   lineouttofile[i+2] = Mas[ii][2];
                   lineouttofile[i+3] = ';';
                   ii++;
           }
           ofstream myfile ("example.txt");
           if (myfile.is_open())
           {
                   myfile << lineouttofile;
                   myfile.close();
           }
           else cout << "Failyt ne moje da se otvori." << endl;
           return 0;
    }
    void GetText2Masiv ()
    {
           int textlen = line.length();
           for (int i = 0; i < textlen; i++)
           {
                   if (line[i] == ';')
                   brtz++;
           }
           //Sazdava nov masiv
           Mas = new char *[brtz];
           if (! Mas) {
                   printf("Greshka! Nqma dostatachno pamet!\n");
                   return;
           }
           for (int i=0; i < brtz; i++)
           {
                   Mas[i] = new char [3];
                   if (! Mas[i])
                   {
                           printf("Greshka! Nqma dostatachno pamet!\n");
                           return;
                   }
           }
           int k=0;
           for (int i = 0; i < brtz; i++)
           {
                   Mas[i][0] = line[k];
                   Mas[i][1] = line[k+1];
                   Mas[i][2] = line[k+2];
                   k+=4;
           }
    }
    void ShowMasiv()
    {
           for (int i = 0; i < brtz; i++)
           {
                   cout << i+1 << "- ";
                   for (int j=0;j<3;j++)
                   cout << Mas[i][j];
                   cout << endl;
           }
    }
    void IsEqual()
    {
           int pyrvatr;
           int vtoratr;
           cout << "Izberete 2 troiki za sravnenie " <<endl;
           cout << "Izberete pyrvata troika (neiniat nomer)";
           cin >> pyrvatr;
           pyrvatr = pyrvatr--;
           cout << "Izberete vtorata troika (neiniat nomer)";
           cin >> vtoratr;
           vtoratr = vtoratr--;
           if ((Mas[pyrvatr][0] != Mas[vtoratr][0]) || (Mas[pyrvatr][1] != Mas[vtoratr][1]) || (Mas[pyrvatr][2] != Mas[vtoratr][2]))
                   cout << "Dvoikite ne sa ravni" <<endl;
           if ((Mas[pyrvatr][0] == Mas[vtoratr][0]) && (Mas[pyrvatr][1] == Mas[vtoratr][1]) && (Mas[pyrvatr][2] == Mas[vtoratr][2]))
                   cout << "Dvoikite sa ravni" <<endl;
    }
    void FindTroika()
    {
           hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
           char tyrs[10];
           cout << "Vavedete troika za tyrsene " <<endl;
           cin >> tyrs;
           if (strlen(tyrs) > 3)
           {
                   cout << "Vyvedete maksimum 3 simvola "<<endl;
                   exit(0);
           }
           bool found = false;
           for (int i = 0; i < brtz; i++)
           {
                   if ((Mas[i][0] == tyrs[0]) && (Mas[i][1] == tyrs[1]) && (Mas[i][2] == tyrs[2]))
           {
           found = true;
           SetConsoleTextAttribute(hConsole, 3);
           cout << Mas[i][0] << Mas[i][1] << Mas[i][2] << endl;
           Sleep(500);
           }
                   else
                   {
                           SetConsoleTextAttribute(hConsole, 6);
                           cout << Mas[i][0] << Mas[i][1] << Mas[i][2] << endl;
                           Sleep(500);
                   }
           }
           SetConsoleTextAttribute(hConsole, 7);
           if ( found )
           cout << "Namerena e troikata, koiato tyrsite "<<endl;
           else
           cout << "Ne e namerena e troikata, koiato tyrsite " <<endl;
    }
    void SortTroika ()
    {
           hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
           system("cls");
           int color = 3;
           int elem1;
           int elem2;
           SetConsoleTextAttribute(hConsole, 5);
           ShowMasiv();
           cout << endl;
           char temp[3];
           for (int i = brtz; i >= 0; i--)
           {
                   for (int j = 0; j < i-1; j++)
                   {
                           if ( int(Mas[j][0]) > int(Mas[j+1][0]) )
                                   {
                                           color = 2;
                                           elem1 = j;
                                           elem2 = j+1;
                                           temp[0] = Mas[j][0];
                                           temp[1] = Mas[j][1];
                                           temp[2] = Mas[j][2];
                                           Mas[j][0] = Mas[j+1][0];
                                           Mas[j][1] = Mas[j+1][1];
                                           Mas[j][2] = Mas[j+1][2];
                                           Mas[j+1][0] = temp[0];
                                           Mas[j+1][1] = temp[1];
                                           Mas[j+1][2] = temp[2];
                                           for (int ki = 0; ki < brtz; ki++)
                                           {
                                                   if (ki == elem1 || ki == elem2)
                                                   color = 2;
                                                   else
                                                   color = 3;
                                                   SetConsoleTextAttribute(hConsole, color);
                                                   cout << ki+1 << "- ";
                                                   for (int kj=0; kj<3; kj++)
                                                   cout << Mas[ki][kj];
                                                   cout << endl;
                                           }
                                   }
                           cout << endl;
                           Sleep(1500);
                   }
           }
           SetConsoleTextAttribute(hConsole, 7);
           cout << endl;
    }
    int main ()
    {
           ReadFile ();
           GetText2Masiv ();
           ShowMasiv();
           IsEqual();
           FindTroika();
           SortTroika ();
           ShowMasiv();
           WriteFile();
           for (int is=0; is < brtz; is++)
           delete []Mas[is];
           delete []Mas;
           system("pause");
           return 0;
    }
    asd.txt
    Code:
    1- tje
    2- kuj
    3- sgr
    4- gjg
    5- geq
    6- yjd
    7- bjp
    8- qhv
    9- dwe
    10- hjd
    11- qcf
    , , :

    Code:
    if (Mas[pyrvatr][0] != Mas[vtoratr][0] || Mas[pyrvatr][1] != Mas[vtoratr][1] || Mas[pyrvatr][2] != Mas[vtoratr][2])
    		cout << "Dvoikite ne sa ravni"<<endl;
    	if (Mas[pyrvatr][0] == Mas[vtoratr][0] && Mas[pyrvatr][1] == Mas[vtoratr][1] && Mas[pyrvatr][2] == Mas[vtoratr][2])
    cout << "Dvoikite sa ravni"<<endl;
    "vtoratr" , . , ?

  2. #2
    Deleted User 4eRNoBiL's Avatar
    Join Date: Oct:2005
    Location:
    Posts: 739
    - Mas. .

    , :
    Code:
    if ((Mas[pyrvatr][0] != Mas[vtoratr][0]) || (Mas[pyrvatr][1] != Mas[vtoratr][1]) || (Mas[pyrvatr][2] != Mas[vtoratr][2]))
                   cout << "Dvoikite ne sa ravni" <<endl;
           if ((Mas[pyrvatr][0] == Mas[vtoratr][0]) && (Mas[pyrvatr][1] == Mas[vtoratr][1]) && (Mas[pyrvatr][2] == Mas[vtoratr][2]))
                   cout << "Dvoikite sa ravni" <<endl;
    :
    Code:
    if ((Mas[pyrvatr][0] != Mas[vtoratr][0]) || (Mas[pyrvatr][1] != Mas[vtoratr][1]) || (Mas[pyrvatr][2] != Mas[vtoratr][2]))
    	cout << "Dvoikite ne sa ravni" <<endl;
    else
    	cout << "Dvoikite sa ravni" <<endl;
    , - .

    - - strcmp() ( , ) :
    Code:
    if (!strcmp(Mas[pyrvatr], Mas[vtoratr]))
    	cout << "Dvoikite ne sa ravni" <<endl;
    else
    	cout << "Dvoikite sa ravni" <<endl;

    - .
    Code:
    char **Mas; // Masiv
    Fujistu Lifebook E756 | Core i7-6500U / 400MHz-3.1GHz | 8 GB DDR4-2133 | Samsung PM871 / 256 GB SSD | 15" 1920x1080 | Manjaro Linux + kernel 4.19

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |