Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstring>
- using namespace std;
- ifstream fin("fisier.txt");
- void subpctA()
- {
- int L = 22;
- char text[10005] = "PROBLEMA DE LA EXAMEN NU MI SE PARE FOARTE GREU DE REZOLVAT IN TIMPUL ACORDAT";
- int litereFolosite = 0; // pe o linie
- char *cuvant = strtok(text, " ");
- while(cuvant)
- {
- if(litereFolosite == 0)
- {
- cout << cuvant << " ";
- litereFolosite = strlen(cuvant) + 1;
- }
- else
- {
- if(litereFolosite + strlen(cuvant) <= L)
- {
- cout << cuvant << " ";
- litereFolosite = litereFolosite + strlen(cuvant) + 1;
- }
- else
- {
- cout << "\n";
- cout << cuvant << " ";
- litereFolosite = strlen(cuvant) + 1;
- }
- }
- cuvant = strtok(NULL, " ");
- }
- }
- void subpctB() {
- int L = 22;
- int N = 4;
- char mat[100][10005];
- int contor = 0;
- for(int i = 0; i < N - 1; i++)
- {
- int linUrm = strlen(mat[i + 1]);
- for(int j = 1; mat[i][j] != '\0'; j++)
- {
- cout << mat[i][j] << " ";
- if(mat[i][j] == ' ')
- {
- if(mat[i + 1][j] == ' ' && j < linUrm)
- {
- contor = 1;
- break;
- }
- if(mat[i + 1][j - 1] == ' ' && j - 1 < linUrm)
- {
- contor = 1;
- break;
- }
- if(mat[i + 1][j + 1] == ' ' && j + 1 < linUrm)
- {
- contor = 1;
- break;
- }
- }
- }
- if(contor != 0)
- break;
- //cout << "\n";
- }
- }
- int rau[100][10005];
- void subpctC() {
- int L = 22;
- int N = 4;
- char mat[100][10005];
- for(int i = 0; i < N; i++)
- {
- fin.getline(mat[i], 10005);
- }
- for(int j = 0; j < strlen(mat[0]); j++)
- if(mat[0][j] == ' ')
- rau[0][j] = 1;
- int rauMax = 0;
- for(int i = 1; i < N; i++)
- {
- for(int j = 0; mat[i][j] != '\0'; j++)
- {
- if(mat[i][j] == ' ')
- {
- int posMax = 0; //posibilitate maxima
- if(rau[i - 1][j - 1] != 0 && rau[i - 1][j - 1] > posMax)
- posMax = rau[i - 1][j - 1];
- if(rau[i - 1][j] != 0 && rau[i - 1][j] > posMax)
- posMax = rau[i - 1][j];
- if(rau[i - 1][j + 1] != 0 && rau[i - 1][j + 1] > posMax)
- posMax = rau[i - 1][j + 1];
- rau[i][j] = 1 + posMax;
- if(rau[i][j] > rauMax)
- rauMax = rau[i][j];
- }
- }
- }
- if(rauMax != 1 && rauMax != 0)
- cout << rauMax << "\n";
- else
- cout << -1;
- }
- int main()
- {
- for(int i = 0; i < N; i++)
- {
- for(int j = 0; mat[i][j] != '\0'; j++)
- {
- cout << rau[i][j] << " ";
- }
- cout << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement