Advertisement
WadeRollins2710

Name Validation [THCS4 N1]

Oct 26th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. //Tran Viet Anh - 10:04PM
  2. #include<iostream>
  3.  
  4. using namespace std;
  5.  
  6. string valid(string s)
  7. {
  8.     string result = "";
  9.     int i = 0, _end = s.length() - 1;
  10.     while (s[i] == ' ') i++;
  11.     while (s[_end] == ' ') _end--;
  12.     if (s[i] >= 97 && s[i] <= 122) result += s[i] - 32;
  13.     else result += s[i] - 32;
  14.     for (int j = i + 1; j <= _end; j++)
  15.         if (s[j] != ' ')
  16.             if (s[j - 1] == ' ')
  17.                 if (s[j] >= 97 && s[j] <= 122) result += s[j] - 32;
  18.                 else result += s[j];
  19.             else
  20.                 if (s[j] >= 65 && s[j] <= 90) result += s[j] + 32;
  21.                 else result += s[j];
  22.         else
  23.             if (s[j - 1] != ' ') result += ' ';
  24.     return result;
  25. }
  26.  
  27. int main()
  28. {
  29.     string s; getline(cin,s);
  30.     cout << valid(s);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement