output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[107];
cin >> s;
int len, c = 0;
len = strlen(s);
for (int i = 1; i < len; i++) {
if (s[i] >= 65 && s[i] <= 90) c++;
}
if (c == len - 1) {
for (int i = 0; i < len; i++) {
if (s[i] >= 65 && s[i] <= 90)
s[i] = s[i] + 32;
else if (s[i] >= 97 && s[i] <= 122)
s[i] = s[i] - 32;
}
}
cout << s << endl;
return 0;
}
| ### Prompt
Develop a solution in cpp to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[107];
cin >> s;
int len, c = 0;
len = strlen(s);
for (int i = 1; i < len; i++) {
if (s[i] >= 65 && s[i] <= 90) c++;
}
if (c == len - 1) {
for (int i = 0; i < len; i++) {
if (s[i] >= 65 && s[i] <= 90)
s[i] = s[i] + 32;
else if (s[i] >= 97 && s[i] <= 122)
s[i] = s[i] - 32;
}
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string str;
int cnt;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> str;
for (int i = 0; i < str.size(); i++)
if (isupper(str[i])) cnt++;
if (cnt == str.size() - 1 && islower(str[0])) {
str[0] = toupper(str[0]);
for (int i = 1; i < str.size(); i++) str[i] = tolower(str[i]);
} else if (cnt == str.size())
for (int i = 0; i < str.size(); i++) str[i] = tolower(str[i]);
cout << str;
}
| ### Prompt
Please create a solution in cpp to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string str;
int cnt;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> str;
for (int i = 0; i < str.size(); i++)
if (isupper(str[i])) cnt++;
if (cnt == str.size() - 1 && islower(str[0])) {
str[0] = toupper(str[0]);
for (int i = 1; i < str.size(); i++) str[i] = tolower(str[i]);
} else if (cnt == str.size())
for (int i = 0; i < str.size(); i++) str[i] = tolower(str[i]);
cout << str;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
cin >> a;
int f = 0, c = a.length(), i, j = 1, l = 0;
if (islower(a[0])) {
l = 1;
}
for (i = 1; i < c; i++) {
if (isupper(a[i])) {
f = 1;
} else if (islower(a[i]) && f == 1) {
f = 0;
break;
} else if (islower(a[i])) {
f = 0;
break;
}
}
i = 0;
while (i < c) {
if (c == 1 && l == 1) {
cout << char(a[0] - 32);
break;
} else if (c == 1 && l == 0) {
cout << char(a[i] + 32);
break;
} else if (f == 1 && l == 1) {
if (islower(a[i]))
cout << char(a[i] - 32);
else
cout << char(a[i] + 32);
}
if (f == 1 && l == 0) {
cout << char(a[i] + 32);
} else if (f == 0)
cout << a[i];
i++;
}
return 0;
}
| ### Prompt
In cpp, your task is to solve the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
cin >> a;
int f = 0, c = a.length(), i, j = 1, l = 0;
if (islower(a[0])) {
l = 1;
}
for (i = 1; i < c; i++) {
if (isupper(a[i])) {
f = 1;
} else if (islower(a[i]) && f == 1) {
f = 0;
break;
} else if (islower(a[i])) {
f = 0;
break;
}
}
i = 0;
while (i < c) {
if (c == 1 && l == 1) {
cout << char(a[0] - 32);
break;
} else if (c == 1 && l == 0) {
cout << char(a[i] + 32);
break;
} else if (f == 1 && l == 1) {
if (islower(a[i]))
cout << char(a[i] - 32);
else
cout << char(a[i] + 32);
}
if (f == 1 && l == 0) {
cout << char(a[i] + 32);
} else if (f == 0)
cout << a[i];
i++;
}
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int l, i, j, c = 0;
char a[500];
scanf("%s", a);
l = strlen(a);
for (i = 1; i < l; i++) {
if (a[i] >= 65 && a[i] <= 90) c++;
}
if (c == l - 1) {
for (i = 0; i < l; i++) {
if (a[i] >= 65 && a[i] <= 90)
a[i] += 32;
else
a[i] -= 32;
}
}
printf("%s", a);
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int l, i, j, c = 0;
char a[500];
scanf("%s", a);
l = strlen(a);
for (i = 1; i < l; i++) {
if (a[i] >= 65 && a[i] <= 90) c++;
}
if (c == l - 1) {
for (i = 0; i < l; i++) {
if (a[i] >= 65 && a[i] <= 90)
a[i] += 32;
else
a[i] -= 32;
}
}
printf("%s", a);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string s1 = "abcdefghijklmnopqrstuvwxyz";
string s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int count1 = 0;
int count2 = 0, a;
for (int i = 0; i < s.size(); i++) {
if ((int(s[i]) >= 65) && (int(s[i]) <= 90)) {
count1++;
}
if ((int(s[i]) >= 97) && (int(s[i]) <= 122)) {
a = i;
count2++;
}
}
if (count1 == s.size()) {
for (int i = 0; i < s.size(); i++) {
cout << s1[s[i] - 'A'];
}
} else if ((count1 == s.size() - 1) && (count2 == 1) && (a == 0)) {
cout << s2[s[0] - 'a'];
for (int i = 1; i < s.size(); i++) {
cout << s1[s[i] - 'A'];
}
} else {
cout << s;
}
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string s1 = "abcdefghijklmnopqrstuvwxyz";
string s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int count1 = 0;
int count2 = 0, a;
for (int i = 0; i < s.size(); i++) {
if ((int(s[i]) >= 65) && (int(s[i]) <= 90)) {
count1++;
}
if ((int(s[i]) >= 97) && (int(s[i]) <= 122)) {
a = i;
count2++;
}
}
if (count1 == s.size()) {
for (int i = 0; i < s.size(); i++) {
cout << s1[s[i] - 'A'];
}
} else if ((count1 == s.size() - 1) && (count2 == 1) && (a == 0)) {
cout << s2[s[0] - 'a'];
for (int i = 1; i < s.size(); i++) {
cout << s1[s[i] - 'A'];
}
} else {
cout << s;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long l, i, k = 0, f1 = 0, f2 = 0, f3 = 0;
string s, s2;
getline(cin, s);
l = s.length();
for (i = 0; i < l; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') f1++;
}
if (f1 == l)
for (i = 0; i < l; i++) cout << char(tolower(s[i]));
else if (s[0] >= 'a' && s[0] <= 'z' && l - f1 == 1) {
cout << char(toupper(s[0]));
for (i = 1; i < l; i++) cout << char(tolower(s[i]));
} else
cout << s;
return 0;
}
| ### Prompt
Develop a solution in cpp to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long l, i, k = 0, f1 = 0, f2 = 0, f3 = 0;
string s, s2;
getline(cin, s);
l = s.length();
for (i = 0; i < l; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') f1++;
}
if (f1 == l)
for (i = 0; i < l; i++) cout << char(tolower(s[i]));
else if (s[0] >= 'a' && s[0] <= 'z' && l - f1 == 1) {
cout << char(toupper(s[0]));
for (i = 1; i < l; i++) cout << char(tolower(s[i]));
} else
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int check(string s) {
int b = 0;
for (int i = 1; i < s.length(); i++) {
if (isupper(s[i]))
b++;
else if (islower(s[i])) {
b = 0;
}
}
return b;
}
int main() {
string s;
cin >> s;
if (s.length() == 1) {
if (islower(s[0]))
s[0] = toupper(s[0]);
else if (isupper(s[0]))
s[0] = tolower(s[0]);
cout << s;
}
int k = check(s);
int m = s.length();
if ((k > 0) && (k == m - 1)) {
for (int i = 1; i < s.length(); i++) {
s[i] = tolower(s[i]);
}
if (islower(s[0]))
s[0] = toupper(s[0]);
else if (isupper(s[0]))
s[0] = tolower(s[0]);
cout << s;
} else if (k != m - 1) {
cout << s;
}
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int check(string s) {
int b = 0;
for (int i = 1; i < s.length(); i++) {
if (isupper(s[i]))
b++;
else if (islower(s[i])) {
b = 0;
}
}
return b;
}
int main() {
string s;
cin >> s;
if (s.length() == 1) {
if (islower(s[0]))
s[0] = toupper(s[0]);
else if (isupper(s[0]))
s[0] = tolower(s[0]);
cout << s;
}
int k = check(s);
int m = s.length();
if ((k > 0) && (k == m - 1)) {
for (int i = 1; i < s.length(); i++) {
s[i] = tolower(s[i]);
}
if (islower(s[0]))
s[0] = toupper(s[0]);
else if (isupper(s[0]))
s[0] = tolower(s[0]);
cout << s;
} else if (k != m - 1) {
cout << s;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int flag = 0;
if (islower(s[0])) {
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
flag = 1;
}
}
} else {
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
flag = 1;
}
}
}
if (flag == 0) {
for (int i = 0; i < s.length(); i++) {
if (islower(s[i])) {
s[i] = toupper(s[i]);
} else
s[i] = tolower(s[i]);
}
}
cout << s;
return 0;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int flag = 0;
if (islower(s[0])) {
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
flag = 1;
}
}
} else {
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
flag = 1;
}
}
}
if (flag == 0) {
for (int i = 0; i < s.length(); i++) {
if (islower(s[i])) {
s[i] = toupper(s[i]);
} else
s[i] = tolower(s[i]);
}
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
string check = str;
transform(check.begin(), check.end(), check.begin(), ::toupper);
if (check == str) {
for (int i = 0; i < str.size(); i++) {
char ch = tolower(str[i]);
cout << ch;
}
cout << endl;
return 0;
} else {
bool flag = false;
char ch1 = tolower(str[0]);
if (ch1 == str[0]) {
for (int i = 1; i < str.size(); i++) {
char ch2 = toupper(str[i]);
if (str[i] == ch2) {
continue;
} else {
flag = true;
}
}
if (flag == false) {
char ch3 = toupper(str[0]);
cout << ch3;
for (int i = 1; i < str.size(); i++) {
char ch4 = tolower(str[i]);
cout << ch4;
}
cout << endl;
return 0;
}
}
}
cout << str << endl;
}
| ### Prompt
Generate a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
string check = str;
transform(check.begin(), check.end(), check.begin(), ::toupper);
if (check == str) {
for (int i = 0; i < str.size(); i++) {
char ch = tolower(str[i]);
cout << ch;
}
cout << endl;
return 0;
} else {
bool flag = false;
char ch1 = tolower(str[0]);
if (ch1 == str[0]) {
for (int i = 1; i < str.size(); i++) {
char ch2 = toupper(str[i]);
if (str[i] == ch2) {
continue;
} else {
flag = true;
}
}
if (flag == false) {
char ch3 = toupper(str[0]);
cout << ch3;
for (int i = 1; i < str.size(); i++) {
char ch4 = tolower(str[i]);
cout << ch4;
}
cout << endl;
return 0;
}
}
}
cout << str << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string Convert(string s) {
for (int i = 0; i < (int)s.length(); i++) {
if (isupper(s[i]))
s[i] = tolower(s[i]);
else if (islower(s[i]))
s[i] = toupper(s[i]);
}
return s;
}
int main() {
string s;
cin >> s;
bool upper = false;
for (int i = 1; i < (int)s.length(); i++) {
if (isupper(s[i])) {
upper = true;
} else {
upper = false;
break;
}
}
(upper || s.length() == 1) ? cout << Convert(s) : cout << s;
return 0;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string Convert(string s) {
for (int i = 0; i < (int)s.length(); i++) {
if (isupper(s[i]))
s[i] = tolower(s[i]);
else if (islower(s[i]))
s[i] = toupper(s[i]);
}
return s;
}
int main() {
string s;
cin >> s;
bool upper = false;
for (int i = 1; i < (int)s.length(); i++) {
if (isupper(s[i])) {
upper = true;
} else {
upper = false;
break;
}
}
(upper || s.length() == 1) ? cout << Convert(s) : cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int flag = false;
for (int i = 1; i < s.size(); i++) {
if (s[i] >= 97) {
flag = true;
break;
}
}
for (int i = 0; i < s.size() && flag == false; i++) {
if (s[i] <= 90) {
s[i] += 32;
} else {
s[i] -= 32;
}
}
cout << s << endl;
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int flag = false;
for (int i = 1; i < s.size(); i++) {
if (s[i] >= 97) {
flag = true;
break;
}
}
for (int i = 0; i < s.size() && flag == false; i++) {
if (s[i] <= 90) {
s[i] += 32;
} else {
s[i] -= 32;
}
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
bool flag = true;
cin >> str;
for (int i = 1; i < str.size(); i++) {
if (str[i] >= 97 && str[i] <= 122) {
flag = false;
break;
}
}
if (flag) {
if (str[0] >= 97 && str[0] <= 122) {
str[0] = str[0] - ('a' - 'A');
} else {
str[0] = str[0] + ('a' - 'A');
}
for (int i = 1; i < str.size(); i++) {
if (str[i] <= 90 && str[i] >= 65) {
str[i] = str[i] + ('a' - 'A');
}
}
}
cout << str << endl;
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
bool flag = true;
cin >> str;
for (int i = 1; i < str.size(); i++) {
if (str[i] >= 97 && str[i] <= 122) {
flag = false;
break;
}
}
if (flag) {
if (str[0] >= 97 && str[0] <= 122) {
str[0] = str[0] - ('a' - 'A');
} else {
str[0] = str[0] + ('a' - 'A');
}
for (int i = 1; i < str.size(); i++) {
if (str[i] <= 90 && str[i] >= 65) {
str[i] = str[i] + ('a' - 'A');
}
}
}
cout << str << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
char a[1000];
char b[1000];
int main() {
int i = 1, z = 0, s;
char c;
gets(a);
strcpy(b, a);
s = strlen(a);
while (b[i]) {
if (isupper(b[i])) {
b[i] = tolower(b[i]);
i++;
} else {
z = 1;
break;
}
}
if (z == 1) {
puts(a);
} else {
if (islower(b[0])) {
b[0] = toupper(b[0]);
} else {
b[0] = tolower(b[0]);
}
puts(b);
}
return 0;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
char a[1000];
char b[1000];
int main() {
int i = 1, z = 0, s;
char c;
gets(a);
strcpy(b, a);
s = strlen(a);
while (b[i]) {
if (isupper(b[i])) {
b[i] = tolower(b[i]);
i++;
} else {
z = 1;
break;
}
}
if (z == 1) {
puts(a);
} else {
if (islower(b[0])) {
b[0] = toupper(b[0]);
} else {
b[0] = tolower(b[0]);
}
puts(b);
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int l = s.length();
bool con1 = true, con2 = true;
for (int i = 0; i < l; i++) {
if (s[i] > 90) {
con1 = false;
break;
}
}
if (!con1) {
if (s[0] < 90) {
con2 = false;
} else {
con2 = true;
for (int i = 1; i < l; i++) {
if (s[i] > 90) {
con2 = false;
break;
}
}
}
}
if (con1 || con2) {
for (int i = 0; i < l; i++) {
if (s[i] > 90) {
s[i] -= 32;
} else {
s[i] += 32;
}
}
}
cout << s << endl;
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int l = s.length();
bool con1 = true, con2 = true;
for (int i = 0; i < l; i++) {
if (s[i] > 90) {
con1 = false;
break;
}
}
if (!con1) {
if (s[0] < 90) {
con2 = false;
} else {
con2 = true;
for (int i = 1; i < l; i++) {
if (s[i] > 90) {
con2 = false;
break;
}
}
}
}
if (con1 || con2) {
for (int i = 0; i < l; i++) {
if (s[i] > 90) {
s[i] -= 32;
} else {
s[i] += 32;
}
}
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e5 + 3;
int cnt[mxN];
int main() {
int n, a = 0, b = 0, c = 0, ans = 0, m, i, j, cn = 0, sm = 0, mx = INT_MIN,
mn = INT_MAX, k;
string s;
cin >> s;
bool f = true;
for (i = 1; i < s.size(); i++) {
if (s[i] - 'a' < 0)
continue;
else {
f = false;
break;
}
}
if (s[0] - 'a' < 0) {
if (f) {
for (i = 0; i < s.size(); i++) cout << char(tolower(s[i]));
cout << "\n";
} else
cout << s << "\n";
} else {
if (f) {
cout << char(toupper(s[0]));
for (i = 1; i < s.size(); i++) cout << char(tolower(s[i]));
cout << "\n";
} else
cout << s << "\n";
}
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e5 + 3;
int cnt[mxN];
int main() {
int n, a = 0, b = 0, c = 0, ans = 0, m, i, j, cn = 0, sm = 0, mx = INT_MIN,
mn = INT_MAX, k;
string s;
cin >> s;
bool f = true;
for (i = 1; i < s.size(); i++) {
if (s[i] - 'a' < 0)
continue;
else {
f = false;
break;
}
}
if (s[0] - 'a' < 0) {
if (f) {
for (i = 0; i < s.size(); i++) cout << char(tolower(s[i]));
cout << "\n";
} else
cout << s << "\n";
} else {
if (f) {
cout << char(toupper(s[0]));
for (i = 1; i < s.size(); i++) cout << char(tolower(s[i]));
cout << "\n";
} else
cout << s << "\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string s = "";
string ans = "";
int n = s.size();
bool check(int pos) {
if (pos == 0) return true;
if (islower(s[pos]))
return false;
else
return check(pos - 1);
}
int main() {
cin >> s;
auto str = s.c_str();
int n = s.size();
bool upFlag = false, lowFlag = true;
upFlag = true;
int i = 0;
upFlag = check(n);
if (upFlag) {
if ('a' <= str[0] && str[0] <= 'z') {
s[0] = s[0] - 'a' + 'A';
} else
s[0] = s[0] - 'A' + 'a';
for (int i = 1; i < n; i++) {
s[i] = s[i] - 'A' + 'a';
}
}
cout << s << endl;
return 0;
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string s = "";
string ans = "";
int n = s.size();
bool check(int pos) {
if (pos == 0) return true;
if (islower(s[pos]))
return false;
else
return check(pos - 1);
}
int main() {
cin >> s;
auto str = s.c_str();
int n = s.size();
bool upFlag = false, lowFlag = true;
upFlag = true;
int i = 0;
upFlag = check(n);
if (upFlag) {
if ('a' <= str[0] && str[0] <= 'z') {
s[0] = s[0] - 'a' + 'A';
} else
s[0] = s[0] - 'A' + 'a';
for (int i = 1; i < n; i++) {
s[i] = s[i] - 'A' + 'a';
}
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
locale loc;
string input;
cin >> input;
int caps_count = 0, nocaps_count = 0;
for (int i = 0; i < input.length(); ++i) {
if ((char)input[i] >= 'A' && (char)input[i] <= 'Z') {
++caps_count;
} else {
++nocaps_count;
}
}
if (caps_count == input.length()) {
for (int i = 0; i < input.length(); ++i) {
cout << tolower(input[i], loc);
}
} else if ((input[0] >= 'A' && input[0] <= 'Z') && caps_count == 1) {
cout << input;
} else if (input.length() == 1) {
cout << toupper(input[0], loc);
} else if ((input[0] >= 'a' && input[0] <= 'z') && nocaps_count == 1 &&
caps_count > 0) {
cout << toupper(input[0], loc);
for (int i = 1; i < input.length(); ++i) {
cout << tolower(input[i], loc);
}
} else {
cout << input;
}
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
locale loc;
string input;
cin >> input;
int caps_count = 0, nocaps_count = 0;
for (int i = 0; i < input.length(); ++i) {
if ((char)input[i] >= 'A' && (char)input[i] <= 'Z') {
++caps_count;
} else {
++nocaps_count;
}
}
if (caps_count == input.length()) {
for (int i = 0; i < input.length(); ++i) {
cout << tolower(input[i], loc);
}
} else if ((input[0] >= 'A' && input[0] <= 'Z') && caps_count == 1) {
cout << input;
} else if (input.length() == 1) {
cout << toupper(input[0], loc);
} else if ((input[0] >= 'a' && input[0] <= 'z') && nocaps_count == 1 &&
caps_count > 0) {
cout << toupper(input[0], loc);
for (int i = 1; i < input.length(); ++i) {
cout << tolower(input[i], loc);
}
} else {
cout << input;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int t1, t2, n;
int main() {
string a;
cin >> a;
n = a.size();
for (int i = 0; i < n; i++) {
if (!(a[i] >= 'A' && a[i] <= 'Z')) t1 = 1;
}
if (t1 == 0) {
for (int i = 0; i < n; i++) {
a[i] = 'a' + (a[i] - 'A');
}
cout << a;
} else {
if (!(a[0] >= 'a' && a[0] <= 'z')) t2 = 1;
if (t2 == 0) {
for (int i = 1; i < n; i++) {
if (!(a[i] >= 'A' && a[i] <= 'Z')) t2 = 1;
}
if (t2 == 0) {
a[0] = 'A' + (a[0] - 'a');
for (int i = 1; i < n; i++) {
a[i] = 'a' + (a[i] - 'A');
}
cout << a;
} else
cout << a;
} else
cout << a;
}
}
| ### Prompt
Please formulate a cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int t1, t2, n;
int main() {
string a;
cin >> a;
n = a.size();
for (int i = 0; i < n; i++) {
if (!(a[i] >= 'A' && a[i] <= 'Z')) t1 = 1;
}
if (t1 == 0) {
for (int i = 0; i < n; i++) {
a[i] = 'a' + (a[i] - 'A');
}
cout << a;
} else {
if (!(a[0] >= 'a' && a[0] <= 'z')) t2 = 1;
if (t2 == 0) {
for (int i = 1; i < n; i++) {
if (!(a[i] >= 'A' && a[i] <= 'Z')) t2 = 1;
}
if (t2 == 0) {
a[0] = 'A' + (a[0] - 'a');
for (int i = 1; i < n; i++) {
a[i] = 'a' + (a[i] - 'A');
}
cout << a;
} else
cout << a;
} else
cout << a;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
char u;
bool c = true;
cin >> s;
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
c = false;
}
}
if (c == true) {
for (int j = 0; j < s.length(); j++) {
if (islower(s[j]))
u = toupper(s[j]);
else
u = tolower(s[j]);
cout << u;
}
} else
cout << s;
return 0;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
char u;
bool c = true;
cin >> s;
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
c = false;
}
}
if (c == true) {
for (int j = 0; j < s.length(); j++) {
if (islower(s[j]))
u = toupper(s[j]);
else
u = tolower(s[j]);
cout << u;
}
} else
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
int isUpper(char *arr) {
int i;
char c;
c = arr[0];
for (i = 1; c != '\0'; i++) {
if (c >= 'a' && c <= 'z') return 0;
c = arr[i];
}
return 1;
}
void printToggle(char *arr) {
int i;
char c;
i = 0;
c = arr[0];
while (c != '\0') {
if (c >= 'a' && c <= 'z') {
printf("%c", c - 32);
} else if (c >= 'A' && c <= 'Z') {
printf("%c", c + 32);
}
i++;
c = arr[i];
}
printf("\n");
}
int main() {
char str[100 + 10];
int caps;
scanf("%s", str);
caps = 1;
if (str[0] >= 'a' && str[0] <= 'z') {
caps = isUpper(&str[1]);
} else {
caps = isUpper(&str[1]);
}
if (caps == 1) {
printToggle(str);
} else {
printf("%s\n", str);
}
}
| ### Prompt
Create a solution in Cpp for the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
int isUpper(char *arr) {
int i;
char c;
c = arr[0];
for (i = 1; c != '\0'; i++) {
if (c >= 'a' && c <= 'z') return 0;
c = arr[i];
}
return 1;
}
void printToggle(char *arr) {
int i;
char c;
i = 0;
c = arr[0];
while (c != '\0') {
if (c >= 'a' && c <= 'z') {
printf("%c", c - 32);
} else if (c >= 'A' && c <= 'Z') {
printf("%c", c + 32);
}
i++;
c = arr[i];
}
printf("\n");
}
int main() {
char str[100 + 10];
int caps;
scanf("%s", str);
caps = 1;
if (str[0] >= 'a' && str[0] <= 'z') {
caps = isUpper(&str[1]);
} else {
caps = isUpper(&str[1]);
}
if (caps == 1) {
printToggle(str);
} else {
printf("%s\n", str);
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int x = 0;
cin >> s;
for (int i = 1; i < s.length(); i++) {
if (isupper(s[i])) x++;
}
if (x == s.length() - 1) {
for (int i = 0; i < s.length(); i++) {
if (isupper(s[i])) {
s[i] = tolower(s[i]);
} else {
s[i] = toupper(s[i]);
}
}
}
cout << s;
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int x = 0;
cin >> s;
for (int i = 1; i < s.length(); i++) {
if (isupper(s[i])) x++;
}
if (x == s.length() - 1) {
for (int i = 0; i < s.length(); i++) {
if (isupper(s[i])) {
s[i] = tolower(s[i]);
} else {
s[i] = toupper(s[i]);
}
}
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool change = true;
for (size_t i = 1; i < s.length(); ++i) {
if (s[i] >= 'a') {
change = false;
break;
}
}
if (change) {
for (size_t i = 0; i < s.length(); ++i) {
if (s[i] >= 'a') {
s[i] -= ('a' - 'A');
} else {
s[i] += ('a' - 'A');
}
}
}
cout << s << endl;
return 0;
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool change = true;
for (size_t i = 1; i < s.length(); ++i) {
if (s[i] >= 'a') {
change = false;
break;
}
}
if (change) {
for (size_t i = 0; i < s.length(); ++i) {
if (s[i] >= 'a') {
s[i] -= ('a' - 'A');
} else {
s[i] += ('a' - 'A');
}
}
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int i, len;
char str[101];
scanf("%s", str);
len = strlen(str);
if (len == 1) {
if (islower(str[0]))
putchar(toupper(str[0]));
else
putchar(tolower(str[0]));
putchar('\n');
} else {
for (i = 1; i < len; i++)
if (islower(str[i])) break;
if (i == len) {
if (islower(str[0]))
putchar(toupper(str[0]));
else
putchar(tolower(str[0]));
for (i = 1; i < len; i++) putchar(tolower(str[i]));
putchar('\n');
} else
printf("%s\n", str);
}
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int i, len;
char str[101];
scanf("%s", str);
len = strlen(str);
if (len == 1) {
if (islower(str[0]))
putchar(toupper(str[0]));
else
putchar(tolower(str[0]));
putchar('\n');
} else {
for (i = 1; i < len; i++)
if (islower(str[i])) break;
if (i == len) {
if (islower(str[0]))
putchar(toupper(str[0]));
else
putchar(tolower(str[0]));
for (i = 1; i < len; i++) putchar(tolower(str[i]));
putchar('\n');
} else
printf("%s\n", str);
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int m = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 65 && s[i] <= 90) {
m++;
}
}
if (m == s.size()) {
for (int i = 0; i < s.size(); i++) {
s[i] = s[i] + ('a' - 'A');
}
}
if (m == s.size() - 1 && s[0] <= 122 && s[0] >= 97) {
s[0] = s[0] - ('a' - 'A');
for (int i = 1; i < s.size(); i++) {
s[i] = s[i] + ('a' - 'A');
}
}
cout << s;
}
| ### Prompt
Generate a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int m = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 65 && s[i] <= 90) {
m++;
}
}
if (m == s.size()) {
for (int i = 0; i < s.size(); i++) {
s[i] = s[i] + ('a' - 'A');
}
}
if (m == s.size() - 1 && s[0] <= 122 && s[0] >= 97) {
s[0] = s[0] - ('a' - 'A');
for (int i = 1; i < s.size(); i++) {
s[i] = s[i] + ('a' - 'A');
}
}
cout << s;
}
``` |
#include <bits/stdc++.h>
using namespace std;
char msk[111];
int len, x, y, z;
bool caps;
int main() {
scanf("%s", msk);
len = strlen(msk);
caps = true;
for (x = 1; x < len; x++)
if ((msk[x] < 'A') || (msk[x] > 'Z')) {
caps = false;
break;
}
if (caps)
for (x = 0; x < len; x++) msk[x] ^= 32;
printf("%s\n", msk);
return 0;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char msk[111];
int len, x, y, z;
bool caps;
int main() {
scanf("%s", msk);
len = strlen(msk);
caps = true;
for (x = 1; x < len; x++)
if ((msk[x] < 'A') || (msk[x] > 'Z')) {
caps = false;
break;
}
if (caps)
for (x = 0; x < len; x++) msk[x] ^= 32;
printf("%s\n", msk);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
if (n == 1) {
if (s[0] <= 'z' && s[0] >= 'a') {
s[0] -= 32;
cout << s;
} else {
s[0] += 32;
cout << s;
}
} else {
int k = 0;
if (s[0] >= 'a' && s[0] <= 'z') {
for (int i = 1; i < n; i++) {
if (s[i] >= 'a' && s[i] <= 'z') k = 1;
}
if (k == 0) {
s[0] -= 32;
for (int i = 1; i < n; i++) s[i] = tolower(s[i]);
cout << s;
} else
cout << s;
} else {
int k1 = 0;
for (int i = 1; i < n; i++) {
if (s[i] >= 'a' && s[i] <= 'z') k1 = 1;
}
if (k1 == 0) {
for (int i = 0; i < n; i++) s[i] = tolower(s[i]);
cout << s;
} else {
cout << s;
}
}
}
}
| ### Prompt
In cpp, your task is to solve the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
if (n == 1) {
if (s[0] <= 'z' && s[0] >= 'a') {
s[0] -= 32;
cout << s;
} else {
s[0] += 32;
cout << s;
}
} else {
int k = 0;
if (s[0] >= 'a' && s[0] <= 'z') {
for (int i = 1; i < n; i++) {
if (s[i] >= 'a' && s[i] <= 'z') k = 1;
}
if (k == 0) {
s[0] -= 32;
for (int i = 1; i < n; i++) s[i] = tolower(s[i]);
cout << s;
} else
cout << s;
} else {
int k1 = 0;
for (int i = 1; i < n; i++) {
if (s[i] >= 'a' && s[i] <= 'z') k1 = 1;
}
if (k1 == 0) {
for (int i = 0; i < n; i++) s[i] = tolower(s[i]);
cout << s;
} else {
cout << s;
}
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int cnt1 = 0;
int cnt2 = 0;
bool f = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] < 97) {
cnt1++;
}
}
if (cnt1 == s.length()) {
for (int i = 0; i < s.length(); i++) {
s[i] += 32;
}
cout << s << endl;
f = 1;
return 0;
}
if (s[0] >= 97) {
for (int i = 1; i < s.length(); i++) {
if (s[i] < 97) {
cnt2++;
}
}
}
if (cnt2 == s.length() - 1) {
s[0] = s[0] - 32;
for (int i = 1; i < s.length(); i++) {
s[i] = s[i] + 32;
}
cout << s << endl;
f = 1;
return 0;
}
if (f == 0) {
cout << s << endl;
}
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int cnt1 = 0;
int cnt2 = 0;
bool f = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] < 97) {
cnt1++;
}
}
if (cnt1 == s.length()) {
for (int i = 0; i < s.length(); i++) {
s[i] += 32;
}
cout << s << endl;
f = 1;
return 0;
}
if (s[0] >= 97) {
for (int i = 1; i < s.length(); i++) {
if (s[i] < 97) {
cnt2++;
}
}
}
if (cnt2 == s.length() - 1) {
s[0] = s[0] - 32;
for (int i = 1; i < s.length(); i++) {
s[i] = s[i] + 32;
}
cout << s << endl;
f = 1;
return 0;
}
if (f == 0) {
cout << s << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string s;
int gede;
int main() {
cin >> s;
for (int i = 0; i < s.size(); i++)
if (s[i] >= 'A' && s[i] <= 'Z') gede++;
if (gede == s.size()) {
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
}
}
if (gede + 1 == s.size() and s[0] >= 'a' and s[0] <= 'z') {
if (s[0] <= 'z' and s[0] >= 'a') s[0] = s[0] - 'a' + 'A';
for (int i = 1; i < s.size(); i++)
if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
}
cout << s << endl;
}
| ### Prompt
Develop a solution in cpp to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string s;
int gede;
int main() {
cin >> s;
for (int i = 0; i < s.size(); i++)
if (s[i] >= 'A' && s[i] <= 'Z') gede++;
if (gede == s.size()) {
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
}
}
if (gede + 1 == s.size() and s[0] >= 'a' and s[0] <= 'z') {
if (s[0] <= 'z' and s[0] >= 'a') s[0] = s[0] - 'a' + 'A';
for (int i = 1; i < s.size(); i++)
if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
}
cout << s << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string x;
cin >> x;
bool flag2 = true;
for (int i = 1; i < x.length(); i++) {
if (!isupper(x[i])) {
flag2 = false;
break;
}
}
if (flag2) {
for (int i = 0; i < x.length(); i++) {
if (isupper(x[i]))
cout << (char)tolower(x[i]);
else
cout << (char)toupper(x[i]);
}
} else
cout << x;
}
| ### Prompt
Generate a cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string x;
cin >> x;
bool flag2 = true;
for (int i = 1; i < x.length(); i++) {
if (!isupper(x[i])) {
flag2 = false;
break;
}
}
if (flag2) {
for (int i = 0; i < x.length(); i++) {
if (isupper(x[i]))
cout << (char)tolower(x[i]);
else
cout << (char)toupper(x[i]);
}
} else
cout << x;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
int dx[] = {0, 0, +1, -1, -1 + 1, -1, +1};
int dy[] = {+1, -1, 0, 0, -1, +1, +1, -1};
const int mx = 1e5 + 123;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
string a;
cin >> a;
int t = a.size();
int cnt = 0;
if (t == 1 && islower(a[0]))
cout << (char)(toupper(a[0]));
else if (t == 1)
cout << (char)tolower(a[0]);
else {
if (a[0] >= 'a' && a[0] <= 'z') {
for (long long i = 1; i < t; i++) {
if (islower(a[i])) {
cnt++;
}
}
if (cnt == (t - 1))
cout << a << '\n';
else if (cnt >= 1 && cnt < (t - 1))
cout << a << '\n';
else {
cout << (char)(toupper(a[0]));
for (int i = 1; i < t; i++) {
cout << (char)(tolower(a[i]));
}
}
} else {
for (int i = 1; i < t; i++) {
if (isupper(a[i])) {
cnt++;
}
}
if (cnt >= 1 && cnt < (t - 1))
cout << a << '\n';
else if (cnt == (t - 1)) {
for (int i = 0; i < t; i++) {
cout << (char)tolower(a[i]);
}
} else if (cnt == 0) {
cout << a << '\n';
}
}
}
}
| ### Prompt
Develop a solution in CPP to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
int dx[] = {0, 0, +1, -1, -1 + 1, -1, +1};
int dy[] = {+1, -1, 0, 0, -1, +1, +1, -1};
const int mx = 1e5 + 123;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
string a;
cin >> a;
int t = a.size();
int cnt = 0;
if (t == 1 && islower(a[0]))
cout << (char)(toupper(a[0]));
else if (t == 1)
cout << (char)tolower(a[0]);
else {
if (a[0] >= 'a' && a[0] <= 'z') {
for (long long i = 1; i < t; i++) {
if (islower(a[i])) {
cnt++;
}
}
if (cnt == (t - 1))
cout << a << '\n';
else if (cnt >= 1 && cnt < (t - 1))
cout << a << '\n';
else {
cout << (char)(toupper(a[0]));
for (int i = 1; i < t; i++) {
cout << (char)(tolower(a[i]));
}
}
} else {
for (int i = 1; i < t; i++) {
if (isupper(a[i])) {
cnt++;
}
}
if (cnt >= 1 && cnt < (t - 1))
cout << a << '\n';
else if (cnt == (t - 1)) {
for (int i = 0; i < t; i++) {
cout << (char)tolower(a[i]);
}
} else if (cnt == 0) {
cout << a << '\n';
}
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool change = true;
for (size_t i = 1; i < s.length(); ++i) {
if (s[i] >= 'a') {
change = false;
break;
}
}
if (change) {
for (size_t i = 0; i < s.length(); ++i) {
if (s[i] >= 'a') {
s[i] -= ('a' - 'A');
} else {
s[i] += ('a' - 'A');
}
}
}
cout << s << endl;
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool change = true;
for (size_t i = 1; i < s.length(); ++i) {
if (s[i] >= 'a') {
change = false;
break;
}
}
if (change) {
for (size_t i = 0; i < s.length(); ++i) {
if (s[i] >= 'a') {
s[i] -= ('a' - 'A');
} else {
s[i] += ('a' - 'A');
}
}
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const unsigned int modval = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string word;
bool uppr = true;
cin >> word;
for (int i = 1; i < word.size(); i++) {
if (!isupper(word[i])) uppr = false;
}
if (uppr) {
for (char &c : word) {
if (isupper(c)) {
c = tolower(c);
} else {
c = toupper(c);
}
}
}
cout << word << '\n';
return 0;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const unsigned int modval = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string word;
bool uppr = true;
cin >> word;
for (int i = 1; i < word.size(); i++) {
if (!isupper(word[i])) uppr = false;
}
if (uppr) {
for (char &c : word) {
if (isupper(c)) {
c = tolower(c);
} else {
c = toupper(c);
}
}
}
cout << word << '\n';
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int a, i;
char s[105];
a = 0;
scanf("%s", s);
for (i = 0; i < strlen(s); i++)
if (s[i] < 91) a++;
if (s[0] > 96 && a == strlen(s) - 1) {
printf("%c", s[0] - 32);
for (i = 1; i < strlen(s); i++) printf("%c", s[i] + 32);
} else if (a == strlen(s))
for (i = 0; i < strlen(s); i++) printf("%c", s[i] + 32);
else
printf("%s", s);
return 0;
}
| ### Prompt
Generate a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int a, i;
char s[105];
a = 0;
scanf("%s", s);
for (i = 0; i < strlen(s); i++)
if (s[i] < 91) a++;
if (s[0] > 96 && a == strlen(s) - 1) {
printf("%c", s[0] - 32);
for (i = 1; i < strlen(s); i++) printf("%c", s[i] + 32);
} else if (a == strlen(s))
for (i = 0; i < strlen(s); i++) printf("%c", s[i] + 32);
else
printf("%s", s);
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
char text[101];
scanf("%s", text);
for (int i = 1; text[i] != '\0'; i++) {
if (text[i] >= 'a' && text[i] <= 'z') {
printf("%s", text);
return 0;
}
}
for (int i = 0; text[i] != '\0'; i++) {
printf("%c", text[i] ^ 32);
}
return 0;
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
int main() {
char text[101];
scanf("%s", text);
for (int i = 1; text[i] != '\0'; i++) {
if (text[i] >= 'a' && text[i] <= 'z') {
printf("%s", text);
return 0;
}
}
for (int i = 0; text[i] != '\0'; i++) {
printf("%c", text[i] ^ 32);
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool todoMayuscula = 1;
for (int i = 0; i < s.size(); i++)
if (islower(s[i])) todoMayuscula = 0;
if (todoMayuscula) {
for (int i = 0; i < s.size(); i++) s[i] = tolower(s[i]);
cout << s << endl;
} else {
bool caso2 = 1;
if (isupper(s[0])) caso2 = 0;
for (int i = 1; i < s.size(); i++)
if (islower(s[i])) caso2 = 0;
if (caso2) {
s[0] = toupper(s[0]);
for (int i = 1; i < s.size(); i++) s[i] = tolower(s[i]);
cout << s << endl;
} else
cout << s << endl;
}
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool todoMayuscula = 1;
for (int i = 0; i < s.size(); i++)
if (islower(s[i])) todoMayuscula = 0;
if (todoMayuscula) {
for (int i = 0; i < s.size(); i++) s[i] = tolower(s[i]);
cout << s << endl;
} else {
bool caso2 = 1;
if (isupper(s[0])) caso2 = 0;
for (int i = 1; i < s.size(); i++)
if (islower(s[i])) caso2 = 0;
if (caso2) {
s[0] = toupper(s[0]);
for (int i = 1; i < s.size(); i++) s[i] = tolower(s[i]);
cout << s << endl;
} else
cout << s << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int b, c, d, e;
int main() {
string a;
cin >> a;
locale loc;
if (isupper(a[0])) d = 1;
for (int i = 1; i < a.size(); i++) {
if (isupper(a[i])) c++;
}
if (c == a.size() - 1 && d == 1)
for (int i = 0; i < a.size(); i++) {
cout << tolower(a[i], loc);
}
else if (c == a.size() - 1) {
cout << toupper(a[0], loc);
for (int i = 1; i < a.size(); i++) {
cout << tolower(a[i], loc);
}
} else
for (int i = 0; i < a.size(); i++) {
cout << a[i];
}
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int b, c, d, e;
int main() {
string a;
cin >> a;
locale loc;
if (isupper(a[0])) d = 1;
for (int i = 1; i < a.size(); i++) {
if (isupper(a[i])) c++;
}
if (c == a.size() - 1 && d == 1)
for (int i = 0; i < a.size(); i++) {
cout << tolower(a[i], loc);
}
else if (c == a.size() - 1) {
cout << toupper(a[0], loc);
for (int i = 1; i < a.size(); i++) {
cout << tolower(a[i], loc);
}
} else
for (int i = 0; i < a.size(); i++) {
cout << a[i];
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
char a[s.size() + 5];
if (s[0] >= 97) {
a[0] = s[0] - 32;
for (int i = 1; i < s.size(); i++) {
if (s[i] < 93) {
a[i] = s[i] + 32;
} else {
cout << s;
return 0;
}
}
} else {
for (int i = 0; i < s.size(); i++) {
{
if (s[i] < 93) {
a[i] = s[i] + 32;
} else {
cout << s;
return 0;
}
}
}
}
for (int i = 0; i < s.size(); i++) {
cout << a[i];
}
return 0;
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
char a[s.size() + 5];
if (s[0] >= 97) {
a[0] = s[0] - 32;
for (int i = 1; i < s.size(); i++) {
if (s[i] < 93) {
a[i] = s[i] + 32;
} else {
cout << s;
return 0;
}
}
} else {
for (int i = 0; i < s.size(); i++) {
{
if (s[i] < 93) {
a[i] = s[i] + 32;
} else {
cout << s;
return 0;
}
}
}
}
for (int i = 0; i < s.size(); i++) {
cout << a[i];
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
char u;
bool c = true;
cin >> s;
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
c = false;
}
}
if (c == true) {
for (int j = 0; j < s.length(); j++) {
if (islower(s[j]))
u = toupper(s[j]);
else
u = tolower(s[j]);
cout << u;
}
} else
cout << s;
return 0;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
char u;
bool c = true;
cin >> s;
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
c = false;
}
}
if (c == true) {
for (int j = 0; j < s.length(); j++) {
if (islower(s[j]))
u = toupper(s[j]);
else
u = tolower(s[j]);
cout << u;
}
} else
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool isCaps(string str) {
for (int i = 1; i < str.length(); ++i) {
if (!isupper(str[i])) {
return false;
}
}
return true;
}
int main() {
string word;
cin >> word;
if (isCaps(word)) {
if (isupper(word[0])) {
cout << (char)tolower(word[0]);
} else {
cout << (char)toupper(word[0]);
}
for (int i = 1; i < word.length(); ++i) {
cout << (char)tolower(word[i]);
}
} else {
cout << word;
}
}
| ### Prompt
Create a solution in CPP for the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool isCaps(string str) {
for (int i = 1; i < str.length(); ++i) {
if (!isupper(str[i])) {
return false;
}
}
return true;
}
int main() {
string word;
cin >> word;
if (isCaps(word)) {
if (isupper(word[0])) {
cout << (char)tolower(word[0]);
} else {
cout << (char)toupper(word[0]);
}
for (int i = 1; i < word.length(); ++i) {
cout << (char)tolower(word[i]);
}
} else {
cout << word;
}
}
``` |
#include <bits/stdc++.h>
char arr[100];
int record[100], bullyean, dafuq;
void solu() {
if (record[0] != 1) {
arr[0] = arr[0] - ' ';
} else
arr[0] = arr[0] + ' ';
for (int i = 1; i < strlen(arr); i++) {
if (record[i] == 1) {
arr[i] = arr[i] + ' ';
}
}
printf("%s\n", arr);
dafuq = 1;
}
int main() {
scanf("%[^\n]", arr);
for (int i = 1; i < strlen(arr); i++) {
if (int(arr[i]) > 96) bullyean = 1;
}
for (int i = 0; i < strlen(arr); i++) {
if (int(arr[i]) > 96)
record[i] = 0;
else
record[i] = 1;
}
if (bullyean == 0)
solu();
else if (dafuq == 0 && record[0] == 0 && bullyean == 0) {
solu();
} else
printf("%s\n", arr);
return 0;
}
| ### Prompt
Develop a solution in cpp to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
char arr[100];
int record[100], bullyean, dafuq;
void solu() {
if (record[0] != 1) {
arr[0] = arr[0] - ' ';
} else
arr[0] = arr[0] + ' ';
for (int i = 1; i < strlen(arr); i++) {
if (record[i] == 1) {
arr[i] = arr[i] + ' ';
}
}
printf("%s\n", arr);
dafuq = 1;
}
int main() {
scanf("%[^\n]", arr);
for (int i = 1; i < strlen(arr); i++) {
if (int(arr[i]) > 96) bullyean = 1;
}
for (int i = 0; i < strlen(arr); i++) {
if (int(arr[i]) > 96)
record[i] = 0;
else
record[i] = 1;
}
if (bullyean == 0)
solu();
else if (dafuq == 0 && record[0] == 0 && bullyean == 0) {
solu();
} else
printf("%s\n", arr);
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int m, n, i, j, len1;
char a[1000];
while (gets(a)) {
n = 0;
len1 = strlen(a);
for (i = 0; i < len1; i++) {
if (a[i] >= 'A' && a[i] <= 'Z') n++;
}
if (n == len1 - 1 && len1 != 1) {
if (a[0] >= 'a' && a[0] <= 'z') {
a[0] = a[0] - 32;
for (i = 1; i < len1; i++) a[i] = a[i] + 32;
}
}
if (n == 0 && len1 == 1) {
a[0] = a[0] - 32;
}
if (n == len1) {
for (i = 0; i < len1; i++) a[i] = a[i] + 32;
}
for (i = 0; i < len1; i++) {
printf("%c", a[i]);
}
printf("\n");
}
return 0;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int m, n, i, j, len1;
char a[1000];
while (gets(a)) {
n = 0;
len1 = strlen(a);
for (i = 0; i < len1; i++) {
if (a[i] >= 'A' && a[i] <= 'Z') n++;
}
if (n == len1 - 1 && len1 != 1) {
if (a[0] >= 'a' && a[0] <= 'z') {
a[0] = a[0] - 32;
for (i = 1; i < len1; i++) a[i] = a[i] + 32;
}
}
if (n == 0 && len1 == 1) {
a[0] = a[0] - 32;
}
if (n == len1) {
for (i = 0; i < len1; i++) a[i] = a[i] + 32;
}
for (i = 0; i < len1; i++) {
printf("%c", a[i]);
}
printf("\n");
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[1000];
int cunt = 0, x = 0;
gets(a);
int len = strlen(a);
if (a[0] >= 'a' && a[0] <= 'z') {
for (int i = 1; i < len; i++) {
if (a[i] >= 'A' && a[i] <= 'Z') {
x++;
} else {
break;
}
}
} else {
for (int i = 0; i < len; i++) {
if (a[i] >= 'A' && a[i] <= 'Z') {
cunt++;
} else {
break;
}
}
}
if (cunt == len) {
for (int i = 0; i < len; i++) {
a[i] = a[i] + 32;
}
} else if (x == len - 1) {
a[0] = a[0] - 32;
for (int i = 1; i < len; i++) {
a[i] = a[i] + 32;
}
}
puts(a);
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[1000];
int cunt = 0, x = 0;
gets(a);
int len = strlen(a);
if (a[0] >= 'a' && a[0] <= 'z') {
for (int i = 1; i < len; i++) {
if (a[i] >= 'A' && a[i] <= 'Z') {
x++;
} else {
break;
}
}
} else {
for (int i = 0; i < len; i++) {
if (a[i] >= 'A' && a[i] <= 'Z') {
cunt++;
} else {
break;
}
}
}
if (cunt == len) {
for (int i = 0; i < len; i++) {
a[i] = a[i] + 32;
}
} else if (x == len - 1) {
a[0] = a[0] - 32;
for (int i = 1; i < len; i++) {
a[i] = a[i] + 32;
}
}
puts(a);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char c[1000];
cin >> c;
int s = 32;
for (int i = 1; i < strlen(c); i++)
if (c[i] >= 'a') s = 0;
for (int i = 0; i < strlen(c); i++) putchar(s ^ c[i]);
}
| ### Prompt
Please create a solution in cpp to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
char c[1000];
cin >> c;
int s = 32;
for (int i = 1; i < strlen(c); i++)
if (c[i] >= 'a') s = 0;
for (int i = 0; i < strlen(c); i++) putchar(s ^ c[i]);
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool isbig(string s) {
for (int i = 0; i < s.length(); i++)
if (s[i] >= 'a') return false;
return true;
}
bool isbad(string s) {
if (s[0] < 'a') return false;
for (int i = 1; i < s.length(); i++)
if (s[i] >= 'a') return false;
return true;
}
char to_up(char a) { return (char)((int)a - (int)'A' + (int)'a'); }
int main() {
string s;
cin >> s;
if (isbig(s)) {
for (int i = 0; i < s.length(); i++) cout << to_up(s[i]);
cout << endl;
return 0;
}
if (isbad(s)) {
cout << (char)((int)s[0] - (int)'a' + (int)'A');
for (int i = 1; i < s.length(); i++) cout << to_up(s[i]);
cout << endl;
return 0;
}
cout << s << endl;
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool isbig(string s) {
for (int i = 0; i < s.length(); i++)
if (s[i] >= 'a') return false;
return true;
}
bool isbad(string s) {
if (s[0] < 'a') return false;
for (int i = 1; i < s.length(); i++)
if (s[i] >= 'a') return false;
return true;
}
char to_up(char a) { return (char)((int)a - (int)'A' + (int)'a'); }
int main() {
string s;
cin >> s;
if (isbig(s)) {
for (int i = 0; i < s.length(); i++) cout << to_up(s[i]);
cout << endl;
return 0;
}
if (isbad(s)) {
cout << (char)((int)s[0] - (int)'a' + (int)'A');
for (int i = 1; i < s.length(); i++) cout << to_up(s[i]);
cout << endl;
return 0;
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
char i, str[101], str2[101];
int count = 0;
scanf("%s", str);
int len = strlen(str);
for (i = 0; i < len; i++) {
str2[i] = str[i];
}
str2[i] = '\0';
if (str[0] >= 97 && str[0] <= 122) {
str[0] = str[0] - 32;
for (i = 1; i < len; i++) {
if ((str[i] >= 65 && str[i] <= 90)) {
str[i] = str[i] + 32;
count++;
}
}
if (count == (len - 1)) {
printf("%s\n", str);
return 0;
}
} else if (str[0] >= 65 && str[0] <= 90) {
for (i = 0; i < len; i++) {
if ((str[i] >= 65 && str[i] <= 90)) {
str[i] = str[i] + 32;
count++;
}
}
if (count == len) {
printf("%s\n", str);
return 0;
}
}
printf("%s\n", str2);
return 0;
}
| ### Prompt
Create a solution in CPP for the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
int main() {
char i, str[101], str2[101];
int count = 0;
scanf("%s", str);
int len = strlen(str);
for (i = 0; i < len; i++) {
str2[i] = str[i];
}
str2[i] = '\0';
if (str[0] >= 97 && str[0] <= 122) {
str[0] = str[0] - 32;
for (i = 1; i < len; i++) {
if ((str[i] >= 65 && str[i] <= 90)) {
str[i] = str[i] + 32;
count++;
}
}
if (count == (len - 1)) {
printf("%s\n", str);
return 0;
}
} else if (str[0] >= 65 && str[0] <= 90) {
for (i = 0; i < len; i++) {
if ((str[i] >= 65 && str[i] <= 90)) {
str[i] = str[i] + 32;
count++;
}
}
if (count == len) {
printf("%s\n", str);
return 0;
}
}
printf("%s\n", str2);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char x[100];
int i, c;
scanf("%s", x);
c = 0;
for (i = 0; i < strlen(x); ++i) {
if (islower(x[i]) == 0) c++;
}
if (c == strlen(x) || (c == strlen(x) - 1 && islower(x[0]))) {
for (i = 0; i < strlen(x); ++i) {
x[i] = tolower(x[i]);
}
if (strlen(x) - 1 == c) {
x[0] = toupper(x[0]);
}
}
cout << x << endl;
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
char x[100];
int i, c;
scanf("%s", x);
c = 0;
for (i = 0; i < strlen(x); ++i) {
if (islower(x[i]) == 0) c++;
}
if (c == strlen(x) || (c == strlen(x) - 1 && islower(x[0]))) {
for (i = 0; i < strlen(x); ++i) {
x[i] = tolower(x[i]);
}
if (strlen(x) - 1 == c) {
x[0] = toupper(x[0]);
}
}
cout << x << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int b = 0, c = 0;
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if ((int)s[i] < 97)
b++;
else
c++;
}
if ((int)s[0] >= 97 && c == 1 || c == 0) {
for (int i = 0; i < s.size(); i++) {
if ((int)s[i] < 97)
s[i] = char(s[i] + 32);
else
s[i] = char(s[i] - 32);
}
cout << s;
} else
cout << s;
return 0;
}
| ### Prompt
Please create a solution in cpp to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int b = 0, c = 0;
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if ((int)s[i] < 97)
b++;
else
c++;
}
if ((int)s[0] >= 97 && c == 1 || c == 0) {
for (int i = 0; i < s.size(); i++) {
if ((int)s[i] < 97)
s[i] = char(s[i] + 32);
else
s[i] = char(s[i] - 32);
}
cout << s;
} else
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string convert(string s) {
for (int i = 0; i < s.length(); i++) {
s[i] = isupper(s[i]) ? tolower(s[i]) : toupper(s[i]);
}
return s;
}
int main() {
string s;
cin >> s;
int upper = 0;
bool firstCap = false;
for (int i = 0; i < s.length(); i++) {
if (i == 0 && isupper(s[i])) {
firstCap = true;
}
if (isupper(s[i])) {
upper++;
}
}
if (upper == s.length() || (!firstCap && upper == s.length() - 1)) {
cout << convert(s) << endl;
} else {
cout << s << endl;
}
return 0;
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string convert(string s) {
for (int i = 0; i < s.length(); i++) {
s[i] = isupper(s[i]) ? tolower(s[i]) : toupper(s[i]);
}
return s;
}
int main() {
string s;
cin >> s;
int upper = 0;
bool firstCap = false;
for (int i = 0; i < s.length(); i++) {
if (i == 0 && isupper(s[i])) {
firstCap = true;
}
if (isupper(s[i])) {
upper++;
}
}
if (upper == s.length() || (!firstCap && upper == s.length() - 1)) {
cout << convert(s) << endl;
} else {
cout << s << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
int caps(const char* s) {
for (int i = 0; s[i]; i++) {
if (isupper(s[i])) goto next_1;
}
return 0;
next_1:
for (int i = 0; s[i]; i++) {
if (islower(s[i])) goto next_2;
}
return 1;
next_2:
for (int i = 1; s[i]; i++) {
if (islower(s[i])) return 2;
}
return 3;
}
int main() {
char s[100];
std::cin >> s;
int result = caps(s);
switch (result) {
case 0:
if (!s[1]) s[0] = toupper(s[0]);
break;
case 1:
for (int i = 0; s[i]; i++) {
s[i] = tolower(s[i]);
}
break;
case 2:
break;
case 3:
s[0] = toupper(s[0]);
for (int i = 1; s[i]; i++) s[i] = tolower(s[i]);
break;
}
std::cout << s << std::endl;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
int caps(const char* s) {
for (int i = 0; s[i]; i++) {
if (isupper(s[i])) goto next_1;
}
return 0;
next_1:
for (int i = 0; s[i]; i++) {
if (islower(s[i])) goto next_2;
}
return 1;
next_2:
for (int i = 1; s[i]; i++) {
if (islower(s[i])) return 2;
}
return 3;
}
int main() {
char s[100];
std::cin >> s;
int result = caps(s);
switch (result) {
case 0:
if (!s[1]) s[0] = toupper(s[0]);
break;
case 1:
for (int i = 0; s[i]; i++) {
s[i] = tolower(s[i]);
}
break;
case 2:
break;
case 3:
s[0] = toupper(s[0]);
for (int i = 1; s[i]; i++) s[i] = tolower(s[i]);
break;
}
std::cout << s << std::endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
int f = 0, a = 0, p = 0;
f = str.size();
int flag = 0;
int cx = 0;
cx = f - 1;
for (int i = 0; i < str.size(); i++) {
if (f > 1) {
if (str[i] >= 'A' && str[i] <= 'Z') {
a += 1;
flag = 1;
} else if (str[0] >= 'a' && str[0] <= 'z' && str[i + 1] >= 'A' &&
str[i + 1] <= 'Z') {
for (int i = 1; i < str.size(); i++) {
if (str[i] >= 'A' && str[i] <= 'Z') {
p += 1;
flag = 2;
}
}
}
}
}
for (int i = 0; i < str.size(); i++) {
if (f == 5 && str[0] >= 'a' && str[0] <= 'z' && str[1] >= 'A' &&
str[1] <= 'Z' && str[2] >= 'a' && str[2] <= 'z' && str[3] >= 'A' &&
str[3] <= 'Z' && str[4] >= 'a' && str[4] <= 'z') {
cout << str[i];
} else if (a != f && p != cx && f != 1) {
cout << str[i];
} else if (f == 1) {
if (str[0] >= 'a' && str[0] <= 'z') {
str[i] -= 32;
cout << str[i];
} else if (str[0] >= 'A' && str[0] <= 'Z') {
str[i] += 32;
cout << str[i];
}
} else if (a == f) {
str[i] += 32;
cout << str[i];
} else if (p = f - 1) {
str[0] -= 32;
str[i + 1] += 32;
cout << str[i];
}
}
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
int f = 0, a = 0, p = 0;
f = str.size();
int flag = 0;
int cx = 0;
cx = f - 1;
for (int i = 0; i < str.size(); i++) {
if (f > 1) {
if (str[i] >= 'A' && str[i] <= 'Z') {
a += 1;
flag = 1;
} else if (str[0] >= 'a' && str[0] <= 'z' && str[i + 1] >= 'A' &&
str[i + 1] <= 'Z') {
for (int i = 1; i < str.size(); i++) {
if (str[i] >= 'A' && str[i] <= 'Z') {
p += 1;
flag = 2;
}
}
}
}
}
for (int i = 0; i < str.size(); i++) {
if (f == 5 && str[0] >= 'a' && str[0] <= 'z' && str[1] >= 'A' &&
str[1] <= 'Z' && str[2] >= 'a' && str[2] <= 'z' && str[3] >= 'A' &&
str[3] <= 'Z' && str[4] >= 'a' && str[4] <= 'z') {
cout << str[i];
} else if (a != f && p != cx && f != 1) {
cout << str[i];
} else if (f == 1) {
if (str[0] >= 'a' && str[0] <= 'z') {
str[i] -= 32;
cout << str[i];
} else if (str[0] >= 'A' && str[0] <= 'Z') {
str[i] += 32;
cout << str[i];
}
} else if (a == f) {
str[i] += 32;
cout << str[i];
} else if (p = f - 1) {
str[0] -= 32;
str[i + 1] += 32;
cout << str[i];
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
char ch;
int flag = 0;
cin >> s;
int count = 0;
for (int i = 0; i < s.size(); i++) {
if (isupper(s[i])) {
if (i == 0) {
flag = 1;
}
count++;
}
}
if (flag == 0 && count == s.size() - 1) {
for (int i = 0; i < s.size(); i++) {
if (i == 0) {
ch = toupper(s[i]);
cout << ch;
} else {
ch = tolower(s[i]);
cout << ch;
}
}
} else if (count == s.size()) {
for (int i = 0; i < s.size(); i++) {
ch = tolower(s[i]);
cout << ch;
}
} else {
cout << s;
}
return 0;
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
char ch;
int flag = 0;
cin >> s;
int count = 0;
for (int i = 0; i < s.size(); i++) {
if (isupper(s[i])) {
if (i == 0) {
flag = 1;
}
count++;
}
}
if (flag == 0 && count == s.size() - 1) {
for (int i = 0; i < s.size(); i++) {
if (i == 0) {
ch = toupper(s[i]);
cout << ch;
} else {
ch = tolower(s[i]);
cout << ch;
}
}
} else if (count == s.size()) {
for (int i = 0; i < s.size(); i++) {
ch = tolower(s[i]);
cout << ch;
}
} else {
cout << s;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char word[100];
char newword[100];
char upperCase[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
char lowerCase[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int i = 0, k, j;
int flag1 = 0, flag2 = 0;
cin >> word;
while (word[i] != '\0') {
i++;
}
for (k = 0; k < 26; k++) {
if (word[0] == lowerCase[k]) {
flag1 = 1;
}
}
for (k = 1; k < i; k++) {
for (j = 0; j < 26; j++) {
if (word[k] == lowerCase[j]) {
flag2 = 1;
break;
}
}
}
if (flag2 == 1) {
for (k = 0; k < i; k++) {
newword[k] = word[k];
}
} else if (flag1 == 0 && flag2 == 0) {
for (k = 0; k < i; k++) {
for (j = 0; j < 26; j++) {
if (word[k] == upperCase[j]) {
newword[k] = lowerCase[j];
break;
}
}
}
} else {
for (k = 0; k < 26; k++) {
if (word[0] == lowerCase[k]) {
newword[0] = upperCase[k];
break;
} else if (word[0] == upperCase[k]) {
newword[0] = word[0];
break;
}
}
for (k = 1; k < i; k++) {
for (j = 0; j < 26; j++) {
if (word[k] == lowerCase[j]) {
newword[k] = word[k];
break;
} else if (word[k] == upperCase[j]) {
newword[k] = lowerCase[j];
break;
}
}
}
}
for (k = 0; k < i; k++) {
cout << newword[k];
}
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
char word[100];
char newword[100];
char upperCase[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
char lowerCase[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int i = 0, k, j;
int flag1 = 0, flag2 = 0;
cin >> word;
while (word[i] != '\0') {
i++;
}
for (k = 0; k < 26; k++) {
if (word[0] == lowerCase[k]) {
flag1 = 1;
}
}
for (k = 1; k < i; k++) {
for (j = 0; j < 26; j++) {
if (word[k] == lowerCase[j]) {
flag2 = 1;
break;
}
}
}
if (flag2 == 1) {
for (k = 0; k < i; k++) {
newword[k] = word[k];
}
} else if (flag1 == 0 && flag2 == 0) {
for (k = 0; k < i; k++) {
for (j = 0; j < 26; j++) {
if (word[k] == upperCase[j]) {
newword[k] = lowerCase[j];
break;
}
}
}
} else {
for (k = 0; k < 26; k++) {
if (word[0] == lowerCase[k]) {
newword[0] = upperCase[k];
break;
} else if (word[0] == upperCase[k]) {
newword[0] = word[0];
break;
}
}
for (k = 1; k < i; k++) {
for (j = 0; j < 26; j++) {
if (word[k] == lowerCase[j]) {
newword[k] = word[k];
break;
} else if (word[k] == upperCase[j]) {
newword[k] = lowerCase[j];
break;
}
}
}
}
for (k = 0; k < i; k++) {
cout << newword[k];
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string word, newWord = "";
cin >> word;
bool changeCase = false;
int counter = 0;
for (int x = 1; x < word.length(); x++) {
if (isupper(word[x])) counter++;
}
if (counter == (word.length() - 1)) {
if (isupper(word[0])) {
newWord = static_cast<char>(tolower(word[0]));
}
if (islower(word[0])) {
newWord = static_cast<char>(toupper(word[0]));
}
for (int x = 1; x < word.length(); x++) {
newWord += static_cast<char>(tolower(word[x]));
}
} else
newWord = word;
cout << newWord << endl;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string word, newWord = "";
cin >> word;
bool changeCase = false;
int counter = 0;
for (int x = 1; x < word.length(); x++) {
if (isupper(word[x])) counter++;
}
if (counter == (word.length() - 1)) {
if (isupper(word[0])) {
newWord = static_cast<char>(tolower(word[0]));
}
if (islower(word[0])) {
newWord = static_cast<char>(toupper(word[0]));
}
for (int x = 1; x < word.length(); x++) {
newWord += static_cast<char>(tolower(word[x]));
}
} else
newWord = word;
cout << newWord << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[101];
scanf("%s", s);
int len = strlen(s);
int upch = 0;
for (int i = 0; i < len; ++i) {
if (isupper(s[i])) ++upch;
}
bool flag = false;
if (upch == len)
flag = true;
else if (islower(s[0]) && len - upch == 1)
flag = true;
if (flag) {
for (int i = 0; i < len; ++i) {
if (isupper(s[i]))
putchar(s[i] + 32);
else
putchar(s[i] - 32);
}
} else {
puts(s);
}
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[101];
scanf("%s", s);
int len = strlen(s);
int upch = 0;
for (int i = 0; i < len; ++i) {
if (isupper(s[i])) ++upch;
}
bool flag = false;
if (upch == len)
flag = true;
else if (islower(s[0]) && len - upch == 1)
flag = true;
if (flag) {
for (int i = 0; i < len; ++i) {
if (isupper(s[i]))
putchar(s[i] + 32);
else
putchar(s[i] - 32);
}
} else {
puts(s);
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool change = true;
for (size_t i = 1; i < s.length(); ++i) {
if (s[i] >= 'a') {
change = false;
break;
}
}
if (change) {
for (size_t i = 0; i < s.length(); ++i) {
if (s[i] >= 'a') {
s[i] -= 32;
} else {
s[i] += 32;
}
}
}
cout << s << endl;
return 0;
}
| ### Prompt
Create a solution in Cpp for the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool change = true;
for (size_t i = 1; i < s.length(); ++i) {
if (s[i] >= 'a') {
change = false;
break;
}
}
if (change) {
for (size_t i = 0; i < s.length(); ++i) {
if (s[i] >= 'a') {
s[i] -= 32;
} else {
s[i] += 32;
}
}
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
char ara[100];
int i, length = 0, m = 2, n = 1;
scanf("%s", &ara);
for (i = 0; ara[i] != '\0'; i++) {
length++;
}
if (ara[0] >= 97 && ara[0] <= 122) {
if (ara[1] >= 97 && ara[1] <= 122) {
while (m < length) {
if (ara[m] >= 97 && ara[m] <= 122)
;
else {
break;
}
m++;
}
if (m == length) {
printf("%s", ara);
} else {
printf("%s", ara);
}
} else if (ara[1] >= 65 && ara[1] <= 90) {
while (m < length) {
if (ara[m] >= 65 && ara[m] <= 90)
;
else {
break;
}
m++;
}
if (m == length) {
ara[0] = 'A' + ara[0] - 'a';
while (n < length) {
if (ara[n] >= 65 && ara[n] <= 90) {
ara[n] = 'a' + ara[n] - 'A';
}
n++;
}
printf("%s", ara);
} else {
printf("%s", ara);
}
} else {
ara[0] = 'A' + ara[0] - 'a';
printf("%s", ara);
}
} else if (ara[0] >= 65 && ara[0] <= 90) {
if (ara[1] >= 65 && ara[1] <= 90) {
while (m < length) {
if (ara[m] >= 65 && ara[m] <= 90)
;
else {
break;
}
m++;
}
if (m == length) {
ara[0] = 'a' + ara[0] - 'A';
while (n < length) {
if (ara[n] >= 65 && ara[n] <= 90) {
ara[n] = 'a' + ara[n] - 'A';
}
n++;
}
printf("%s", ara);
} else {
printf("%s", ara);
}
} else if (ara[1] >= 97 && ara[1] <= 122) {
printf("%s", ara);
} else {
ara[0] = 'a' + ara[0] - 'A';
printf("%s", ara);
}
}
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
int main() {
char ara[100];
int i, length = 0, m = 2, n = 1;
scanf("%s", &ara);
for (i = 0; ara[i] != '\0'; i++) {
length++;
}
if (ara[0] >= 97 && ara[0] <= 122) {
if (ara[1] >= 97 && ara[1] <= 122) {
while (m < length) {
if (ara[m] >= 97 && ara[m] <= 122)
;
else {
break;
}
m++;
}
if (m == length) {
printf("%s", ara);
} else {
printf("%s", ara);
}
} else if (ara[1] >= 65 && ara[1] <= 90) {
while (m < length) {
if (ara[m] >= 65 && ara[m] <= 90)
;
else {
break;
}
m++;
}
if (m == length) {
ara[0] = 'A' + ara[0] - 'a';
while (n < length) {
if (ara[n] >= 65 && ara[n] <= 90) {
ara[n] = 'a' + ara[n] - 'A';
}
n++;
}
printf("%s", ara);
} else {
printf("%s", ara);
}
} else {
ara[0] = 'A' + ara[0] - 'a';
printf("%s", ara);
}
} else if (ara[0] >= 65 && ara[0] <= 90) {
if (ara[1] >= 65 && ara[1] <= 90) {
while (m < length) {
if (ara[m] >= 65 && ara[m] <= 90)
;
else {
break;
}
m++;
}
if (m == length) {
ara[0] = 'a' + ara[0] - 'A';
while (n < length) {
if (ara[n] >= 65 && ara[n] <= 90) {
ara[n] = 'a' + ara[n] - 'A';
}
n++;
}
printf("%s", ara);
} else {
printf("%s", ara);
}
} else if (ara[1] >= 97 && ara[1] <= 122) {
printf("%s", ara);
} else {
ara[0] = 'a' + ara[0] - 'A';
printf("%s", ara);
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace ::std;
int main() {
char g[1000], i;
cin >> g;
int k = 0;
if (g[0] >= 97 && g[0] <= 122) {
for (i = 1; g[i] != '\0'; i++)
if (g[i] >= 97 && g[i] <= 122) k = 1;
if (k == 0) {
for (i = 0; g[i] != '\0'; i++) {
if (g[i] >= 97 && g[i] <= 122)
g[i] = g[i] - 32;
else if (g[i] >= 65 && g[i] <= 90)
g[i] = g[i] + 32;
}
}
cout << "\n" << g;
} else if (g[0] >= 65 && g[0] <= 90) {
int d = 0;
for (i = 0; g[i] != '\0'; i++) {
if (g[i] >= 97 && g[i] <= 122) d = 1;
}
if (d == 0)
for (i = 0; g[i] != '\0'; i++) {
if (g[i] >= 97 && g[i] <= 122)
g[i] = g[i] - 32;
else if (g[i] >= 65 && g[i] <= 90)
g[i] = g[i] + 32;
}
cout << "\n" << g;
} else
cout << "\n" << g;
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace ::std;
int main() {
char g[1000], i;
cin >> g;
int k = 0;
if (g[0] >= 97 && g[0] <= 122) {
for (i = 1; g[i] != '\0'; i++)
if (g[i] >= 97 && g[i] <= 122) k = 1;
if (k == 0) {
for (i = 0; g[i] != '\0'; i++) {
if (g[i] >= 97 && g[i] <= 122)
g[i] = g[i] - 32;
else if (g[i] >= 65 && g[i] <= 90)
g[i] = g[i] + 32;
}
}
cout << "\n" << g;
} else if (g[0] >= 65 && g[0] <= 90) {
int d = 0;
for (i = 0; g[i] != '\0'; i++) {
if (g[i] >= 97 && g[i] <= 122) d = 1;
}
if (d == 0)
for (i = 0; g[i] != '\0'; i++) {
if (g[i] >= 97 && g[i] <= 122)
g[i] = g[i] - 32;
else if (g[i] >= 65 && g[i] <= 90)
g[i] = g[i] + 32;
}
cout << "\n" << g;
} else
cout << "\n" << g;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.length();
int i;
int flag = 0;
for (i = 1; i < n; i++) {
if (s[i] > 'Z') {
flag = 1;
}
}
if (flag == 0) {
for (i = 0; i < n; i++) {
if (s[i] > 'Z') {
s[i] = s[i] - 32;
} else {
s[i] = s[i] + 32;
}
}
}
cout << s;
return 0;
}
| ### Prompt
Please formulate a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.length();
int i;
int flag = 0;
for (i = 1; i < n; i++) {
if (s[i] > 'Z') {
flag = 1;
}
}
if (flag == 0) {
for (i = 0; i < n; i++) {
if (s[i] > 'Z') {
s[i] = s[i] - 32;
} else {
s[i] = s[i] + 32;
}
}
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int t = 0;
int t1 = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] <= 90 && s[i] >= 65) t++;
}
if (s[0] <= 124 && s[0] >= 97) t1++;
if (t == s.size())
transform(s.begin(), s.end(), s.begin(), ::tolower);
else if (t == s.size() - 1 && t1 == 1) {
s[0] = s[0] - 32;
transform(s.begin() + 1, s.end(), s.begin() + 1, ::tolower);
}
cout << s;
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int t = 0;
int t1 = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] <= 90 && s[i] >= 65) t++;
}
if (s[0] <= 124 && s[0] >= 97) t1++;
if (t == s.size())
transform(s.begin(), s.end(), s.begin(), ::tolower);
else if (t == s.size() - 1 && t1 == 1) {
s[0] = s[0] - 32;
transform(s.begin() + 1, s.end(), s.begin() + 1, ::tolower);
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool uppy(string &s) {
if (s.length() > 1)
for (int i = 1; i < (int)s.length(); i++)
if (islower(s[i])) return false;
return true;
}
void up(char &ch) {
if (islower(ch)) ch -= 32;
}
void low(char &ch) {
if (isupper(ch)) ch += 32;
}
void trans(string &s) {
if (uppy(s)) {
for (int i = 0; i < (int)s.length(); i++)
if (islower(s[i]))
up(s[i]);
else
low(s[i]);
}
cout << s;
}
int main() {
string s;
cin >> s;
trans(s);
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool uppy(string &s) {
if (s.length() > 1)
for (int i = 1; i < (int)s.length(); i++)
if (islower(s[i])) return false;
return true;
}
void up(char &ch) {
if (islower(ch)) ch -= 32;
}
void low(char &ch) {
if (isupper(ch)) ch += 32;
}
void trans(string &s) {
if (uppy(s)) {
for (int i = 0; i < (int)s.length(); i++)
if (islower(s[i]))
up(s[i]);
else
low(s[i]);
}
cout << s;
}
int main() {
string s;
cin >> s;
trans(s);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string str, answer;
int n;
int main() {
cin >> str;
if ('a' <= str[0] && 'z' >= str[0]) {
for (int i = 1; i < str.size(); i++) {
if ('a' <= str[i] && 'z' >= str[i]) {
n += 1;
}
}
} else {
for (int i = 0; i < str.size(); i++) {
if ('a' <= str[i] && 'z' >= str[i]) {
n += 1;
}
}
}
if (n == 0) {
for (int i = 0; i < str.size(); i++) {
if ('a' <= str[i] && 'z' >= str[i]) {
answer.push_back('A' + (str[i] - 'a'));
} else {
answer.push_back('a' + (str[i] - 'A'));
}
}
cout << answer;
} else {
cout << str;
}
return 0;
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string str, answer;
int n;
int main() {
cin >> str;
if ('a' <= str[0] && 'z' >= str[0]) {
for (int i = 1; i < str.size(); i++) {
if ('a' <= str[i] && 'z' >= str[i]) {
n += 1;
}
}
} else {
for (int i = 0; i < str.size(); i++) {
if ('a' <= str[i] && 'z' >= str[i]) {
n += 1;
}
}
}
if (n == 0) {
for (int i = 0; i < str.size(); i++) {
if ('a' <= str[i] && 'z' >= str[i]) {
answer.push_back('A' + (str[i] - 'a'));
} else {
answer.push_back('a' + (str[i] - 'A'));
}
}
cout << answer;
} else {
cout << str;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[1000];
cin >> a;
int n = strlen(a), i, up = 1;
for (i = 1; i < n; i++)
if (a[i] >= 'a' && a[i] <= 'z') up = 0;
if (up) {
for (i = 1; i < n; i++) a[i] = a[i] + 'a' - 'A';
if (a[0] >= 'A' && a[0] <= 'Z')
a[0] = a[0] + 'a' - 'A';
else
a[0] = a[0] + 'A' - 'a';
}
cout << a;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[1000];
cin >> a;
int n = strlen(a), i, up = 1;
for (i = 1; i < n; i++)
if (a[i] >= 'a' && a[i] <= 'z') up = 0;
if (up) {
for (i = 1; i < n; i++) a[i] = a[i] + 'a' - 'A';
if (a[0] >= 'A' && a[0] <= 'Z')
a[0] = a[0] + 'a' - 'A';
else
a[0] = a[0] + 'A' - 'a';
}
cout << a;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.length();
string f = s.substr(1, n - 1);
if (islower(s[0])) {
for (int i = 1; i < n; i++) {
if (isupper(s[i])) {
continue;
} else {
cout << s;
return 0;
}
}
cout << (char)toupper(s[0]);
for (int i = 1; i < n; i++) {
cout << (char)tolower(s[i]);
}
} else {
for (int i = 0; i < n; i++) {
if (isupper(s[i])) {
continue;
} else {
cout << s;
return 0;
}
}
for (int i = 0; i < n; i++) {
cout << (char)tolower(s[i]);
}
}
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.length();
string f = s.substr(1, n - 1);
if (islower(s[0])) {
for (int i = 1; i < n; i++) {
if (isupper(s[i])) {
continue;
} else {
cout << s;
return 0;
}
}
cout << (char)toupper(s[0]);
for (int i = 1; i < n; i++) {
cout << (char)tolower(s[i]);
}
} else {
for (int i = 0; i < n; i++) {
if (isupper(s[i])) {
continue;
} else {
cout << s;
return 0;
}
}
for (int i = 0; i < n; i++) {
cout << (char)tolower(s[i]);
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rang(
chrono::high_resolution_clock::now().time_since_epoch().count());
int64_t ceil_div(int64_t a, int64_t b) { return (a + b - 1) / b; }
long long power(long long x, long long y, long long p);
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long tc = 1, i, j, k;
while (tc--) {
string s;
cin >> s;
long long n = s.size();
long long cnt = 0;
for (long long i = 0; i < n; i++)
if (s[i] >= 65 && s[i] <= 90) cnt++;
if (cnt == n) {
for (long long i = 0; i < n; i++) cout << char(s[i] + 32);
} else if (cnt == n - 1 && s[0] >= 97) {
cout << char(s[0] - 32);
for (long long i = 1; i <= n - 1; i++) cout << char(s[i] + 32);
} else
cout << s;
}
}
long long power(long long x, long long y, long long p) {
int res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
| ### Prompt
In CPP, your task is to solve the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rang(
chrono::high_resolution_clock::now().time_since_epoch().count());
int64_t ceil_div(int64_t a, int64_t b) { return (a + b - 1) / b; }
long long power(long long x, long long y, long long p);
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long tc = 1, i, j, k;
while (tc--) {
string s;
cin >> s;
long long n = s.size();
long long cnt = 0;
for (long long i = 0; i < n; i++)
if (s[i] >= 65 && s[i] <= 90) cnt++;
if (cnt == n) {
for (long long i = 0; i < n; i++) cout << char(s[i] + 32);
} else if (cnt == n - 1 && s[0] >= 97) {
cout << char(s[0] - 32);
for (long long i = 1; i <= n - 1; i++) cout << char(s[i] + 32);
} else
cout << s;
}
}
long long power(long long x, long long y, long long p) {
int res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool is_all_upper_case_letters(string str) {
for (int i = 0; i < str.size(); i++) {
if (!isupper(str[i])) return false;
}
return true;
}
bool is_only_first_lower(string str) {
for (int i = 1; i < str.size(); i++) {
if (!isupper(str[i])) return false;
}
if (islower(str[0])) return true;
return false;
}
string to_lower(string SS) {
string str = SS;
for (int i = 0; i < str.size(); i++) {
if (isupper(str[i])) {
str[i] += 32;
} else {
str[i] -= 32;
}
}
return str;
}
int main() {
string str;
cin >> str;
if (is_all_upper_case_letters(str) && str.size() != 1) {
str = to_lower(str);
}
if (is_only_first_lower(str) && str.size() != 1) {
str = to_lower(str);
}
if (str.size() == 1) {
if (isupper(str[0]))
str[0] += 32;
else
str[0] -= 32;
}
cout << str << endl;
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool is_all_upper_case_letters(string str) {
for (int i = 0; i < str.size(); i++) {
if (!isupper(str[i])) return false;
}
return true;
}
bool is_only_first_lower(string str) {
for (int i = 1; i < str.size(); i++) {
if (!isupper(str[i])) return false;
}
if (islower(str[0])) return true;
return false;
}
string to_lower(string SS) {
string str = SS;
for (int i = 0; i < str.size(); i++) {
if (isupper(str[i])) {
str[i] += 32;
} else {
str[i] -= 32;
}
}
return str;
}
int main() {
string str;
cin >> str;
if (is_all_upper_case_letters(str) && str.size() != 1) {
str = to_lower(str);
}
if (is_only_first_lower(str) && str.size() != 1) {
str = to_lower(str);
}
if (str.size() == 1) {
if (isupper(str[0]))
str[0] += 32;
else
str[0] -= 32;
}
cout << str << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n, m, a;
vector<int> v;
string s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> s;
m = s.size();
for (int i = 0; i < s.size(); ++i)
if (s[i] >= 65 && s[i] <= 90) a++;
if (a == s.size()) {
for (int i = 0; i < s.size(); ++i) s[i] += 32;
cout << s;
return 0;
}
if (a == m - 1 && s[0] >= 97) {
for (int i = 1; i < s.size(); ++i) s[i] += 32;
s[0] -= 32;
cout << s;
return 0;
}
cout << s;
}
| ### Prompt
Please create a solution in CPP to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, m, a;
vector<int> v;
string s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> s;
m = s.size();
for (int i = 0; i < s.size(); ++i)
if (s[i] >= 65 && s[i] <= 90) a++;
if (a == s.size()) {
for (int i = 0; i < s.size(); ++i) s[i] += 32;
cout << s;
return 0;
}
if (a == m - 1 && s[0] >= 97) {
for (int i = 1; i < s.size(); ++i) s[i] += 32;
s[0] -= 32;
cout << s;
return 0;
}
cout << s;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, j, f = 0, t = 0, mini;
string s1, s2;
cin >> s1;
for (i = 1; i < s1.length(); i++) {
if (s1[i] < 92 && s1[i] > 64) f++;
}
if (f == s1.length() - 1) {
if (s1[0] < 92)
cout << (char)tolower(s1[0]);
else
cout << (char)toupper(s1[0]);
for (i = 1; i < s1.length(); i++) {
cout << (char)tolower(s1[i]);
}
} else
cout << s1;
return 0;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, j, f = 0, t = 0, mini;
string s1, s2;
cin >> s1;
for (i = 1; i < s1.length(); i++) {
if (s1[i] < 92 && s1[i] > 64) f++;
}
if (f == s1.length() - 1) {
if (s1[0] < 92)
cout << (char)tolower(s1[0]);
else
cout << (char)toupper(s1[0]);
for (i = 1; i < s1.length(); i++) {
cout << (char)tolower(s1[i]);
}
} else
cout << s1;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, L = 0;
char a[100];
cin >> a;
for (i = 1; i < strlen(a); i++) {
if (a[i] >= 65 && a[i] <= 90) {
L++;
}
}
if (L == strlen(a) - 1) {
for (i = 0; i < strlen(a); i++) {
if (a[i] >= 65 && a[i] <= 90)
a[i] = 97 + a[i] - 65;
else if (a[i] >= 97 && a[i] <= 122)
a[i] = 65 + a[i] - 97;
}
}
cout << a;
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, L = 0;
char a[100];
cin >> a;
for (i = 1; i < strlen(a); i++) {
if (a[i] >= 65 && a[i] <= 90) {
L++;
}
}
if (L == strlen(a) - 1) {
for (i = 0; i < strlen(a); i++) {
if (a[i] >= 65 && a[i] <= 90)
a[i] = 97 + a[i] - 65;
else if (a[i] >= 97 && a[i] <= 122)
a[i] = 65 + a[i] - 97;
}
}
cout << a;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string n;
int k = 0;
cin >> n;
if (n[0] <= 'Z') {
for (int i = 0; i < n.size(); i++) {
if (n[i] <= 'Z') k++;
}
if (k == n.size()) {
transform(n.begin(), n.end(), n.begin(), (int (*)(int))tolower);
cout << n;
} else
cout << n;
} else {
for (int i = 0; i < n.size(); i++) {
if (n[i] <= 'Z') k++;
}
if (k == n.size() - 1) {
transform(n.begin(), n.end(), n.begin(), (int (*)(int))tolower);
n.at(0) = toupper(n.at(0));
cout << n;
} else
cout << n;
}
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string n;
int k = 0;
cin >> n;
if (n[0] <= 'Z') {
for (int i = 0; i < n.size(); i++) {
if (n[i] <= 'Z') k++;
}
if (k == n.size()) {
transform(n.begin(), n.end(), n.begin(), (int (*)(int))tolower);
cout << n;
} else
cout << n;
} else {
for (int i = 0; i < n.size(); i++) {
if (n[i] <= 'Z') k++;
}
if (k == n.size() - 1) {
transform(n.begin(), n.end(), n.begin(), (int (*)(int))tolower);
n.at(0) = toupper(n.at(0));
cout << n;
} else
cout << n;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, d, n;
cin >> s;
for (int i = 1; i <= s.size(); i++) {
if (s[i] >= 97 && s[i] <= 122) {
cout << s;
return 0;
}
}
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 65 && s[i] <= 90) {
s[i] += 32;
} else if (s[i] >= 97 and s[i] <= 122)
s[i] -= 32;
}
cout << s;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, d, n;
cin >> s;
for (int i = 1; i <= s.size(); i++) {
if (s[i] >= 97 && s[i] <= 122) {
cout << s;
return 0;
}
}
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 65 && s[i] <= 90) {
s[i] += 32;
} else if (s[i] >= 97 and s[i] <= 122)
s[i] -= 32;
}
cout << s;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string word;
cin >> word;
int counter = 0, counter2 = 0, counter3 = 0, counter4 = 0;
for (int x = 0; x < word.length(); x++) {
if (isupper(word.at(x))) {
counter++;
}
}
for (int x = 0; x < word.length(); x++) {
if (x == 0) {
if (islower(word.at(x))) {
counter2++;
}
} else {
if (isupper(word.at(x))) {
counter3++;
}
}
}
if (counter == word.length()) {
for (int x = 0; x < word.length(); x++) {
word.at(x) = tolower(word.at(x));
}
cout << word;
} else if (counter2 == 1 && counter3 == word.length() - 1) {
for (int x = 0; x < word.length(); x++) {
if (x == 0)
word.at(x) = toupper(word.at(x));
else
word.at(x) = tolower(word.at(x));
}
cout << word;
} else
cout << word;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string word;
cin >> word;
int counter = 0, counter2 = 0, counter3 = 0, counter4 = 0;
for (int x = 0; x < word.length(); x++) {
if (isupper(word.at(x))) {
counter++;
}
}
for (int x = 0; x < word.length(); x++) {
if (x == 0) {
if (islower(word.at(x))) {
counter2++;
}
} else {
if (isupper(word.at(x))) {
counter3++;
}
}
}
if (counter == word.length()) {
for (int x = 0; x < word.length(); x++) {
word.at(x) = tolower(word.at(x));
}
cout << word;
} else if (counter2 == 1 && counter3 == word.length() - 1) {
for (int x = 0; x < word.length(); x++) {
if (x == 0)
word.at(x) = toupper(word.at(x));
else
word.at(x) = tolower(word.at(x));
}
cout << word;
} else
cout << word;
}
``` |
#include <bits/stdc++.h>
int main() {
int count = 0;
char s[100];
scanf("%s", s);
for (int i = 1; i < strlen(s); i++) {
if (isupper(s[i])) {
count++;
}
}
if (count == (strlen(s) - 1)) {
for (int i = 0; i < strlen(s); i++) {
s[i] = isupper(s[i]) ? tolower(s[i]) : toupper(s[i]);
}
}
printf("%s", s);
return 0;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int count = 0;
char s[100];
scanf("%s", s);
for (int i = 1; i < strlen(s); i++) {
if (isupper(s[i])) {
count++;
}
}
if (count == (strlen(s) - 1)) {
for (int i = 0; i < strlen(s); i++) {
s[i] = isupper(s[i]) ? tolower(s[i]) : toupper(s[i]);
}
}
printf("%s", s);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[10000];
cin >> s;
int uc = 0, n = strlen(s);
for (int i = 0; i < n; i++) {
if (s[i] < 'a') {
uc++;
}
}
if (s[0] >= 'a' && uc == n - 1) {
if (s[0] >= 'a') {
s[0] = s[0] - 32;
}
for (int i = 1; s[i] != '\0'; i++) {
if (s[i] < 'a') {
s[i] = s[i] + 32;
}
}
}
if (uc == n) {
for (int i = 0; s[i] != '\0'; i++) {
s[i] = s[i] + 32;
}
}
cout << s;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[10000];
cin >> s;
int uc = 0, n = strlen(s);
for (int i = 0; i < n; i++) {
if (s[i] < 'a') {
uc++;
}
}
if (s[0] >= 'a' && uc == n - 1) {
if (s[0] >= 'a') {
s[0] = s[0] - 32;
}
for (int i = 1; s[i] != '\0'; i++) {
if (s[i] < 'a') {
s[i] = s[i] + 32;
}
}
}
if (uc == n) {
for (int i = 0; s[i] != '\0'; i++) {
s[i] = s[i] + 32;
}
}
cout << s;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool t = 1;
int y;
for (int i = 0; s[i]; i++) {
if (islower(s[i])) {
t = 0;
y = i;
break;
}
}
if (t == 0 && y == 0) {
bool q = 0;
for (int i = 1; s[i]; i++) {
if (islower(s[i])) {
q = 1;
break;
}
}
if (!q) {
for (int i = 0; s[i]; i++) {
if (isupper(s[i])) {
s[i] = tolower(s[i]);
} else
s[i] = toupper(s[i]);
}
}
} else if (t == 1) {
for (int i = 0; s[i]; i++) {
if (isupper(s[i])) {
s[i] = tolower(s[i]);
} else
s[i] = toupper(s[i]);
}
}
cout << s << endl;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool t = 1;
int y;
for (int i = 0; s[i]; i++) {
if (islower(s[i])) {
t = 0;
y = i;
break;
}
}
if (t == 0 && y == 0) {
bool q = 0;
for (int i = 1; s[i]; i++) {
if (islower(s[i])) {
q = 1;
break;
}
}
if (!q) {
for (int i = 0; s[i]; i++) {
if (isupper(s[i])) {
s[i] = tolower(s[i]);
} else
s[i] = toupper(s[i]);
}
}
} else if (t == 1) {
for (int i = 0; s[i]; i++) {
if (isupper(s[i])) {
s[i] = tolower(s[i]);
} else
s[i] = toupper(s[i]);
}
}
cout << s << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int i, k, count = 0, flag = 0;
cin >> s;
for (i = 0; i < s.length(); i++) {
if (s[i] >= 65 && s[i] < 97) {
count++;
}
}
if (count == s.length()) {
for (i = 0; i < s.length(); i++) {
if (s[i] >= 65 && s[i] < 97) {
s[i] = s[i] + 32;
}
}
cout << s << endl;
exit(0);
} else if (count == s.length() - 1 && s[0] >= 97 && s[0] < 123) {
s[0] = s[0] - 32;
for (i = 1; i < s.length(); i++) {
s[i] = s[i] + 32;
}
cout << s << endl;
exit(0);
} else {
cout << s << endl;
}
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int i, k, count = 0, flag = 0;
cin >> s;
for (i = 0; i < s.length(); i++) {
if (s[i] >= 65 && s[i] < 97) {
count++;
}
}
if (count == s.length()) {
for (i = 0; i < s.length(); i++) {
if (s[i] >= 65 && s[i] < 97) {
s[i] = s[i] + 32;
}
}
cout << s << endl;
exit(0);
} else if (count == s.length() - 1 && s[0] >= 97 && s[0] < 123) {
s[0] = s[0] - 32;
for (i = 1; i < s.length(); i++) {
s[i] = s[i] + 32;
}
cout << s << endl;
exit(0);
} else {
cout << s << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
ifstream in("test.in");
ofstream out("r10.out");
int main() {
string s;
cin >> s;
bool ver = 1;
for (int i = 1; i < s.size(); i++) {
if (!isupper(s[i])) {
ver = 0;
break;
}
}
if (ver == 0)
cout << s;
else {
for (int i = 0; i < s.size(); i++) {
if (isupper(s[i]))
cout << char(tolower(s[i]));
else
cout << char(toupper(s[i]));
}
}
}
| ### Prompt
In cpp, your task is to solve the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
ifstream in("test.in");
ofstream out("r10.out");
int main() {
string s;
cin >> s;
bool ver = 1;
for (int i = 1; i < s.size(); i++) {
if (!isupper(s[i])) {
ver = 0;
break;
}
}
if (ver == 0)
cout << s;
else {
for (int i = 0; i < s.size(); i++) {
if (isupper(s[i]))
cout << char(tolower(s[i]));
else
cout << char(toupper(s[i]));
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int sum1 = 0, sum2 = 0, flag = 0, sum = 0;
string str;
cin >> str;
if (str[0] >= 97 && str[0] <= 123) {
for (int i = 1; i < str.size(); i++) {
if (str[i] >= 97 && str[i] <= 123) {
sum1++;
} else if (str[i] >= 65 && str[i] <= 91) {
sum2++;
}
}
if (sum2 == str.size() - 1) flag = 1;
if (flag == 1) {
cout << (char)(str[0] - 32);
for (int i = 1; i < str.size(); i++) {
if (str[i] >= 97 && str[i] <= 123)
cout << (char)(str[i] - 32);
else
cout << (char)(str[i] + 32);
}
} else
cout << str;
} else {
for (int i = 1; i < str.size(); i++) {
if (str[i] >= 65 && str[i] <= 91) sum++;
}
if (sum == str.size() - 1) flag = 1;
if (flag == 1) {
cout << (char)(str[0] + 32);
for (int i = 1; i < str.size(); i++) cout << (char)(str[i] + 32);
} else
cout << str;
}
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int sum1 = 0, sum2 = 0, flag = 0, sum = 0;
string str;
cin >> str;
if (str[0] >= 97 && str[0] <= 123) {
for (int i = 1; i < str.size(); i++) {
if (str[i] >= 97 && str[i] <= 123) {
sum1++;
} else if (str[i] >= 65 && str[i] <= 91) {
sum2++;
}
}
if (sum2 == str.size() - 1) flag = 1;
if (flag == 1) {
cout << (char)(str[0] - 32);
for (int i = 1; i < str.size(); i++) {
if (str[i] >= 97 && str[i] <= 123)
cout << (char)(str[i] - 32);
else
cout << (char)(str[i] + 32);
}
} else
cout << str;
} else {
for (int i = 1; i < str.size(); i++) {
if (str[i] >= 65 && str[i] <= 91) sum++;
}
if (sum == str.size() - 1) flag = 1;
if (flag == 1) {
cout << (char)(str[0] + 32);
for (int i = 1; i < str.size(); i++) cout << (char)(str[i] + 32);
} else
cout << str;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
char word[109];
bool chang = 1;
int main() {
cin >> word;
for (int i = 1; word[i] != '\0'; i++) {
if (word[i] >= 'A' && word[i] <= 'Z')
chang = 1;
else {
chang = 0;
break;
}
}
if (!chang)
cout << word << endl;
else {
if (word[0] >= 'A' && word[0] <= 'Z')
word[0] += 32;
else
word[0] -= 32;
for (int i = 1; word[i] != '\0'; i++) word[i] += 32;
cout << word << endl;
}
return 0;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char word[109];
bool chang = 1;
int main() {
cin >> word;
for (int i = 1; word[i] != '\0'; i++) {
if (word[i] >= 'A' && word[i] <= 'Z')
chang = 1;
else {
chang = 0;
break;
}
}
if (!chang)
cout << word << endl;
else {
if (word[0] >= 'A' && word[0] <= 'Z')
word[0] += 32;
else
word[0] -= 32;
for (int i = 1; word[i] != '\0'; i++) word[i] += 32;
cout << word << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int len, i, j;
cin >> s;
len = s.length();
j = 0;
if (s[0] >= 'a' && s[0] <= 'z') {
for (i = 1; i < len; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
j = 1;
}
if (i == len - 1 && j == 0) {
j = 2;
}
}
} else {
for (i = 1; i < len; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
j = 1;
}
}
}
if (j == 1) {
cout << s << endl;
} else if (j == 0) {
if (len == 1 && s[0] >= 'a' && s[0] <= 'z') {
s[0] = s[0] - 32;
cout << s << endl;
} else {
for (i = 0; i < len; i++) {
s[i] += 32;
}
cout << s << endl;
}
} else if (j == 2) {
if (s[0] >= 'a' && s[0] <= 'z') {
s[0] = s[0] - 32;
}
for (i = 1; i < len; i++) {
s[i] += 32;
}
cout << s << endl;
}
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int len, i, j;
cin >> s;
len = s.length();
j = 0;
if (s[0] >= 'a' && s[0] <= 'z') {
for (i = 1; i < len; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
j = 1;
}
if (i == len - 1 && j == 0) {
j = 2;
}
}
} else {
for (i = 1; i < len; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
j = 1;
}
}
}
if (j == 1) {
cout << s << endl;
} else if (j == 0) {
if (len == 1 && s[0] >= 'a' && s[0] <= 'z') {
s[0] = s[0] - 32;
cout << s << endl;
} else {
for (i = 0; i < len; i++) {
s[i] += 32;
}
cout << s << endl;
}
} else if (j == 2) {
if (s[0] >= 'a' && s[0] <= 'z') {
s[0] = s[0] - 32;
}
for (i = 1; i < len; i++) {
s[i] += 32;
}
cout << s << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int flg = 1;
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
flg = 0;
cout << s << endl;
return 0;
}
}
string s1 = s;
transform(s.begin(), s.end(), s.begin(), ::tolower);
if (islower(s1[0])) {
s[0] -= 32;
}
cout << s << endl;
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int flg = 1;
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
flg = 0;
cout << s << endl;
return 0;
}
}
string s1 = s;
transform(s.begin(), s.end(), s.begin(), ::tolower);
if (islower(s1[0])) {
s[0] -= 32;
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool allb;
char pk[101];
int main() {
while (~scanf("%s", &pk)) {
bool sc = false;
if (strlen(pk) == 1)
printf("%c\n",
pk[0] >= 'a' && pk[0] <= 'z' ? pk[0] - 0x20 : pk[0] + 0x20);
else {
for (int i = 1; i < strlen(pk); ++i) {
if (pk[i] >= 'A' && pk[i] <= 'Z')
sc = true;
else {
sc = false;
break;
}
}
if (sc) {
if (pk[0] >= 'a' && pk[0] <= 'z')
pk[0] -= 0x20;
else
pk[0] += 0x20;
for (int i = 1; i < strlen(pk); ++i) {
if (pk[i] >= 'A' && pk[i] <= 'Z') pk[i] += 0x20;
}
}
printf("%s\n", pk);
}
}
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool allb;
char pk[101];
int main() {
while (~scanf("%s", &pk)) {
bool sc = false;
if (strlen(pk) == 1)
printf("%c\n",
pk[0] >= 'a' && pk[0] <= 'z' ? pk[0] - 0x20 : pk[0] + 0x20);
else {
for (int i = 1; i < strlen(pk); ++i) {
if (pk[i] >= 'A' && pk[i] <= 'Z')
sc = true;
else {
sc = false;
break;
}
}
if (sc) {
if (pk[0] >= 'a' && pk[0] <= 'z')
pk[0] -= 0x20;
else
pk[0] += 0x20;
for (int i = 1; i < strlen(pk); ++i) {
if (pk[i] >= 'A' && pk[i] <= 'Z') pk[i] += 0x20;
}
}
printf("%s\n", pk);
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
char word[101];
int main() {
scanf("%100s", word);
if (strlen(word) == 1) {
if (word[0] >= 'A' && word[0] <= 'Z')
word[0] = tolower(word[0]);
else if (word[0] >= 'a' && word[0] <= 'z')
word[0] = toupper(word[0]);
printf("%s", word);
return 0;
}
bool check = false;
for (int i = 1; i < strlen(word); i++)
if (word[i] < 'A' || word[i] > 'Z') {
check = true;
break;
}
if (check)
printf("%s", word);
else {
for (int i = 1; i < strlen(word); i++) word[i] = tolower(word[i]);
if (word[0] >= 'A' && word[0] <= 'Z')
word[0] = tolower(word[0]);
else if (word[0] >= 'a' && word[0] <= 'z')
word[0] = toupper(word[0]);
printf("%s", word);
}
}
| ### Prompt
Please create a solution in Cpp to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char word[101];
int main() {
scanf("%100s", word);
if (strlen(word) == 1) {
if (word[0] >= 'A' && word[0] <= 'Z')
word[0] = tolower(word[0]);
else if (word[0] >= 'a' && word[0] <= 'z')
word[0] = toupper(word[0]);
printf("%s", word);
return 0;
}
bool check = false;
for (int i = 1; i < strlen(word); i++)
if (word[i] < 'A' || word[i] > 'Z') {
check = true;
break;
}
if (check)
printf("%s", word);
else {
for (int i = 1; i < strlen(word); i++) word[i] = tolower(word[i]);
if (word[0] >= 'A' && word[0] <= 'Z')
word[0] = tolower(word[0]);
else if (word[0] >= 'a' && word[0] <= 'z')
word[0] = toupper(word[0]);
printf("%s", word);
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool one(string s);
bool two(string s);
void c(string s);
void c2(string s);
int main() {
string str;
int i;
cin >> str;
if (one(str)) {
c(str);
} else if (two(str)) {
c2(str);
} else {
cout << str << endl;
}
return 0;
}
bool one(string s) {
int i;
int len = s.length();
for (i = 0; i < len; i++) {
if (i == 0) {
if (isupper(s[i])) {
return false;
}
} else {
if (!isupper(s[i])) return false;
}
}
return true;
}
bool two(string s) {
int i;
int len = s.length();
for (i = 0; i < len; i++) {
if (!isupper(s[i])) return false;
}
return true;
}
void c(string s) {
int i;
int len = s.length();
s[0] = toupper(s[0]);
for (i = 1; i < len; i++) {
s[i] = tolower(s[i]);
}
cout << s << endl;
}
void c2(string s) {
int i;
int len = s.length();
for (i = 0; i < len; i++) {
s[i] = tolower(s[i]);
}
cout << s << endl;
}
| ### Prompt
Construct a Cpp code solution to the problem outlined:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool one(string s);
bool two(string s);
void c(string s);
void c2(string s);
int main() {
string str;
int i;
cin >> str;
if (one(str)) {
c(str);
} else if (two(str)) {
c2(str);
} else {
cout << str << endl;
}
return 0;
}
bool one(string s) {
int i;
int len = s.length();
for (i = 0; i < len; i++) {
if (i == 0) {
if (isupper(s[i])) {
return false;
}
} else {
if (!isupper(s[i])) return false;
}
}
return true;
}
bool two(string s) {
int i;
int len = s.length();
for (i = 0; i < len; i++) {
if (!isupper(s[i])) return false;
}
return true;
}
void c(string s) {
int i;
int len = s.length();
s[0] = toupper(s[0]);
for (i = 1; i < len; i++) {
s[i] = tolower(s[i]);
}
cout << s << endl;
}
void c2(string s) {
int i;
int len = s.length();
for (i = 0; i < len; i++) {
s[i] = tolower(s[i]);
}
cout << s << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
char ch;
int s = str.size();
int flag1 = 0, flag2 = 0;
if (str[0] >= 'a' && str[0] <= 'z') {
flag1 = 1;
for (int i = 1; i < s; i++) {
if (str[i] >= 'a' && str[i] <= 'z') flag1 = 0;
}
} else if ((str[0] >= 'A' && str[0] <= 'Z')) {
flag2 = 1;
for (int i = 1; i < s; i++) {
if (str[i] >= 'a' && str[i] <= 'z') flag2 = 0;
}
}
if (s == 1) {
if (str[0] >= 'A' && str[0] <= 'Z') {
ch = str[0] + 32;
cout << ch << endl;
} else {
ch = str[0] - 32;
cout << ch << endl;
}
} else if (flag1) {
ch = str[0] - 32;
cout << ch;
for (int i = 1; i < s; i++) {
ch = str[i] + 32;
cout << ch;
}
} else if (flag2 == 1) {
for (int i = 0; i < s; i++) {
ch = str[i] + 32;
cout << ch;
}
} else
cout << str << endl;
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
char ch;
int s = str.size();
int flag1 = 0, flag2 = 0;
if (str[0] >= 'a' && str[0] <= 'z') {
flag1 = 1;
for (int i = 1; i < s; i++) {
if (str[i] >= 'a' && str[i] <= 'z') flag1 = 0;
}
} else if ((str[0] >= 'A' && str[0] <= 'Z')) {
flag2 = 1;
for (int i = 1; i < s; i++) {
if (str[i] >= 'a' && str[i] <= 'z') flag2 = 0;
}
}
if (s == 1) {
if (str[0] >= 'A' && str[0] <= 'Z') {
ch = str[0] + 32;
cout << ch << endl;
} else {
ch = str[0] - 32;
cout << ch << endl;
}
} else if (flag1) {
ch = str[0] - 32;
cout << ch;
for (int i = 1; i < s; i++) {
ch = str[i] + 32;
cout << ch;
}
} else if (flag2 == 1) {
for (int i = 0; i < s; i++) {
ch = str[i] + 32;
cout << ch;
}
} else
cout << str << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int l = 0, u = 0, n = s.size();
for (auto c : s) {
if (islower(c)) l++;
if (isupper(c)) u++;
}
if (u == n || (islower(s[0]) && u == n - 1)) {
for (auto &c : s) {
if (islower(c))
c = toupper(c);
else
c = tolower(c);
}
}
cout << s;
return 0;
}
| ### Prompt
Create a solution in Cpp for the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int l = 0, u = 0, n = s.size();
for (auto c : s) {
if (islower(c)) l++;
if (isupper(c)) u++;
}
if (u == n || (islower(s[0]) && u == n - 1)) {
for (auto &c : s) {
if (islower(c))
c = toupper(c);
else
c = tolower(c);
}
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long powermodm(long long x, long long n, long long M) {
long long result = 1;
while (n > 0) {
if (n % 2 == 1) result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
long long modInv(long long x, long long M) { return powermodm(x, M - 2, M); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
bool firstOn;
if (s[0] >= 'A' && s[0] <= 'Z') {
firstOn = true;
} else {
firstOn = false;
}
long long caps = 0;
for (long long i = 1; i < s.length(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
caps++;
}
}
if (caps == s.length() - 1) {
for (long long i = 0; i < s.length(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
cout << ((char)(s[i] + 32));
} else {
cout << ((char)(s[i] - 32));
}
}
} else {
cout << s;
}
cout << '\n';
return 0;
}
| ### Prompt
Create a solution in Cpp for the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long powermodm(long long x, long long n, long long M) {
long long result = 1;
while (n > 0) {
if (n % 2 == 1) result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
long long modInv(long long x, long long M) { return powermodm(x, M - 2, M); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
bool firstOn;
if (s[0] >= 'A' && s[0] <= 'Z') {
firstOn = true;
} else {
firstOn = false;
}
long long caps = 0;
for (long long i = 1; i < s.length(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
caps++;
}
}
if (caps == s.length() - 1) {
for (long long i = 0; i < s.length(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
cout << ((char)(s[i] + 32));
} else {
cout << ((char)(s[i] - 32));
}
}
} else {
cout << s;
}
cout << '\n';
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, s2;
int c = 0;
cin >> s;
for (int i = 1; i < s.size(); i++) {
if (isupper(s[i])) c++;
}
if (c == s.size() - 1) {
for (int i = 0; i < s.size(); i++) {
if (isupper(s[i]))
s[i] = tolower(s[i]);
else
s[i] = toupper(s[i]);
}
cout << s << endl;
} else if (c < s.size() - 1)
cout << s;
}
| ### Prompt
Generate a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, s2;
int c = 0;
cin >> s;
for (int i = 1; i < s.size(); i++) {
if (isupper(s[i])) c++;
}
if (c == s.size() - 1) {
for (int i = 0; i < s.size(); i++) {
if (isupper(s[i]))
s[i] = tolower(s[i]);
else
s[i] = toupper(s[i]);
}
cout << s << endl;
} else if (c < s.size() - 1)
cout << s;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0;
string A;
cin >> A;
if (A[0] < 97) {
for (int i = 0; i < A.size(); i++) {
if (A[i] < 97) n++;
}
if (n == A.size()) {
for (int i = 0; i < A.size(); i++) A[i] += 32;
cout << A;
} else
cout << A;
} else {
for (int i = 1; i < A.size(); i++) {
if (A[i] < 97) n++;
}
if (n == A.size() - 1) {
A[0] -= 32;
for (int i = 1; i < A.size(); i++) A[i] += 32;
cout << A;
} else
cout << A;
}
}
| ### Prompt
Please create a solution in CPP to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0;
string A;
cin >> A;
if (A[0] < 97) {
for (int i = 0; i < A.size(); i++) {
if (A[i] < 97) n++;
}
if (n == A.size()) {
for (int i = 0; i < A.size(); i++) A[i] += 32;
cout << A;
} else
cout << A;
} else {
for (int i = 1; i < A.size(); i++) {
if (A[i] < 97) n++;
}
if (n == A.size() - 1) {
A[0] -= 32;
for (int i = 1; i < A.size(); i++) A[i] += 32;
cout << A;
} else
cout << A;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c, m;
string s;
cin >> s;
n = s.length();
int i = 0;
for (int k = 0; k < n; k++)
if (isupper(s[k])) i++;
if (i == n) {
for (int k = 0; k < n; k++) s[k] = tolower(s[k]);
cout << s;
return 0;
}
if ((i == n - 1) && (islower(s[0]))) {
s[0] = toupper(s[0]);
for (int k = 1; k < n; k++) s[k] = tolower(s[k]);
cout << s;
return 0;
}
cout << s;
return 0;
}
| ### Prompt
Please formulate a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c, m;
string s;
cin >> s;
n = s.length();
int i = 0;
for (int k = 0; k < n; k++)
if (isupper(s[k])) i++;
if (i == n) {
for (int k = 0; k < n; k++) s[k] = tolower(s[k]);
cout << s;
return 0;
}
if ((i == n - 1) && (islower(s[0]))) {
s[0] = toupper(s[0]);
for (int k = 1; k < n; k++) s[k] = tolower(s[k]);
cout << s;
return 0;
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
bool low = 0;
string s;
cin >> s;
for (int i = 1; i < s.length(); ++i) {
if (s[i] > 'Z') {
low = 1;
}
}
if (low) {
cout << s;
} else {
if (s[0] > 'Z') {
cout << (char)toupper(s[0]);
} else {
cout << (char)tolower(s[0]);
}
for (int i = 1; i < s.length(); ++i) {
cout << (char)tolower(s[i]);
}
}
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
bool low = 0;
string s;
cin >> s;
for (int i = 1; i < s.length(); ++i) {
if (s[i] > 'Z') {
low = 1;
}
}
if (low) {
cout << s;
} else {
if (s[0] > 'Z') {
cout << (char)toupper(s[0]);
} else {
cout << (char)tolower(s[0]);
}
for (int i = 1; i < s.length(); ++i) {
cout << (char)tolower(s[i]);
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
signed main() {
string str;
int i, countc = 0;
cin >> str;
for (i = 0; i < str.length(); i++) {
if (int(str[i]) >= 65 && int(str[i]) < 97) {
countc++;
}
}
if (countc == str.length()) {
for (i = 0; i < str.length(); i++) {
if (int(str[i]) >= 97) {
str[i] = char(int(str[i] - 32));
} else {
str[i] = char(int(str[i]) + 32);
}
}
} else if (countc == str.length() - 1 && int(str[0]) >= 97) {
for (i = 0; i < str.length(); i++) {
if (int(str[i]) >= 97) {
str[i] = char(int(str[i] - 32));
} else {
str[i] = char(int(str[i]) + 32);
}
}
}
cout << str;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
signed main() {
string str;
int i, countc = 0;
cin >> str;
for (i = 0; i < str.length(); i++) {
if (int(str[i]) >= 65 && int(str[i]) < 97) {
countc++;
}
}
if (countc == str.length()) {
for (i = 0; i < str.length(); i++) {
if (int(str[i]) >= 97) {
str[i] = char(int(str[i] - 32));
} else {
str[i] = char(int(str[i]) + 32);
}
}
} else if (countc == str.length() - 1 && int(str[0]) >= 97) {
for (i = 0; i < str.length(); i++) {
if (int(str[i]) >= 97) {
str[i] = char(int(str[i] - 32));
} else {
str[i] = char(int(str[i]) + 32);
}
}
}
cout << str;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, sum = 0, c = 0;
string s;
cin >> s;
for (i = 0; i < s.length(); i++) {
if (s[i] >= 65 && s[i] <= 90) sum++;
}
if (sum == s.length()) {
transform(s.begin(), s.end(), s.begin(), ::tolower);
cout << s << endl;
return 0;
}
for (i = 1; i < s.length(); i++) {
if (s[i] >= 65 && s[i] <= 90) c++;
}
if (c == s.length() - 1) {
s[0] = toupper(s[0]);
transform(s.begin() + 1, s.end(), s.begin() + 1, ::tolower);
cout << s << endl;
return 0;
}
cout << s << endl;
}
| ### Prompt
Generate a cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, sum = 0, c = 0;
string s;
cin >> s;
for (i = 0; i < s.length(); i++) {
if (s[i] >= 65 && s[i] <= 90) sum++;
}
if (sum == s.length()) {
transform(s.begin(), s.end(), s.begin(), ::tolower);
cout << s << endl;
return 0;
}
for (i = 1; i < s.length(); i++) {
if (s[i] >= 65 && s[i] <= 90) c++;
}
if (c == s.length() - 1) {
s[0] = toupper(s[0]);
transform(s.begin() + 1, s.end(), s.begin() + 1, ::tolower);
cout << s << endl;
return 0;
}
cout << s << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int d = 'a' - 'A';
void init() {}
int main() {
init();
string str;
cin >> str;
for (int i = 1; i < str.length(); ++i) {
if (str[i] >= 'a') {
cout << str;
return 0;
}
}
if (str[0] >= 'a')
str[0] -= d;
else
str[0] += d;
for (int i = 1; i < str.length(); ++i) str[i] += d;
cout << str << endl;
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int d = 'a' - 'A';
void init() {}
int main() {
init();
string str;
cin >> str;
for (int i = 1; i < str.length(); ++i) {
if (str[i] >= 'a') {
cout << str;
return 0;
}
}
if (str[0] >= 'a')
str[0] -= d;
else
str[0] += d;
for (int i = 1; i < str.length(); ++i) str[i] += d;
cout << str << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int cont = 1;
if (s.size() > 1) {
for (int i = 1; i < s.size(); i++) {
if (isupper(s[i])) {
cont++;
} else
continue;
}
if (cont == s.size()) {
if (islower(s[0])) {
s[0] = toupper(s[0]);
for (int i = 1; i < s.size(); i++) s[i] = tolower(s[i]);
cout << s;
} else {
s[0] = tolower(s[0]);
for (int i = 1; i < s.size(); i++) s[i] = tolower(s[i]);
cout << s;
}
} else
cout << s;
} else {
(islower(s[0]) ? s[0] = toupper(s[0]) : s[0] = tolower(s[0]));
cout << s;
}
return 0;
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int cont = 1;
if (s.size() > 1) {
for (int i = 1; i < s.size(); i++) {
if (isupper(s[i])) {
cont++;
} else
continue;
}
if (cont == s.size()) {
if (islower(s[0])) {
s[0] = toupper(s[0]);
for (int i = 1; i < s.size(); i++) s[i] = tolower(s[i]);
cout << s;
} else {
s[0] = tolower(s[0]);
for (int i = 1; i < s.size(); i++) s[i] = tolower(s[i]);
cout << s;
}
} else
cout << s;
} else {
(islower(s[0]) ? s[0] = toupper(s[0]) : s[0] = tolower(s[0]));
cout << s;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int i, j;
int main() {
string s;
cin >> s;
for (; s[i] != '\0'; i++)
if (s[i] >= 'A' && s[i] <= 'Z') j++;
if (j == s.size() - 1 && s[0] >= 'a' && s[0] <= 'z') {
s[0] = toupper(s[0]);
for (i = 1; s[i] != '\0'; i++) s[i] = tolower(s[i]);
}
if (j == s.size())
for (i = 0; s[i] != '\0'; i++) s[i] = tolower(s[i]);
cout << s << endl;
return 0;
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int i, j;
int main() {
string s;
cin >> s;
for (; s[i] != '\0'; i++)
if (s[i] >= 'A' && s[i] <= 'Z') j++;
if (j == s.size() - 1 && s[0] >= 'a' && s[0] <= 'z') {
s[0] = toupper(s[0]);
for (i = 1; s[i] != '\0'; i++) s[i] = tolower(s[i]);
}
if (j == s.size())
for (i = 0; s[i] != '\0'; i++) s[i] = tolower(s[i]);
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 10000;
template <class T>
bool umin(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
bool umax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
template <class A>
void read(vector<A>& v);
template <class A, size_t S>
void read(array<A, S>& a);
template <class T>
void read(T& x) {
cin >> x;
}
void read(double& d) {
string t;
read(t);
d = stod(t);
}
void read(long double& d) {
string t;
read(t);
d = stold(t);
}
template <class H, class... T>
void read(H& h, T&... t) {
read(h);
read(t...);
}
template <class A>
void read(vector<A>& x) {
for (auto& a : x) read(a);
}
template <class A, size_t S>
void read(array<A, S>& x) {
for (auto& a : x) read(a);
}
string to_string(char c) { return string(1, c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return string(s); }
string to_string(string s) { return s; }
string to_string(vector<bool> v) {
string res;
for (long long i = (0);
(1) > 0 ? i < ((long long)(v).size()) : i > ((long long)(v).size());
i += (1))
res += char('0' + v[i]);
return res;
}
template <size_t S>
string to_string(bitset<S> b) {
string res;
for (long long i = (0); (1) > 0 ? i < (S) : i > (S); i += (1))
res += char('0' + b[i]);
return res;
}
template <class T>
string to_string(T v) {
bool f = 1;
string res;
for (auto& x : v) {
if (!f) res += ' ';
f = 0;
res += to_string(x);
}
return res;
}
template <class A, class B>
void write(pair<A, B> x) {
cout << to_string(x.first) << ' ' << to_string(x.second);
}
template <class A>
void write(A x) {
cout << to_string(x);
}
template <class H, class... T>
void write(const H& h, const T&... t) {
write(h);
write(t...);
}
void print() { write("\n"); }
template <class H, class... T>
void print(const H& h, const T&... t) {
write(h);
if (sizeof...(t)) write(' ');
print(t...);
}
void DBG() { cerr << "]" << endl; }
template <class H, class... T>
void DBG(H h, T... t) {
cerr << to_string(h);
if (sizeof...(t)) cerr << ", ";
DBG(t...);
}
void fast_io() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void file_io(string taskname) {
string fin = taskname + ".in";
string fout = taskname + ".out";
const char* FIN = fin.c_str();
const char* FOUT = fout.c_str();
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
fast_io();
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long get_random() {
static uniform_int_distribution<long long> dist(0, 1e9 + 6);
return dist(rng);
}
template <class T>
void make_unique(T& v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
}
void lower(string& s) { transform(s.begin(), s.end(), s.begin(), ::tolower); }
void upper(string& s) { transform(s.begin(), s.end(), s.begin(), ::toupper); }
using namespace std;
long long dx[] = {0, 0, 1, -1};
long long dy[] = {1, -1, 0, 0};
bool app1(string s) {
long long i;
bool res = true;
for (i = 0; i < (long long)(s).size(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
} else {
res = false;
break;
}
}
return res;
}
bool app2(string s) {
string str = s.substr(1);
if (s[0] >= 'a' && s[0] <= 'z' && app1(str)) {
return true;
}
return false;
}
signed main() {
fast_io();
string s;
read(s);
if (app1(s) || app2(s)) {
for (auto& x : s) {
if (x >= 'a' && x <= 'z') {
x -= ('a' - 'A');
} else {
x += ('a' - 'A');
}
}
}
print(s);
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long mod = 10000;
template <class T>
bool umin(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
bool umax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
template <class A>
void read(vector<A>& v);
template <class A, size_t S>
void read(array<A, S>& a);
template <class T>
void read(T& x) {
cin >> x;
}
void read(double& d) {
string t;
read(t);
d = stod(t);
}
void read(long double& d) {
string t;
read(t);
d = stold(t);
}
template <class H, class... T>
void read(H& h, T&... t) {
read(h);
read(t...);
}
template <class A>
void read(vector<A>& x) {
for (auto& a : x) read(a);
}
template <class A, size_t S>
void read(array<A, S>& x) {
for (auto& a : x) read(a);
}
string to_string(char c) { return string(1, c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return string(s); }
string to_string(string s) { return s; }
string to_string(vector<bool> v) {
string res;
for (long long i = (0);
(1) > 0 ? i < ((long long)(v).size()) : i > ((long long)(v).size());
i += (1))
res += char('0' + v[i]);
return res;
}
template <size_t S>
string to_string(bitset<S> b) {
string res;
for (long long i = (0); (1) > 0 ? i < (S) : i > (S); i += (1))
res += char('0' + b[i]);
return res;
}
template <class T>
string to_string(T v) {
bool f = 1;
string res;
for (auto& x : v) {
if (!f) res += ' ';
f = 0;
res += to_string(x);
}
return res;
}
template <class A, class B>
void write(pair<A, B> x) {
cout << to_string(x.first) << ' ' << to_string(x.second);
}
template <class A>
void write(A x) {
cout << to_string(x);
}
template <class H, class... T>
void write(const H& h, const T&... t) {
write(h);
write(t...);
}
void print() { write("\n"); }
template <class H, class... T>
void print(const H& h, const T&... t) {
write(h);
if (sizeof...(t)) write(' ');
print(t...);
}
void DBG() { cerr << "]" << endl; }
template <class H, class... T>
void DBG(H h, T... t) {
cerr << to_string(h);
if (sizeof...(t)) cerr << ", ";
DBG(t...);
}
void fast_io() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void file_io(string taskname) {
string fin = taskname + ".in";
string fout = taskname + ".out";
const char* FIN = fin.c_str();
const char* FOUT = fout.c_str();
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
fast_io();
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long get_random() {
static uniform_int_distribution<long long> dist(0, 1e9 + 6);
return dist(rng);
}
template <class T>
void make_unique(T& v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
}
void lower(string& s) { transform(s.begin(), s.end(), s.begin(), ::tolower); }
void upper(string& s) { transform(s.begin(), s.end(), s.begin(), ::toupper); }
using namespace std;
long long dx[] = {0, 0, 1, -1};
long long dy[] = {1, -1, 0, 0};
bool app1(string s) {
long long i;
bool res = true;
for (i = 0; i < (long long)(s).size(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
} else {
res = false;
break;
}
}
return res;
}
bool app2(string s) {
string str = s.substr(1);
if (s[0] >= 'a' && s[0] <= 'z' && app1(str)) {
return true;
}
return false;
}
signed main() {
fast_io();
string s;
read(s);
if (app1(s) || app2(s)) {
for (auto& x : s) {
if (x >= 'a' && x <= 'z') {
x -= ('a' - 'A');
} else {
x += ('a' - 'A');
}
}
}
print(s);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int cnt1 = 0, cnt2 = 0;
int l = s.length();
char c;
for (int i = 0; i < l; i++) {
if (isupper(s[i])) cnt1++;
if (islower(s[i])) cnt2++;
}
if (cnt1 == l) {
for (int i = 0; i < l; i++) {
c = s[i];
c = tolower(c);
cout << c;
}
} else if (cnt2 == 1 && islower(s[0])) {
c = s[0];
c = toupper(c);
cout << c;
for (int i = 1; i < l; i++) {
c = s[i];
c = tolower(c);
cout << c;
}
} else {
for (int i = 0; i < l; i++) cout << s[i];
}
return 0;
}
| ### Prompt
Please formulate a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int cnt1 = 0, cnt2 = 0;
int l = s.length();
char c;
for (int i = 0; i < l; i++) {
if (isupper(s[i])) cnt1++;
if (islower(s[i])) cnt2++;
}
if (cnt1 == l) {
for (int i = 0; i < l; i++) {
c = s[i];
c = tolower(c);
cout << c;
}
} else if (cnt2 == 1 && islower(s[0])) {
c = s[0];
c = toupper(c);
cout << c;
for (int i = 1; i < l; i++) {
c = s[i];
c = tolower(c);
cout << c;
}
} else {
for (int i = 0; i < l; i++) cout << s[i];
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
bool temp = true;
cin >> s;
for (int i = 1; i < s.size(); ++i) {
if (!isupper(s[i])) temp = false;
}
if (temp) {
for (char i : s) {
if (isupper(i))
putchar(tolower(i));
else
putchar(toupper(i));
}
} else
cout << s;
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
bool temp = true;
cin >> s;
for (int i = 1; i < s.size(); ++i) {
if (!isupper(s[i])) temp = false;
}
if (temp) {
for (char i : s) {
if (isupper(i))
putchar(tolower(i));
else
putchar(toupper(i));
}
} else
cout << s;
}
``` |
#include <bits/stdc++.h>
int main() {
int i, j, top = 0;
char dizi[101];
scanf("%s", dizi);
for (i = 1; i < strlen(dizi); i++)
if (dizi[i] <= 'Z' && dizi[i] >= 'A') top++;
if (top == strlen(dizi) - 1) {
if (dizi[0] <= 'z' && dizi[0] >= 'a')
dizi[0] = dizi[0] + 'A' - 'a';
else
dizi[0] = tolower(dizi[0]);
for (i = 1; i < strlen(dizi); i++)
if (dizi[i] <= 'Z' && dizi[i] >= 'A') dizi[i] = dizi[i] - 'A' + 'a';
}
for (i = 0; i < strlen(dizi); i++) printf("%c", dizi[i]);
return 0;
}
| ### Prompt
Please formulate a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int i, j, top = 0;
char dizi[101];
scanf("%s", dizi);
for (i = 1; i < strlen(dizi); i++)
if (dizi[i] <= 'Z' && dizi[i] >= 'A') top++;
if (top == strlen(dizi) - 1) {
if (dizi[0] <= 'z' && dizi[0] >= 'a')
dizi[0] = dizi[0] + 'A' - 'a';
else
dizi[0] = tolower(dizi[0]);
for (i = 1; i < strlen(dizi); i++)
if (dizi[i] <= 'Z' && dizi[i] >= 'A') dizi[i] = dizi[i] - 'A' + 'a';
}
for (i = 0; i < strlen(dizi); i++) printf("%c", dizi[i]);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n = 0;
string s;
getline(cin, s);
if (s.length() == 1) {
n = int(s[0]);
if (n < 97)
s[0] = char(n + 32);
else
s[0] = char(n - 32);
} else {
for (i = 1; i < s.length(); i++) {
if (int(s[i]) < 97) n++;
}
if (n == (s.length()) - 1) {
for (i = 0; i < s.length(); i++) {
n = int(s[i]);
if (n < 97)
s[i] = char(n + 32);
else
s[i] = char(n - 32);
}
}
}
cout << s;
}
| ### Prompt
Create a solution in Cpp for the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n = 0;
string s;
getline(cin, s);
if (s.length() == 1) {
n = int(s[0]);
if (n < 97)
s[0] = char(n + 32);
else
s[0] = char(n - 32);
} else {
for (i = 1; i < s.length(); i++) {
if (int(s[i]) < 97) n++;
}
if (n == (s.length()) - 1) {
for (i = 0; i < s.length(); i++) {
n = int(s[i]);
if (n < 97)
s[i] = char(n + 32);
else
s[i] = char(n - 32);
}
}
}
cout << s;
}
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.