-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathdancing_sentence.cpp
54 lines (44 loc) · 1.22 KB
/
dancing_sentence.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// https://www.urionlinejudge.com.br/judge/en/problems/view/1234
#include <iostream>
#include <string>
using namespace std;
char to_uppercase(char charac) {
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int index = alphabet.find(charac) - 26;
return alphabet[index];
}
char to_lowercase(char charac) {
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int index = alphabet.find(charac) + 26;
return alphabet[index];
}
bool is_uppercase(char charac) {
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
if (alphabet.find(charac) <= 25) return true;
else return false;
}
int main() {
string s;
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
while (getline(cin, s)) {
string result = "";
bool uppercase = true;
for (int i = 0; i < s.size(); i++) {
if (s[i] == ' ') {
result += s[i];
} else {
if (uppercase) {
if (is_uppercase(s[i])) result += s[i];
else result += to_uppercase(s[i]);
uppercase = !uppercase;
} else {
if (is_uppercase(s[i])) result += to_lowercase(s[i]);
else result += s[i];
uppercase = !uppercase;
}
}
}
cout << result << endl;
}
return 0;
}