Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstring>
- using namespace std;
- void Citire(char *s)
- {
- ifstream fin("text.in");
- fin.getline(s, 999);
- fin.close();
- }
- void Replace(char *text, char c1, char c2)
- {
- for(int i = 0; text[i] != 0; i++)
- if(text[i] == c1) text[i] = c2;
- }
- void Delete(char *text)
- {
- char *p;
- while((p = strstr(text, " ")) != NULL)
- strcpy(p+1, p+2);
- }
- void Trim(char *text)
- {
- int i;
- for(i = 0; text[i] == ' '; i++);
- strcpy(text, text+i);
- for(i = strlen(text)-1; text[i] == ' '; i--);
- text[i+1] = 0;
- }
- int Count(char *text)
- {
- int nr = 0;
- for(int i = 0; text[i] != 0; i++)
- if(text[i] == ' ') nr++;
- return nr+1;
- }
- void Solve(char *text)
- {
- char sep[] = ".,?!;:";
- for(int i = 0; i < 6; i++)
- Replace(text, sep[i], ' ');
- Trim(text);
- Delete(text);
- cout << Count(text);
- }
- int main()
- {
- char text[1000];
- Citire(text);
- //Replace(text, 'a', 'x');
- //cout << text << "\n";
- //Delete(text);
- //cout << text << "\n";
- //cin.getline(text, 999);
- cout << text << "\n";
- //Trim(text);
- //cout << text << "." << "\n";
- //cout << Count(text) << "\n";
- Solve(text);
- //cout << text << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement