Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstring>
- #include <cstdlib>
- using namespace std;
- //1.
- //a.
- int CitMem(char* txt, char tabl[][15])
- {
- ifstream fin("date.in");
- fin.getline(txt, 999);
- fin.close();
- cout << "text.in: " << txt << "\n\n";
- char sep[] = " ,.;:!?", *p;
- int i = 0;
- p = strtok(txt, sep);
- while(p != NULL)
- {
- strcpy(tabl[i], p);
- i++;
- p = strtok(NULL, sep);
- }
- return i;
- }
- //b.
- void AparCuv(char tabl[][15], int nrcuv, char* cuv)
- {
- int nr = 0;
- for(int i = 0; i < nrcuv; i++)
- if(strcmp(tabl[i], cuv) == 0) nr++;
- cout << "b.Aparitii \"" << cuv << "\" : " << nr << "\n\n";
- }
- //c.
- void SubCuv(char tabl[][15], int nrcuv, char* subcuv)
- {
- cout << "c.Cuvinte cu \"" << subcuv << "\" :\n";
- for(int i = 0; i < nrcuv; i++)
- if(strstr(tabl[i], subcuv) != NULL)
- cout << tabl[i] << "\n";
- cout << "\n";
- }
- //d.
- void MicCuv(char tabl[][15], int nrcuv)
- {
- int i;
- char* cuv = tabl[0];
- for(i = 1; i < nrcuv; i++)
- if(strcmp(tabl[i], cuv) < 0)
- cuv = tabl[i];
- cout << "d.Cel mai mic cuvant: " << cuv << "\n\n";
- }
- //e.
- void InvCuv(char tabl[][15], int nrcuv)
- {
- cout << "e.Cuvintele inversate :\n";
- int i, j, lg;
- for(i = 0; i < nrcuv; i++)
- {
- lg = strlen(tabl[i]) - 1;
- for(j = lg; j >= 0; j--)
- cout << tabl[i][j];
- cout << " ";
- }
- cout << "\n\n";
- }
- //f.
- void TermLit(char tabl[][15], int nrcuv, char lit)
- {
- cout << "f.Cuvintele cu \'" << lit << "\' :\n";
- int i, lg;
- for(i = 0; i < nrcuv; i++)
- {
- lg = strlen(tabl[i]) - 1;
- if(tabl[i][lg] == lit)
- cout << tabl[i] << "\n";
- }
- cout << "\n";
- }
- //g.
- inline void Mutare(char tabl[][15], int nrcuv, int n)
- {
- for(int i = n; i < nrcuv-1; i++)
- strcpy(tabl[i], tabl[i+1]);
- tabl[nrcuv-1][0] = 0;
- }
- int ElimCuv(char tabl[][15], int nrcuv, int nrlit)
- {
- for(int i = 0; i < nrcuv; i++)
- if(strlen(tabl[i]) <= nrlit)
- {
- Mutare(tabl, nrcuv, i);
- nrcuv--;
- i--;
- }
- return nrcuv;
- }
- //h.
- void OrdAlfab(char tabl[][15], int nrcuv)
- {
- int i, j;
- char aux[15];
- for(i = 0; i+1 < nrcuv; i++)
- for(j = i+1; j < nrcuv; j++)
- {
- if(strcmp(tabl[i], tabl[j]) > 0)
- {
- strcpy(aux, tabl[i]);
- strcpy(tabl[i], tabl[j]);
- strcpy(tabl[j], aux);
- }
- }
- }
- //2.
- int Identic(char* s, char* t)
- {
- char *p;
- int slg, tlg;
- slg = strlen(s);
- tlg = strlen(t);
- if(slg != tlg) return 0;
- while(tlg >= 0)
- {
- p = strchr(s, t[0]);
- if(p != NULL)
- {
- strcpy(p, p+1);
- strcpy(t, t+1);
- tlg--;
- }
- else return 0;
- }
- return 1;
- }
- //3.
- void Suma(char* expr)
- {
- int s = 0;
- char *p, sep[] = "x=+ ";
- p = strtok(expr, sep);
- while(p != NULL)
- {
- s += atoi(p);
- p = strtok(NULL, sep);
- }
- cout << "x = " << s;
- }
- int main()
- {
- //1.
- char str[1000], cuv[100][15];
- //a.
- int nrcuv = CitMem(str, cuv);
- //b.
- AparCuv(cuv, nrcuv, "calculator");
- //c.
- SubCuv(cuv, nrcuv, "ini");
- //d.
- MicCuv(cuv, nrcuv);
- //e.
- InvCuv(cuv, nrcuv);
- //f.
- TermLit(cuv, nrcuv, 'a');
- //g.
- nrcuv = ElimCuv(cuv, nrcuv, 3);
- //h.
- OrdAlfab(cuv, nrcuv);
- //2.
- char s[99], t[99];
- cout << "2.s: "; cin.getline(s, 99);
- cout << " t: "; cin.getline(t, 99);
- if(Identic(s, t) == 1)
- cout << "s si t sunt identice.\n\n";
- else
- cout << "s si t nu sunt identice.\n\n";
- //3.
- cout << "3.x=a+b: ";cin.getline(s,99);
- Suma(s);
- //cout << s;
- //cout << nrcuv << "\n";
- //for(int i = 0; i < nrcuv; i++)
- // cout << cuv[i] << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement