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;
- inline void Citire(char* s)
- {
- ifstream fin("text.in");
- fin.getline(s, 999);
- fin.close();
- }
- int main()
- {
- char s[1001], *p;
- Citire(s);
- cout << s << "\n\n\n";
- //a
- int nrcuv = 0;
- p = strtok(s, " ");
- while(p != NULL)
- {
- nrcuv++;
- p = strtok(NULL, " ");
- }
- cout << "a)Nr. cuvinte: " << nrcuv << "\n\n";
- /*
- while((p = strchr(s, ' ')) != NULL)
- {
- n++;
- strcpy(p, p+1);
- }
- cout << n+1;
- */
- //b
- Citire(s);
- int mx = 0, len = 0;
- p = strtok(s, " ");
- while(p != NULL)
- {
- len = strlen(p);
- if(len > mx) mx = len;
- p = strtok(NULL, " ");
- }
- cout << "b)Lung. max. a unui cuvant: " << mx << "\n\n";
- //c
- Citire(s);
- int apr = 0;
- while((p = strstr(s, "muschi")) != NULL)
- {
- apr++;
- strcpy(p, p+6);
- }
- cout << "c)\"Muschi\" aparitii: " << apr << "\n\n";
- //d
- Citire(s);
- char cuv[nrcuv][100];
- char a[100], b[100];
- int i = 0, j;
- p = strtok(s, " ");
- while(p != NULL)
- {
- strcpy(cuv[i], p); i++;
- p = strtok(NULL, " ");
- }
- for(i = 0; i+1 < nrcuv; i++)
- for(j = i+1; j < nrcuv; j++)
- {
- strcpy(a, cuv[i]);
- strcpy(b, cuv[j]);
- int x = strcmp(a, b);
- if(x > 0)
- {
- strcpy(cuv[i], cuv[j]);
- strcpy(cuv[j], a);
- }
- }
- cout << "d)Cuvintele ordonate alfabetic:\n";
- for(i = 0; i < nrcuv; i++)
- cout << cuv[i] << " " ;
- cout << "\n\n";
- //d
- Citire(s);
- for(i = 0; s[i] != 0; i++)
- if(s[i] != 32) s[i] -= 32;
- cout << "e)Uppercase: " << s;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement