Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Tran Viet Anh - 10:04PM
- #include<iostream>
- using namespace std;
- string valid(string s)
- {
- string result = "";
- int i = 0, _end = s.length() - 1;
- while (s[i] == ' ') i++;
- while (s[_end] == ' ') _end--;
- if (s[i] >= 97 && s[i] <= 122) result += s[i] - 32;
- else result += s[i] - 32;
- for (int j = i + 1; j <= _end; j++)
- if (s[j] != ' ')
- if (s[j - 1] == ' ')
- if (s[j] >= 97 && s[j] <= 122) result += s[j] - 32;
- else result += s[j];
- else
- if (s[j] >= 65 && s[j] <= 90) result += s[j] + 32;
- else result += s[j];
- else
- if (s[j - 1] != ' ') result += ' ';
- return result;
- }
- int main()
- {
- string s; getline(cin,s);
- cout << valid(s);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement