Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cctype>
- using namespace std;
- enum State { START, WORD, SPACE };
- string acronym(string text);
- int main()
- {
- string input;
- cout << "Enter sentence: ";
- getline(cin, input);
- cout << "Acronym: " << acronym(input) << endl;
- return 0;
- }
- string acronym(string text)
- {
- State st = START;
- string acr = "";
- if (isalpha(text[0]))
- {
- st = WORD;
- acr += toupper(text[0]);
- }
- else
- {
- st = SPACE;
- }
- for (int i = 1; i <= text.length(); i++)
- {
- if (st == SPACE)
- {
- if (isalpha(text[i]))
- {
- st = WORD;
- acr += toupper(text[i]);
- }
- }
- else if (st == WORD)
- {
- if (!isalpha(text[i]))
- {
- st = SPACE;
- }
- }
- }
- return acr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement