output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d = 0;
char s[105];
cin >> s;
a = strlen(s);
for (b = 1; b < a; b++) {
if (s[b] >= 65 && s[b] <= 90) {
d++;
}
}
if (d == a - 1) {
for (b = 0; b < a; b++) {
if (s[b] >= 65 && s[b] <= 90) {
s[b] += (97 - 65);
} else
s[b] -= (97 - 65);
}
cout << s << endl;
} else
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() {
int a, b, c, d = 0;
char s[105];
cin >> s;
a = strlen(s);
for (b = 1; b < a; b++) {
if (s[b] >= 65 && s[b] <= 90) {
d++;
}
}
if (d == a - 1) {
for (b = 0; b < a; b++) {
if (s[b] >= 65 && s[b] <= 90) {
s[b] += (97 - 65);
} else
s[b] -= (97 - 65);
}
cout << s << endl;
} else
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
bool b = 1;
string s;
cin >> s;
for (int i = 1; i < s.size(); i++)
if (s[i] >= 'a') b = 0;
if (b) {
for (int i = 0; i < s.size(); i++)
if (s[i] >= 'a')
s[i] -= 32;
else if (s[i] <= 'a')
s[i] += 32;
}
cout << s;
}
| ### 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() {
bool b = 1;
string s;
cin >> s;
for (int i = 1; i < s.size(); i++)
if (s[i] >= 'a') b = 0;
if (b) {
for (int i = 0; i < s.size(); i++)
if (s[i] >= 'a')
s[i] -= 32;
else if (s[i] <= 'a')
s[i] += 32;
}
cout << s;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[205];
while (cin >> str) {
int len = strlen(str);
int cnt = 0;
for (int i = 0; i < len; i++)
if (isupper(str[i])) cnt++;
if (cnt == len || (islower(str[0]) && cnt == len - 1)) {
for (int i = 0; i < len; i++) {
if (isupper(str[i]))
str[i] = tolower(str[i]);
else
str[i] = toupper(str[i]);
}
}
cout << str << 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 str[205];
while (cin >> str) {
int len = strlen(str);
int cnt = 0;
for (int i = 0; i < len; i++)
if (isupper(str[i])) cnt++;
if (cnt == len || (islower(str[0]) && cnt == len - 1)) {
for (int i = 0; i < len; i++) {
if (isupper(str[i]))
str[i] = tolower(str[i]);
else
str[i] = toupper(str[i]);
}
}
cout << str << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
char str[101];
int i, count = 0, sum = 0;
gets(str);
int len = strlen(str);
if (len == 1) {
if (str[0] >= 97 && str[0] <= 122)
str[0] = str[0] - 32;
else if (str[0] >= 65 && str[0] <= 90)
str[0] = str[0] + 32;
}
if (str[0] >= 97 && str[0] <= 122) {
for (i = 1; i < len; i++) {
if (str[i] >= 65 && str[i] <= 90) count++;
}
}
if (str[0] >= 65 && str[0] <= 90) {
for (i = 1; i < len; i++) {
if (str[i] >= 65 && str[i] <= 90) sum++;
}
}
if (count == (len - 1)) {
str[0] = str[0] - 32;
for (i = 1; i < len; i++) {
str[i] = str[i] + 32;
}
}
if (sum == (len - 1)) {
for (i = 0; i < len; i++) {
str[i] = str[i] + 32;
}
}
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() {
char str[101];
int i, count = 0, sum = 0;
gets(str);
int len = strlen(str);
if (len == 1) {
if (str[0] >= 97 && str[0] <= 122)
str[0] = str[0] - 32;
else if (str[0] >= 65 && str[0] <= 90)
str[0] = str[0] + 32;
}
if (str[0] >= 97 && str[0] <= 122) {
for (i = 1; i < len; i++) {
if (str[i] >= 65 && str[i] <= 90) count++;
}
}
if (str[0] >= 65 && str[0] <= 90) {
for (i = 1; i < len; i++) {
if (str[i] >= 65 && str[i] <= 90) sum++;
}
}
if (count == (len - 1)) {
str[0] = str[0] - 32;
for (i = 1; i < len; i++) {
str[i] = str[i] + 32;
}
}
if (sum == (len - 1)) {
for (i = 0; i < len; i++) {
str[i] = str[i] + 32;
}
}
printf("%s\n", str);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int count = 0;
string str;
cin >> str;
int n = str.length() - 1;
for (int i = 1; i < str.length(); i++) {
if (str[i] >= 'A' && str[i] <= 'Z') count++;
}
if (count == n) {
if (str[0] >= 'a' && str[0] <= 'z')
str[0] = str[0] + ('A' - 'a');
else if (str[0] >= 'A' && str[0] <= 'Z')
str[0] = str[0] - ('A' - 'a');
for (int k = 1; k < str.length(); k++) {
str[k] = str[k] - ('A' - 'a');
}
}
cout << str << 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() {
int count = 0;
string str;
cin >> str;
int n = str.length() - 1;
for (int i = 1; i < str.length(); i++) {
if (str[i] >= 'A' && str[i] <= 'Z') count++;
}
if (count == n) {
if (str[0] >= 'a' && str[0] <= 'z')
str[0] = str[0] + ('A' - 'a');
else if (str[0] >= 'A' && str[0] <= 'Z')
str[0] = str[0] - ('A' - 'a');
for (int k = 1; k < str.length(); k++) {
str[k] = str[k] - ('A' - 'a');
}
}
cout << str << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool checkAccident(string word) {
bool allCaps = true;
for (int i = 1; i < word.length(); i++) {
if (word[i] >= 'A' && word[i] <= 'Z') {
} else {
allCaps = false;
break;
}
}
if (allCaps)
return true;
else
return false;
}
int main() {
string word;
cin >> word;
if (checkAccident(word)) {
if (word[0] > 'Z') {
cout << (char)(word[0] - 32);
} else {
cout << (char)(word[0] + 32);
}
for (int i = 1; i < word.length(); i++) {
cout << (char)(word[i] + 32);
}
} else {
cout << word;
}
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;
bool checkAccident(string word) {
bool allCaps = true;
for (int i = 1; i < word.length(); i++) {
if (word[i] >= 'A' && word[i] <= 'Z') {
} else {
allCaps = false;
break;
}
}
if (allCaps)
return true;
else
return false;
}
int main() {
string word;
cin >> word;
if (checkAccident(word)) {
if (word[0] > 'Z') {
cout << (char)(word[0] - 32);
} else {
cout << (char)(word[0] + 32);
}
for (int i = 1; i < word.length(); i++) {
cout << (char)(word[i] + 32);
}
} else {
cout << word;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int len, a, b, c;
string s;
cin >> s;
len = s.length();
if ((len == 1) && (((int)s[0] >= 97) && ((int)s[0] <= 122)))
printf("%c\n", (char)((int)s[0] - 32));
if ((len == 1) && (((int)s[0] >= 65) && ((int)s[0] <= 90)))
printf("%c\n", (char)((int)s[0] + 32));
if (len != 1) {
if (((int)s[0] >= 65) && ((int)s[0] <= 90)) {
b = 1;
for (int j = 1; j < len; j++) {
if (((int)s[j] >= 65) && ((int)s[j] <= 90))
continue;
else {
b = 0;
break;
}
}
if (b == 0)
cout << s << endl;
else {
for (int j = 0; j < len; j++) {
if ((s[j] >= 65) && (s[j] <= 90))
printf("%c", (char)((int)s[j] + 32));
else
printf("%c", (char)((int)s[j] - 32));
}
printf("\n");
}
}
if (((int)s[0] >= 97) && ((int)s[0] <= 122)) {
b = 1;
for (int j = 1; j < len; j++) {
if ((s[j] >= 65) && (s[j] <= 90))
continue;
else {
b = 0;
break;
}
}
if (b == 0)
cout << s << endl;
else {
for (int j = 0; j < len; j++) {
if ((s[j] >= 65) && (s[j] <= 90))
printf("%c", (char)((int)s[j] + 32));
else
printf("%c", (char)((int)s[j] - 32));
}
printf("\n");
}
}
}
}
| ### 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() {
int len, a, b, c;
string s;
cin >> s;
len = s.length();
if ((len == 1) && (((int)s[0] >= 97) && ((int)s[0] <= 122)))
printf("%c\n", (char)((int)s[0] - 32));
if ((len == 1) && (((int)s[0] >= 65) && ((int)s[0] <= 90)))
printf("%c\n", (char)((int)s[0] + 32));
if (len != 1) {
if (((int)s[0] >= 65) && ((int)s[0] <= 90)) {
b = 1;
for (int j = 1; j < len; j++) {
if (((int)s[j] >= 65) && ((int)s[j] <= 90))
continue;
else {
b = 0;
break;
}
}
if (b == 0)
cout << s << endl;
else {
for (int j = 0; j < len; j++) {
if ((s[j] >= 65) && (s[j] <= 90))
printf("%c", (char)((int)s[j] + 32));
else
printf("%c", (char)((int)s[j] - 32));
}
printf("\n");
}
}
if (((int)s[0] >= 97) && ((int)s[0] <= 122)) {
b = 1;
for (int j = 1; j < len; j++) {
if ((s[j] >= 65) && (s[j] <= 90))
continue;
else {
b = 0;
break;
}
}
if (b == 0)
cout << s << endl;
else {
for (int j = 0; j < len; j++) {
if ((s[j] >= 65) && (s[j] <= 90))
printf("%c", (char)((int)s[j] + 32));
else
printf("%c", (char)((int)s[j] - 32));
}
printf("\n");
}
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int penuh = 1;
for (int i = 0; i < s.length(); i++) {
if (i == 0) {
} else {
if (s[i] >= 'A' && s[i] <= 'Z') {
} else
penuh = 0;
}
}
if (penuh == 1) {
for (int i = 0; i < s.length(); i++) {
if (s[i] >= 'a' && s[i] <= 'z')
cout << (char)(s[i] - 32);
else
cout << (char)(s[i] + 32);
}
cout << endl;
} else {
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;
int penuh = 1;
for (int i = 0; i < s.length(); i++) {
if (i == 0) {
} else {
if (s[i] >= 'A' && s[i] <= 'Z') {
} else
penuh = 0;
}
}
if (penuh == 1) {
for (int i = 0; i < s.length(); i++) {
if (s[i] >= 'a' && s[i] <= 'z')
cout << (char)(s[i] - 32);
else
cout << (char)(s[i] + 32);
}
cout << endl;
} else {
cout << s << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <typename _Tp>
inline _Tp read(_Tp& x) {
char c11 = getchar(), ob = 0;
x = 0;
while (c11 ^ '-' && !isdigit(c11)) c11 = getchar();
if (c11 == '-') c11 = getchar(), ob = 1;
while (isdigit(c11)) x = x * 10 + c11 - '0', c11 = getchar();
if (ob) x = -x;
return x;
}
int main() {
string s;
cin >> s;
if (s.length() == 1) {
printf("%c", s.at(0) < 'a' ? tolower(s.at(0)) : toupper(s.at(0)));
return 0;
}
bool flag = true;
for (int index = 1; index < s.length(); index++) {
if (s.at(index) >= 'a') {
flag = false;
break;
}
}
for (int index = 0; index < s.length(); index++) {
if (flag) {
printf("%c",
s.at(index) < 'a' ? tolower(s.at(index)) : toupper(s.at(index)));
} else {
printf("%c", s.at(index));
}
}
}
| ### 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;
template <typename _Tp>
inline _Tp read(_Tp& x) {
char c11 = getchar(), ob = 0;
x = 0;
while (c11 ^ '-' && !isdigit(c11)) c11 = getchar();
if (c11 == '-') c11 = getchar(), ob = 1;
while (isdigit(c11)) x = x * 10 + c11 - '0', c11 = getchar();
if (ob) x = -x;
return x;
}
int main() {
string s;
cin >> s;
if (s.length() == 1) {
printf("%c", s.at(0) < 'a' ? tolower(s.at(0)) : toupper(s.at(0)));
return 0;
}
bool flag = true;
for (int index = 1; index < s.length(); index++) {
if (s.at(index) >= 'a') {
flag = false;
break;
}
}
for (int index = 0; index < s.length(); index++) {
if (flag) {
printf("%c",
s.at(index) < 'a' ? tolower(s.at(index)) : toupper(s.at(index)));
} else {
printf("%c", s.at(index));
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long int INF = 1e17;
long long int power(long long int x, long long int y) {
long long int t = 1;
while (y > 0) {
if (y % 2)
y -= 1, t = t * x % mod;
else
y /= 2, x = x * x % mod;
}
return t;
}
long long int inverse(long long int q) {
long long int t;
t = power(q, mod - 2);
return t;
}
long long int get_bit(long long int x, long long int k) { return x >> k & 1; }
bool cmp(pair<long long int, long long int> p1,
pair<long long int, long long int> p2) {
if (p1.first > p2.first) {
return true;
} else if (p1.first == p2.first) {
if (p1.second <= p2.second) {
return true;
} else {
return false;
}
} else {
return false;
}
}
string numtostr(long long int n) {
stringstream ss;
ss << n;
string str = ss.str();
return str;
}
long long int strtonum(string s) {
long long int ans = 0, i;
for (i = 0; i < s.length(); i++) {
long long int temp = s[i] - '0';
ans *= 10;
ans += temp;
}
return ans;
}
long long int prime[1000001] = {0};
int main() {
long long int i, j, k, l;
string s;
cin >> s;
long long int cou = 0;
for (i = 0; i < s.length(); i++) {
k = (int)s[i];
if (k >= 65 && k <= 90) {
cou++;
}
}
k = (int)s[0];
if (cou == s.length() || (cou == (s.length() - 1) && k >= 97)) {
for (i = 0; i < s.length(); i++) {
k = (int)s[i];
if (k >= 65 && k <= 90) {
k -= 65;
k += 97;
cout << (char)(k);
} else {
k -= 97;
k += 65;
cout << (char)(k);
}
}
} else {
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;
const int mod = 1e9 + 7;
const long long int INF = 1e17;
long long int power(long long int x, long long int y) {
long long int t = 1;
while (y > 0) {
if (y % 2)
y -= 1, t = t * x % mod;
else
y /= 2, x = x * x % mod;
}
return t;
}
long long int inverse(long long int q) {
long long int t;
t = power(q, mod - 2);
return t;
}
long long int get_bit(long long int x, long long int k) { return x >> k & 1; }
bool cmp(pair<long long int, long long int> p1,
pair<long long int, long long int> p2) {
if (p1.first > p2.first) {
return true;
} else if (p1.first == p2.first) {
if (p1.second <= p2.second) {
return true;
} else {
return false;
}
} else {
return false;
}
}
string numtostr(long long int n) {
stringstream ss;
ss << n;
string str = ss.str();
return str;
}
long long int strtonum(string s) {
long long int ans = 0, i;
for (i = 0; i < s.length(); i++) {
long long int temp = s[i] - '0';
ans *= 10;
ans += temp;
}
return ans;
}
long long int prime[1000001] = {0};
int main() {
long long int i, j, k, l;
string s;
cin >> s;
long long int cou = 0;
for (i = 0; i < s.length(); i++) {
k = (int)s[i];
if (k >= 65 && k <= 90) {
cou++;
}
}
k = (int)s[0];
if (cou == s.length() || (cou == (s.length() - 1) && k >= 97)) {
for (i = 0; i < s.length(); i++) {
k = (int)s[i];
if (k >= 65 && k <= 90) {
k -= 65;
k += 97;
cout << (char)(k);
} else {
k -= 97;
k += 65;
cout << (char)(k);
}
}
} else {
cout << s << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int c = 0;
for (int i = 0; i < s.size(); i++) {
if (int(s[i]) <= int('Z')) {
c++;
}
}
if (c == s.size()) {
for (int i = 0; i < s.size(); i++) {
s[i] = tolower(s[i]);
}
cout << s;
} else if ((int(s[0]) > int('Z')) & (c == (s.size() - 1))) {
for (int i = 1; i < s.size(); i++) {
s[i] = tolower(s[i]);
}
s[0] = toupper(s[0]);
cout << s;
} 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;
cin >> s;
int c = 0;
for (int i = 0; i < s.size(); i++) {
if (int(s[i]) <= int('Z')) {
c++;
}
}
if (c == s.size()) {
for (int i = 0; i < s.size(); i++) {
s[i] = tolower(s[i]);
}
cout << s;
} else if ((int(s[0]) > int('Z')) & (c == (s.size() - 1))) {
for (int i = 1; i < s.size(); i++) {
s[i] = tolower(s[i]);
}
s[0] = toupper(s[0]);
cout << s;
} else {
cout << s;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin >> s;
bool ok = true;
for (int i = 1; i < s.length(); ++i) {
if (!isupper(s[i])) {
ok = false;
break;
}
}
if (ok) {
if (islower(s[0]))
s[0] = toupper(s[0]);
else
s[0] = tolower(s[0]);
for (int i = 1; i < s.length(); ++i) s[i] = tolower(s[i]);
}
cout << s;
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;
string s;
int main() {
cin >> s;
bool ok = true;
for (int i = 1; i < s.length(); ++i) {
if (!isupper(s[i])) {
ok = false;
break;
}
}
if (ok) {
if (islower(s[0]))
s[0] = toupper(s[0]);
else
s[0] = tolower(s[0]);
for (int i = 1; i < s.length(); ++i) s[i] = tolower(s[i]);
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int cnt = 0;
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] < 97) cnt++;
}
if (cnt == s.size() || s[0] >= 97 && cnt == s.size() - 1) {
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 97)
cout << char(toupper(s[i]));
else if (s[i] < 97)
cout << char(tolower(s[i]));
}
} else
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 cnt = 0;
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] < 97) cnt++;
}
if (cnt == s.size() || s[0] >= 97 && cnt == s.size() - 1) {
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 97)
cout << char(toupper(s[i]));
else if (s[i] < 97)
cout << char(tolower(s[i]));
}
} else
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
while (cin >> s) {
bool flag = true;
for (int i = 1; i < s.size(); i++) {
if (!(s[i] >= 65 && s[i] <= 90)) {
flag = false;
break;
}
}
if (flag) {
if (s[0] >= 97 && s[0] <= 122) {
s[0] = toupper(s[0]);
} else {
s[0] = tolower(s[0]);
}
for (int i = 1; i < s.size(); i++) {
s[i] = tolower(s[i]);
}
}
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;
int main() {
string s;
while (cin >> s) {
bool flag = true;
for (int i = 1; i < s.size(); i++) {
if (!(s[i] >= 65 && s[i] <= 90)) {
flag = false;
break;
}
}
if (flag) {
if (s[0] >= 97 && s[0] <= 122) {
s[0] = toupper(s[0]);
} else {
s[0] = tolower(s[0]);
}
for (int i = 1; i < s.size(); i++) {
s[i] = tolower(s[i]);
}
}
cout << s << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char ch[101];
scanf("%s", &ch);
int len = strlen(ch), i, count = 0;
for (i = 1; i < len; i++) {
if (ch[i] >= 'a' && ch[i] <= 'z') {
count = 1;
break;
}
}
if (count == 1)
printf("%s", ch);
else {
if (ch[0] >= 'a' && ch[0] <= 'z')
ch[0] = toupper(ch[0]);
else
ch[0] = tolower(ch[0]);
printf("%c", ch[0]);
for (i = 1; i < len; i++) printf("%c", tolower(ch[i]));
}
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() {
char ch[101];
scanf("%s", &ch);
int len = strlen(ch), i, count = 0;
for (i = 1; i < len; i++) {
if (ch[i] >= 'a' && ch[i] <= 'z') {
count = 1;
break;
}
}
if (count == 1)
printf("%s", ch);
else {
if (ch[0] >= 'a' && ch[0] <= 'z')
ch[0] = toupper(ch[0]);
else
ch[0] = tolower(ch[0]);
printf("%c", ch[0]);
for (i = 1; i < len; i++) printf("%c", tolower(ch[i]));
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, d, c, i;
string ug;
cin >> ug;
for (i = 1; i < ug.size(); i++) {
if (ug[i] >= 'a') {
cout << ug;
return 0;
}
}
for (char &n : ug) {
if (n >= 'a')
n = n - 32;
else
n = n + 32;
}
cout << ug;
}
| ### 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() {
int a, b, d, c, i;
string ug;
cin >> ug;
for (i = 1; i < ug.size(); i++) {
if (ug[i] >= 'a') {
cout << ug;
return 0;
}
}
for (char &n : ug) {
if (n >= 'a')
n = n - 32;
else
n = n + 32;
}
cout << ug;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char word[105];
scanf("%s", word);
bool flag = true;
for (int i = 1; i < strlen(word); ++i) {
if (islower(word[i])) {
flag = false;
break;
}
}
if (!flag) {
printf("%s", word);
} else {
if (isupper(word[0]))
word[0] = tolower(word[0]);
else
word[0] = toupper(word[0]);
for (int i = 1; i < strlen(word); ++i) {
word[i] = tolower(word[i]);
}
printf("%s", word);
}
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() {
char word[105];
scanf("%s", word);
bool flag = true;
for (int i = 1; i < strlen(word); ++i) {
if (islower(word[i])) {
flag = false;
break;
}
}
if (!flag) {
printf("%s", word);
} else {
if (isupper(word[0]))
word[0] = tolower(word[0]);
else
word[0] = toupper(word[0]);
for (int i = 1; i < strlen(word); ++i) {
word[i] = tolower(word[i]);
}
printf("%s", word);
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
bool temp = false;
string str;
cin >> str;
for (int i = 0; str[i] != '\0'; ++i)
if (str[i] >= 'a' && str[i] <= 'z' && i) {
temp = true;
break;
}
if (temp)
cout << str;
else {
for (int i = 0; str[i]; ++i)
if (str[i] >= 'a' && str[i] <= 'z')
cout << (char)(str[i] - 32);
else
cout << (char)(str[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>
using namespace std;
int main() {
bool temp = false;
string str;
cin >> str;
for (int i = 0; str[i] != '\0'; ++i)
if (str[i] >= 'a' && str[i] <= 'z' && i) {
temp = true;
break;
}
if (temp)
cout << str;
else {
for (int i = 0; str[i]; ++i)
if (str[i] >= 'a' && str[i] <= 'z')
cout << (char)(str[i] - 32);
else
cout << (char)(str[i] + 32);
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string revCaps(string str) {
for (int i = 0; i < str.size(); i++)
if (str[i] >= 'a' && str[i] <= 'z')
str[i] = str[i] + 'A' - 'a';
else if (str[i] >= 'A' && str[i] <= 'Z')
str[i] = str[i] + 'a' - 'A';
return str;
}
int main() {
string str;
cin >> str;
bool caps = false;
bool allCaps = true;
for (int i = 0; i < str.size(); i++) {
if (str[i] >= 'a' && str[i] <= 'z') allCaps = false;
}
bool otherCaps = true;
for (int i = 1; i < str.size(); i++) {
if (str[i] >= 'a' && str[i] <= 'z') otherCaps = false;
}
bool firstNoCap = (str[0] >= 'a' && str[0] <= 'z');
if (allCaps || (otherCaps && firstNoCap)) {
cout << revCaps(str) << endl;
} else
cout << str << 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;
string revCaps(string str) {
for (int i = 0; i < str.size(); i++)
if (str[i] >= 'a' && str[i] <= 'z')
str[i] = str[i] + 'A' - 'a';
else if (str[i] >= 'A' && str[i] <= 'Z')
str[i] = str[i] + 'a' - 'A';
return str;
}
int main() {
string str;
cin >> str;
bool caps = false;
bool allCaps = true;
for (int i = 0; i < str.size(); i++) {
if (str[i] >= 'a' && str[i] <= 'z') allCaps = false;
}
bool otherCaps = true;
for (int i = 1; i < str.size(); i++) {
if (str[i] >= 'a' && str[i] <= 'z') otherCaps = false;
}
bool firstNoCap = (str[0] >= 'a' && str[0] <= 'z');
if (allCaps || (otherCaps && firstNoCap)) {
cout << revCaps(str) << endl;
} else
cout << str << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using ::std::cin;
using ::std::cout;
using ::std::string;
bool malaLiterka(string s) {
return s.length() == 1 && s[0] >= 'a' && s[0] <= 'z';
}
bool duzeLiterki(string s) {
for (int i = 0; i < s.length(); ++i) {
if (s[i] >= 'a' && s[i] <= 'z') return false;
}
return true;
}
bool malaDuza(string s) {
if (s[0] >= 'a' && s[0] <= 'z') {
for (int i = 1; i < s.length(); ++i) {
if (s[i] >= 'a' && s[i] <= 'z') return false;
}
return true;
}
return false;
}
int main() {
string s;
cin >> s;
if (malaLiterka(s))
s[0] -= 'a' - 'A';
else if (duzeLiterki(s)) {
for (int i = 0; i < s.length(); ++i) {
s[i] += 'a' - 'A';
}
} else if (malaDuza(s)) {
s[0] -= 'a' - 'A';
for (int i = 1; i < s.length(); ++i) {
s[i] += 'a' - 'A';
}
}
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 ::std::cin;
using ::std::cout;
using ::std::string;
bool malaLiterka(string s) {
return s.length() == 1 && s[0] >= 'a' && s[0] <= 'z';
}
bool duzeLiterki(string s) {
for (int i = 0; i < s.length(); ++i) {
if (s[i] >= 'a' && s[i] <= 'z') return false;
}
return true;
}
bool malaDuza(string s) {
if (s[0] >= 'a' && s[0] <= 'z') {
for (int i = 1; i < s.length(); ++i) {
if (s[i] >= 'a' && s[i] <= 'z') return false;
}
return true;
}
return false;
}
int main() {
string s;
cin >> s;
if (malaLiterka(s))
s[0] -= 'a' - 'A';
else if (duzeLiterki(s)) {
for (int i = 0; i < s.length(); ++i) {
s[i] += 'a' - 'A';
}
} else if (malaDuza(s)) {
s[0] -= 'a' - 'A';
for (int i = 1; i < s.length(); ++i) {
s[i] += 'a' - 'A';
}
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int flag = 0;
int count = 0;
if (isupper(s[0])) {
flag = 1;
count = 1;
}
for (int i = 1; i < s.length(); i++) {
if (isupper(s[i])) count++;
}
if (count == s.length()) {
for (int i = 0; i < s.length(); i++) {
s[i] = tolower(s[i]);
}
} else if (count == s.length() - 1 && flag == 0) {
s[0] = toupper(s[0]);
for (int i = 1; i < s.length(); i++) {
s[i] = tolower(s[i]);
}
}
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 flag = 0;
int count = 0;
if (isupper(s[0])) {
flag = 1;
count = 1;
}
for (int i = 1; i < s.length(); i++) {
if (isupper(s[i])) count++;
}
if (count == s.length()) {
for (int i = 0; i < s.length(); i++) {
s[i] = tolower(s[i]);
}
} else if (count == s.length() - 1 && flag == 0) {
s[0] = toupper(s[0]);
for (int i = 1; i < s.length(); i++) {
s[i] = tolower(s[i]);
}
}
cout << s;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool f = false;
for (int i = 0; i < s.length(); i++) {
if (s[i] >= 'a') {
f = true;
break;
}
}
if (!f) {
for (int i = 0; i < s.length(); i++) cout << char(s[i] + 32);
cout << endl;
return 0;
}
f = false;
if (s[0] <= 'Z') {
cout << s << endl;
return 0;
}
for (int i = 1; i < s.length(); i++) {
if (s[i] >= 'a') {
f = true;
break;
}
}
if (!f) {
cout << char(s[0] - 32);
for (int i = 1; i < s.length(); i++) cout << char(s[i] + 32);
cout << endl;
return 0;
}
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;
int main() {
string s;
cin >> s;
bool f = false;
for (int i = 0; i < s.length(); i++) {
if (s[i] >= 'a') {
f = true;
break;
}
}
if (!f) {
for (int i = 0; i < s.length(); i++) cout << char(s[i] + 32);
cout << endl;
return 0;
}
f = false;
if (s[0] <= 'Z') {
cout << s << endl;
return 0;
}
for (int i = 1; i < s.length(); i++) {
if (s[i] >= 'a') {
f = true;
break;
}
}
if (!f) {
cout << char(s[0] - 32);
for (int i = 1; i < s.length(); i++) cout << char(s[i] + 32);
cout << endl;
return 0;
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int i;
int j, flag = 1;
char Str[100];
scanf("%s", Str);
for (i = 1; Str[i] != '\0'; i++) {
if (Str[i] >= 97 && Str[i] <= 122) {
flag = 0;
break;
}
}
if (flag == 1) {
if (Str[0] >= 65 && Str[0] <= 90)
Str[0] = Str[0] + 32;
else
Str[0] = Str[0] - 32;
for (j = 1; Str[j] != '\0'; j++) {
Str[j] = Str[j] + 32;
}
}
printf("%s\n", Str);
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>
int main() {
int i;
int j, flag = 1;
char Str[100];
scanf("%s", Str);
for (i = 1; Str[i] != '\0'; i++) {
if (Str[i] >= 97 && Str[i] <= 122) {
flag = 0;
break;
}
}
if (flag == 1) {
if (Str[0] >= 65 && Str[0] <= 90)
Str[0] = Str[0] + 32;
else
Str[0] = Str[0] - 32;
for (j = 1; Str[j] != '\0'; j++) {
Str[j] = Str[j] + 32;
}
}
printf("%s\n", Str);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool all(string s) {
for (int i = 0; i < (s.length()); i++) {
if (s[i] != toupper(s[i])) return false;
}
return true;
}
int main() {
string s;
cin >> s;
if (s[0] == tolower(s[0]) && all(s.substr(1))) {
s[0] = toupper(s[0]);
for (int i = 1; i < s.length(); ++i) s[i] = tolower(s[i]);
} else if (all(s)) {
for (int i = 0; i < (s.length()); i++) s[i] = tolower(s[i]);
}
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;
bool all(string s) {
for (int i = 0; i < (s.length()); i++) {
if (s[i] != toupper(s[i])) return false;
}
return true;
}
int main() {
string s;
cin >> s;
if (s[0] == tolower(s[0]) && all(s.substr(1))) {
s[0] = toupper(s[0]);
for (int i = 1; i < s.length(); ++i) s[i] = tolower(s[i]);
} else if (all(s)) {
for (int i = 0; i < (s.length()); i++) s[i] = tolower(s[i]);
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, p, x, a, b, m;
int i, f = 0;
while (cin >> s) {
if (s.length() == 1 && s[0] <= 'z' && s[0] >= 'a') {
cout << (char)(s[0] - 'a' + 'A') << '\n';
continue;
}
m = s;
p = s[0];
x = tolower(s[0]);
if (x == p) {
for (i = 1; i < s.length(); i++) {
a = s[i];
b = toupper(s[i]);
if (b == a) {
f = 1;
} else {
f = 0;
break;
}
}
if (f == 0)
cout << s << endl;
else {
for (i = 0; i < s.length(); i++) {
a = s[i];
b = toupper(s[i]);
if (b == a) {
s[i] = tolower(s[i]);
cout << s[i];
} else {
s[i] = toupper(s[i]);
cout << s[i];
}
}
cout << endl;
}
} else {
transform(s.begin(), s.end(), s.begin(), ::toupper);
if (s == m) {
transform(s.begin(), s.end(), s.begin(), ::tolower);
cout << s << endl;
} else
cout << m << 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 main() {
string s, p, x, a, b, m;
int i, f = 0;
while (cin >> s) {
if (s.length() == 1 && s[0] <= 'z' && s[0] >= 'a') {
cout << (char)(s[0] - 'a' + 'A') << '\n';
continue;
}
m = s;
p = s[0];
x = tolower(s[0]);
if (x == p) {
for (i = 1; i < s.length(); i++) {
a = s[i];
b = toupper(s[i]);
if (b == a) {
f = 1;
} else {
f = 0;
break;
}
}
if (f == 0)
cout << s << endl;
else {
for (i = 0; i < s.length(); i++) {
a = s[i];
b = toupper(s[i]);
if (b == a) {
s[i] = tolower(s[i]);
cout << s[i];
} else {
s[i] = toupper(s[i]);
cout << s[i];
}
}
cout << endl;
}
} else {
transform(s.begin(), s.end(), s.begin(), ::toupper);
if (s == m) {
transform(s.begin(), s.end(), s.begin(), ::tolower);
cout << s << endl;
} else
cout << m << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string in;
cin >> in;
if (in.size() == 1)
if (islower(in[0]))
printf("%c", toupper(in[0]));
else
printf("%c", tolower(in[0]));
else {
bool all_caps = true;
for (int i = 1; in[i] != '\0'; i++) {
if (islower(in[i])) all_caps = false;
}
if (all_caps && !islower(in[0])) {
for (int i = 0; in[i] != '\0'; i++) printf("%c", tolower(in[i]));
} else if (all_caps && islower(in[0])) {
printf("%c", toupper(in[0]));
for (int i = 1; in[i] != '\0'; i++) printf("%c", tolower(in[i]));
} else
cout << in;
}
printf("\n");
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 in;
cin >> in;
if (in.size() == 1)
if (islower(in[0]))
printf("%c", toupper(in[0]));
else
printf("%c", tolower(in[0]));
else {
bool all_caps = true;
for (int i = 1; in[i] != '\0'; i++) {
if (islower(in[i])) all_caps = false;
}
if (all_caps && !islower(in[0])) {
for (int i = 0; in[i] != '\0'; i++) printf("%c", tolower(in[i]));
} else if (all_caps && islower(in[0])) {
printf("%c", toupper(in[0]));
for (int i = 1; in[i] != '\0'; i++) printf("%c", tolower(in[i]));
} else
cout << in;
}
printf("\n");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char st[100];
int v = 0;
for (int i = 0; i < 100; i++) {
st[i] = 0;
}
cin >> st;
int c = 0;
while (st[c] != 0) {
c++;
}
for (int i = 0; i < c; i++) {
if (isupper(st[i])) {
v++;
}
}
if (v == c - 1 && islower(st[0])) {
st[0] = toupper(st[0]);
for (int i = 1; i < c; i++) {
st[i] = tolower(st[i]);
}
} else if (islower(st[0]) && c == 1) {
st[0] = toupper(st[0]);
} else if (isupper(st[0]) && c == 1) {
st[0] = tolower(st[0]);
} else if (v == c && c != 1) {
for (int i = 0; i < c; i++) {
st[i] = tolower(st[i]);
}
}
cout << st;
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 st[100];
int v = 0;
for (int i = 0; i < 100; i++) {
st[i] = 0;
}
cin >> st;
int c = 0;
while (st[c] != 0) {
c++;
}
for (int i = 0; i < c; i++) {
if (isupper(st[i])) {
v++;
}
}
if (v == c - 1 && islower(st[0])) {
st[0] = toupper(st[0]);
for (int i = 1; i < c; i++) {
st[i] = tolower(st[i]);
}
} else if (islower(st[0]) && c == 1) {
st[0] = toupper(st[0]);
} else if (isupper(st[0]) && c == 1) {
st[0] = tolower(st[0]);
} else if (v == c && c != 1) {
for (int i = 0; i < c; i++) {
st[i] = tolower(st[i]);
}
}
cout << st;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
char a[100];
int i, j, count, k;
count = 0;
scanf("%s", a);
k = 0;
for (j = 0; a[j] != '\0'; j++) {
if (!((int)a[j] < 97) && !((int)a[j] > 122)) {
count++;
k = j;
}
if (count > 1) {
printf("%s", a);
return 0;
}
}
if (k == 0) {
if (count == 0) {
printf("%c", (int)a[0] + 32);
} else {
printf("%c", (int)a[0] - 32);
}
for (i = 1; a[i] != '\0'; i++) {
printf("%c", (int)a[i] + 32);
}
} else {
printf("%s", 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>
int main() {
char a[100];
int i, j, count, k;
count = 0;
scanf("%s", a);
k = 0;
for (j = 0; a[j] != '\0'; j++) {
if (!((int)a[j] < 97) && !((int)a[j] > 122)) {
count++;
k = j;
}
if (count > 1) {
printf("%s", a);
return 0;
}
}
if (k == 0) {
if (count == 0) {
printf("%c", (int)a[0] + 32);
} else {
printf("%c", (int)a[0] - 32);
}
for (i = 1; a[i] != '\0'; i++) {
printf("%c", (int)a[i] + 32);
}
} else {
printf("%s", a);
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int len = (int)s.size();
int l = 0, u = 0;
for (int i = 0; i < len; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
l++;
} else {
u++;
}
}
if ((s[0] >= 'a' && s[0] <= 'z') && (u == len - 1)) {
cout << (char)(s[0] - 32);
for (int i = 1; i < len; i++) {
cout << (char)(s[i] + 32);
}
} else if (u == len) {
for (int i = 0; i < len; i++) {
cout << (char)(s[i] + 32);
}
} 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;
cin >> s;
int len = (int)s.size();
int l = 0, u = 0;
for (int i = 0; i < len; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
l++;
} else {
u++;
}
}
if ((s[0] >= 'a' && s[0] <= 'z') && (u == len - 1)) {
cout << (char)(s[0] - 32);
for (int i = 1; i < len; i++) {
cout << (char)(s[i] + 32);
}
} else if (u == len) {
for (int i = 0; i < len; i++) {
cout << (char)(s[i] + 32);
}
} else {
cout << s << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
char str[1000];
int i, flag = 0, a;
gets(str);
a = strlen(str);
for (i = 1; i < a; i++) {
if (str[i] >= 'A' && str[i] <= 'Z')
continue;
else
flag++;
}
if (flag >= 1) {
printf("%s", str);
} else if (flag == 0 && str[0] >= 'A' && str[0] <= 'Z') {
for (i = 0; i < a; i++) str[i] = str[i] + 32;
printf("%s", str);
} else if (flag == 0) {
if (str[0] >= 'a' && str[0] <= 'z') str[0] = str[0] - 32;
for (i = 1; i < strlen(str); i++) {
if (str[i] >= 'A' && str[i] <= 'Z') str[i] = str[i] + 32;
}
printf("%s", str);
}
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>
int main() {
char str[1000];
int i, flag = 0, a;
gets(str);
a = strlen(str);
for (i = 1; i < a; i++) {
if (str[i] >= 'A' && str[i] <= 'Z')
continue;
else
flag++;
}
if (flag >= 1) {
printf("%s", str);
} else if (flag == 0 && str[0] >= 'A' && str[0] <= 'Z') {
for (i = 0; i < a; i++) str[i] = str[i] + 32;
printf("%s", str);
} else if (flag == 0) {
if (str[0] >= 'a' && str[0] <= 'z') str[0] = str[0] - 32;
for (i = 1; i < strlen(str); i++) {
if (str[i] >= 'A' && str[i] <= 'Z') str[i] = str[i] + 32;
}
printf("%s", str);
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string chipi;
cin >> chipi;
if (chipi[0] >= 'a') {
bool r = true;
for (int i = 1; i < chipi.size(); i++)
if (chipi[i] >= 'a') r = false;
if (r) {
chipi[0] -= 32;
for (int i = 1; i < chipi.size(); i++)
if (chipi[i] < 'a') chipi[i] += 32;
}
} else {
bool kk = true;
for (int i = 1; i < chipi.size(); i++)
if (chipi[i] >= 'a') kk = false;
if (kk) {
for (int i = 0; i < chipi.size(); i++)
if (chipi[i] < 'a') chipi[i] += 32;
}
}
cout << chipi;
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() {
string chipi;
cin >> chipi;
if (chipi[0] >= 'a') {
bool r = true;
for (int i = 1; i < chipi.size(); i++)
if (chipi[i] >= 'a') r = false;
if (r) {
chipi[0] -= 32;
for (int i = 1; i < chipi.size(); i++)
if (chipi[i] < 'a') chipi[i] += 32;
}
} else {
bool kk = true;
for (int i = 1; i < chipi.size(); i++)
if (chipi[i] >= 'a') kk = false;
if (kk) {
for (int i = 0; i < chipi.size(); i++)
if (chipi[i] < 'a') chipi[i] += 32;
}
}
cout << chipi;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool check(string str) {
int cnt = 0;
for (int i = 0; i < str.length(); i++) {
if (isupper(str[i])) {
cnt++;
}
}
if (islower(str[0]) && cnt == (str.length() - 1))
return 1;
else
return 0;
}
int main() {
string str;
cin >> str;
int cnt = 0;
for (int i = 0; i < str.length(); i++) {
if (isupper(str[i])) {
cnt++;
}
}
if (cnt == str.length()) {
for (int i = 0; i < str.length(); i++) {
putchar(tolower(str[i]));
}
} else if (check(str)) {
putchar(toupper(str[0]));
for (int i = 1; i < str.length(); i++) {
putchar(tolower(str[i]));
}
} else
cout << str;
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 check(string str) {
int cnt = 0;
for (int i = 0; i < str.length(); i++) {
if (isupper(str[i])) {
cnt++;
}
}
if (islower(str[0]) && cnt == (str.length() - 1))
return 1;
else
return 0;
}
int main() {
string str;
cin >> str;
int cnt = 0;
for (int i = 0; i < str.length(); i++) {
if (isupper(str[i])) {
cnt++;
}
}
if (cnt == str.length()) {
for (int i = 0; i < str.length(); i++) {
putchar(tolower(str[i]));
}
} else if (check(str)) {
putchar(toupper(str[0]));
for (int i = 1; i < str.length(); i++) {
putchar(tolower(str[i]));
}
} else
cout << str;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int NOD(int x, int y) {
if (x == 0) return y;
if (y == 0) return x;
while ((x % y != 0) && (y % x != 0)) {
if (x > y)
x %= y;
else
y %= x;
}
if (x < y)
return x;
else
return y;
}
int NOK(int x, int y) { return (x / NOD(x, y)) * y; }
vector<int> fact(int n) {
vector<int> a;
for (int i = 2; (i - 1) * (i - 1) < n; i++) {
if (n % i == 0) {
if (i != 2) a.push_back(i);
if (i * i != n) a.push_back(n / i);
}
}
return a;
}
bool is_happy(int n) {
if (n == 0) return 0;
bool flag = 1;
while (n > 0) {
if (n % 10 != 4 && n % 10 != 7) {
flag = 0;
break;
}
n /= 10;
}
return flag;
}
void taxi() {
long s1 = 0, s2 = 0, s3 = 0, s4 = 0;
int n;
cin >> n;
int s;
for (int i = 0; i < n; i++) {
cin >> s;
if (s == 1) s1++;
if (s == 2) s2++;
if (s == 3) s3++;
if (s == 4) s4++;
}
if (s3 < s1) {
s4 += s3;
s1 -= s3;
s4 += s2 / 2;
if (s2 % 2 == 1)
s2 = 2;
else
s2 = 0;
s4 += (s2 + s1) / 4;
if ((s2 + s1) % 4 != 0) s4++;
} else {
s4 += s3;
s4 += s2 / 4;
if (s2 % 2 == 1) s4++;
}
cout << s4;
}
void capslook() {
string s;
cin >> s;
if (s.length() == 1) {
if (int(s[0]) < 96)
cout << char(int(s[0]) + 32);
else
cout << char(int(s[0] - 32));
} else {
bool flag;
if (int(s[0]) > 96)
flag = 1;
else
flag = 0;
string ans = "";
if (flag)
ans.push_back(char(int(s[0]) - 32));
else
ans.push_back(char(int(s[0]) + 32));
bool flag_s = 0;
for (int i = 1; i < s.length(); i++) {
if (int(s[i]) > 96) {
flag_s = 1;
break;
} else
ans.push_back(char(int(s[i]) + 32));
}
if (flag_s)
cout << s;
else
cout << ans;
}
}
void sculpture() {
int n;
cin >> n;
vector<int> a = fact(n);
if (a.size()) {
vector<vector<long> > b;
b.resize(a.size());
for (int i = 0; i < b.size(); i++) b[i].resize(n / a[i]);
for (int i = 0; i < b.size(); i++) {
for (int j = 0; j < b[i].size(); j++) b[i][j] = 0;
}
long t;
long all = 0;
for (int i = 0; i < n; i++) {
cin >> t;
all += t;
for (int j = 0; j < b.size(); j++) b[j][i % (n / a[j])] += t;
}
for (int i = 0; i < b.size(); i++) {
for (int j = 0; j < b[i].size(); j++)
if (all < b[i][j]) all = b[i][j];
}
cout << all;
} else {
long t;
long all = 0;
for (int i = 0; i < n; i++) {
cin >> t;
all += t;
}
cout << all;
}
}
void team() {
int n;
cin >> n;
int a, b, c;
int ans = 0;
for (int i = 0; i < n; i++) {
cin >> a >> b >> c;
if (a + b + c > 1) ans++;
}
cout << ans;
}
void general() {
int n;
cin >> n;
vector<int> a;
a.resize(n);
for (int i = 0; i < n; i++) cin >> a[i];
int max = 0;
int min = n - 1;
for (int i = 0; i < n; i++) {
if (a[max] < a[i]) max = i;
if (a[min] >= a[i]) min = i;
}
if (max > min)
cout << max + n - 1 - min - 1;
else
cout << max + n - 1 - min;
}
void present() {
int n;
cin >> n;
vector<int> p;
p.resize(n);
for (int i = 0; i < n; i++) {
cin >> p[i];
p[i]--;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
if (p[j] == i) cout << j + 1 << " ";
}
}
void football() {
string s;
cin >> s;
int ans = 1;
for (int i = 1; i < s.length(); i++) {
if (s[i] == s[i - 1])
ans++;
else
ans = 1;
if (ans == 7) {
cout << "YES";
break;
}
}
if (ans < 7) cout << "NO";
}
void Valera() {
int* s = new int[4];
bool* flag = new bool[4];
for (int i = 0; i < 4; i++) {
cin >> s[i];
flag[i] = 1;
}
int ans = 0;
for (int i = 0; i < 4; i++) {
for (int j = i + 1; j < 4; j++) {
if (s[i] == s[j] && flag[j]) {
ans++;
flag[j] = 0;
}
}
}
cout << ans;
}
void Happy() {
long long n;
cin >> n;
int i = 0;
while (n > 0) {
if (n % 10 == 4 || n % 10 == 7) i++;
n /= 10;
}
bool flag = 0;
if (i == 0)
cout << "NO";
else {
while (i > 0) {
if (i % 10 != 4 && i % 10 != 7) {
flag = 1;
break;
}
i /= 10;
}
if (flag)
cout << "NO";
else
cout << "YES";
}
}
void fisic() {
int n;
cin >> n;
int v1 = 0, v2 = 0, v3 = 0, x, y, z;
for (int i = 0; i < n; i++) {
cin >> x >> y >> z;
v1 += x;
v2 += y;
v3 += z;
}
if (v1 == 0 && v2 == 0 && v3 == 0)
cout << "YES";
else
cout << "NO";
}
void Lena() {
int n;
cin >> n;
for (int j = 0; j < 2 * n; j++) cout << " ";
cout << 0 << endl;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2 * (n - i - 1); j++) cout << " ";
for (int j = 0; j < i + 1; j++) cout << j << " ";
for (int j = i + 1; j >= 0; j--) {
if (j == 0)
cout << j << endl;
else
cout << j << " ";
}
}
for (int i = n - 2; i >= 0; i--) {
for (int j = 0; j < 2 * (n - i - 1); j++) cout << " ";
for (int j = 0; j < i + 1; j++) cout << j << " ";
for (int j = i + 1; j >= 0; j--) {
if (j == 0)
cout << j << endl;
else
cout << j << " ";
}
}
for (int j = 0; j < 2 * n; j++) cout << " ";
cout << 0 << endl;
}
void Shapur() {
string a;
string b;
cin >> a >> b;
for (int i = 0; i < a.length(); i++) {
if (a[i] == b[i])
cout << 0;
else
cout << 1;
}
}
void Happy2() {
int n;
cin >> n;
vector<int> a = fact(n);
bool flag = 0;
for (int i = 0; i < a.size(); i++) {
if (is_happy(a[i])) {
flag = 1;
break;
}
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void flower() {
vector<int> a;
a.resize(12);
int k;
cin >> k;
for (int i = 0; i < 12; i++) cin >> a[i];
sort(a.begin(), a.end());
int i = 11;
while (k > 0 && i >= 0) {
k -= a[i];
i--;
}
if (i < 0 && k > 0)
cout << -1 << endl;
else
cout << 11 - i << endl;
}
void moroz() {
string a, b, sum;
cin >> a >> b >> sum;
vector<bool> a1;
vector<bool> b1;
vector<bool> sum1;
a1.resize(a.length());
b1.resize(b.length());
sum1.resize(sum.length());
bool flag = 1;
for (int i = 0; i < a1.size(); i++) a1[i] = 1;
for (int i = 0; i < b1.size(); i++) b1[i] = 1;
for (int i = 0; i < sum1.size(); i++) sum1[i] = 1;
for (int i = 0; i < sum.length(); i++) {
for (int j = 0; j < a.length(); j++) {
if (sum[i] == a[j] && a1[j] && sum1[i]) {
a1[j] = 0;
sum1[i] = 0;
break;
}
}
for (int j = 0; j < b.length(); j++) {
if (sum[i] == b[j] && b1[j] && sum1[i]) {
b1[j] = 0;
sum1[i] = 0;
break;
}
}
if (sum1[i]) {
flag = 0;
break;
}
}
if (flag) {
for (int i = 0; i < a1.size(); i++) {
if (a1[i]) {
cout << "NO" << endl;
return;
}
}
for (int i = 0; i < b1.size(); i++) {
if (b1[i]) {
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
} else
cout << "NO" << endl;
}
void Vasia() {
int n;
cin >> n;
int cur;
cin >> cur;
int min = cur;
int max = cur;
int cool = 0;
for (int i = 1; i < n; i++) {
cin >> cur;
if (cur > max) {
max = cur;
cool++;
}
if (cur < min) {
min = cur;
cool++;
}
}
cout << cool;
}
int main() { capslook(); }
| ### 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 NOD(int x, int y) {
if (x == 0) return y;
if (y == 0) return x;
while ((x % y != 0) && (y % x != 0)) {
if (x > y)
x %= y;
else
y %= x;
}
if (x < y)
return x;
else
return y;
}
int NOK(int x, int y) { return (x / NOD(x, y)) * y; }
vector<int> fact(int n) {
vector<int> a;
for (int i = 2; (i - 1) * (i - 1) < n; i++) {
if (n % i == 0) {
if (i != 2) a.push_back(i);
if (i * i != n) a.push_back(n / i);
}
}
return a;
}
bool is_happy(int n) {
if (n == 0) return 0;
bool flag = 1;
while (n > 0) {
if (n % 10 != 4 && n % 10 != 7) {
flag = 0;
break;
}
n /= 10;
}
return flag;
}
void taxi() {
long s1 = 0, s2 = 0, s3 = 0, s4 = 0;
int n;
cin >> n;
int s;
for (int i = 0; i < n; i++) {
cin >> s;
if (s == 1) s1++;
if (s == 2) s2++;
if (s == 3) s3++;
if (s == 4) s4++;
}
if (s3 < s1) {
s4 += s3;
s1 -= s3;
s4 += s2 / 2;
if (s2 % 2 == 1)
s2 = 2;
else
s2 = 0;
s4 += (s2 + s1) / 4;
if ((s2 + s1) % 4 != 0) s4++;
} else {
s4 += s3;
s4 += s2 / 4;
if (s2 % 2 == 1) s4++;
}
cout << s4;
}
void capslook() {
string s;
cin >> s;
if (s.length() == 1) {
if (int(s[0]) < 96)
cout << char(int(s[0]) + 32);
else
cout << char(int(s[0] - 32));
} else {
bool flag;
if (int(s[0]) > 96)
flag = 1;
else
flag = 0;
string ans = "";
if (flag)
ans.push_back(char(int(s[0]) - 32));
else
ans.push_back(char(int(s[0]) + 32));
bool flag_s = 0;
for (int i = 1; i < s.length(); i++) {
if (int(s[i]) > 96) {
flag_s = 1;
break;
} else
ans.push_back(char(int(s[i]) + 32));
}
if (flag_s)
cout << s;
else
cout << ans;
}
}
void sculpture() {
int n;
cin >> n;
vector<int> a = fact(n);
if (a.size()) {
vector<vector<long> > b;
b.resize(a.size());
for (int i = 0; i < b.size(); i++) b[i].resize(n / a[i]);
for (int i = 0; i < b.size(); i++) {
for (int j = 0; j < b[i].size(); j++) b[i][j] = 0;
}
long t;
long all = 0;
for (int i = 0; i < n; i++) {
cin >> t;
all += t;
for (int j = 0; j < b.size(); j++) b[j][i % (n / a[j])] += t;
}
for (int i = 0; i < b.size(); i++) {
for (int j = 0; j < b[i].size(); j++)
if (all < b[i][j]) all = b[i][j];
}
cout << all;
} else {
long t;
long all = 0;
for (int i = 0; i < n; i++) {
cin >> t;
all += t;
}
cout << all;
}
}
void team() {
int n;
cin >> n;
int a, b, c;
int ans = 0;
for (int i = 0; i < n; i++) {
cin >> a >> b >> c;
if (a + b + c > 1) ans++;
}
cout << ans;
}
void general() {
int n;
cin >> n;
vector<int> a;
a.resize(n);
for (int i = 0; i < n; i++) cin >> a[i];
int max = 0;
int min = n - 1;
for (int i = 0; i < n; i++) {
if (a[max] < a[i]) max = i;
if (a[min] >= a[i]) min = i;
}
if (max > min)
cout << max + n - 1 - min - 1;
else
cout << max + n - 1 - min;
}
void present() {
int n;
cin >> n;
vector<int> p;
p.resize(n);
for (int i = 0; i < n; i++) {
cin >> p[i];
p[i]--;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
if (p[j] == i) cout << j + 1 << " ";
}
}
void football() {
string s;
cin >> s;
int ans = 1;
for (int i = 1; i < s.length(); i++) {
if (s[i] == s[i - 1])
ans++;
else
ans = 1;
if (ans == 7) {
cout << "YES";
break;
}
}
if (ans < 7) cout << "NO";
}
void Valera() {
int* s = new int[4];
bool* flag = new bool[4];
for (int i = 0; i < 4; i++) {
cin >> s[i];
flag[i] = 1;
}
int ans = 0;
for (int i = 0; i < 4; i++) {
for (int j = i + 1; j < 4; j++) {
if (s[i] == s[j] && flag[j]) {
ans++;
flag[j] = 0;
}
}
}
cout << ans;
}
void Happy() {
long long n;
cin >> n;
int i = 0;
while (n > 0) {
if (n % 10 == 4 || n % 10 == 7) i++;
n /= 10;
}
bool flag = 0;
if (i == 0)
cout << "NO";
else {
while (i > 0) {
if (i % 10 != 4 && i % 10 != 7) {
flag = 1;
break;
}
i /= 10;
}
if (flag)
cout << "NO";
else
cout << "YES";
}
}
void fisic() {
int n;
cin >> n;
int v1 = 0, v2 = 0, v3 = 0, x, y, z;
for (int i = 0; i < n; i++) {
cin >> x >> y >> z;
v1 += x;
v2 += y;
v3 += z;
}
if (v1 == 0 && v2 == 0 && v3 == 0)
cout << "YES";
else
cout << "NO";
}
void Lena() {
int n;
cin >> n;
for (int j = 0; j < 2 * n; j++) cout << " ";
cout << 0 << endl;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2 * (n - i - 1); j++) cout << " ";
for (int j = 0; j < i + 1; j++) cout << j << " ";
for (int j = i + 1; j >= 0; j--) {
if (j == 0)
cout << j << endl;
else
cout << j << " ";
}
}
for (int i = n - 2; i >= 0; i--) {
for (int j = 0; j < 2 * (n - i - 1); j++) cout << " ";
for (int j = 0; j < i + 1; j++) cout << j << " ";
for (int j = i + 1; j >= 0; j--) {
if (j == 0)
cout << j << endl;
else
cout << j << " ";
}
}
for (int j = 0; j < 2 * n; j++) cout << " ";
cout << 0 << endl;
}
void Shapur() {
string a;
string b;
cin >> a >> b;
for (int i = 0; i < a.length(); i++) {
if (a[i] == b[i])
cout << 0;
else
cout << 1;
}
}
void Happy2() {
int n;
cin >> n;
vector<int> a = fact(n);
bool flag = 0;
for (int i = 0; i < a.size(); i++) {
if (is_happy(a[i])) {
flag = 1;
break;
}
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void flower() {
vector<int> a;
a.resize(12);
int k;
cin >> k;
for (int i = 0; i < 12; i++) cin >> a[i];
sort(a.begin(), a.end());
int i = 11;
while (k > 0 && i >= 0) {
k -= a[i];
i--;
}
if (i < 0 && k > 0)
cout << -1 << endl;
else
cout << 11 - i << endl;
}
void moroz() {
string a, b, sum;
cin >> a >> b >> sum;
vector<bool> a1;
vector<bool> b1;
vector<bool> sum1;
a1.resize(a.length());
b1.resize(b.length());
sum1.resize(sum.length());
bool flag = 1;
for (int i = 0; i < a1.size(); i++) a1[i] = 1;
for (int i = 0; i < b1.size(); i++) b1[i] = 1;
for (int i = 0; i < sum1.size(); i++) sum1[i] = 1;
for (int i = 0; i < sum.length(); i++) {
for (int j = 0; j < a.length(); j++) {
if (sum[i] == a[j] && a1[j] && sum1[i]) {
a1[j] = 0;
sum1[i] = 0;
break;
}
}
for (int j = 0; j < b.length(); j++) {
if (sum[i] == b[j] && b1[j] && sum1[i]) {
b1[j] = 0;
sum1[i] = 0;
break;
}
}
if (sum1[i]) {
flag = 0;
break;
}
}
if (flag) {
for (int i = 0; i < a1.size(); i++) {
if (a1[i]) {
cout << "NO" << endl;
return;
}
}
for (int i = 0; i < b1.size(); i++) {
if (b1[i]) {
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
} else
cout << "NO" << endl;
}
void Vasia() {
int n;
cin >> n;
int cur;
cin >> cur;
int min = cur;
int max = cur;
int cool = 0;
for (int i = 1; i < n; i++) {
cin >> cur;
if (cur > max) {
max = cur;
cool++;
}
if (cur < min) {
min = cur;
cool++;
}
}
cout << cool;
}
int main() { capslook(); }
``` |
#include <bits/stdc++.h>
using namespace std;
bool check(string s) {
for (int i = s.size() - 1; i > 0; i--)
if (!((0 <= s[i] - 'A') && (s[i] - 'A' <= 26))) return false;
return true;
}
int main() {
string s;
char u, l;
cin >> s;
if (check(s)) {
for (int i = 0; i < s.size(); i++) {
u = toupper(s[i]);
l = tolower(s[i]);
if (s[i] == u)
cout << l;
else
cout << u;
}
return 0;
}
cout << s;
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;
bool check(string s) {
for (int i = s.size() - 1; i > 0; i--)
if (!((0 <= s[i] - 'A') && (s[i] - 'A' <= 26))) return false;
return true;
}
int main() {
string s;
char u, l;
cin >> s;
if (check(s)) {
for (int i = 0; i < s.size(); i++) {
u = toupper(s[i]);
l = tolower(s[i]);
if (s[i] == u)
cout << l;
else
cout << u;
}
return 0;
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
char a[100];
int len, sign1, sign2, i;
gets(a);
len = strlen(a);
sign1 = 0;
sign2 = 0;
if (a[0] < 'A' || a[0] > 'Z') sign1++;
for (i = 0; i < len; i++) {
if (a[i] >= 'A' && a[i] <= 'Z') sign2++;
}
if (sign2 == len || sign2 == len - 1 && sign1 == 1) {
for (i = 0; i < len; i++) {
if (a[i] >= 'a' && a[i] <= 'z')
a[i] = a[i] - 32;
else if (a[i] >= 'A' && a[i] <= 'Z')
a[i] = a[i] + 32;
}
}
for (i = 0; i < len; 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() {
char a[100];
int len, sign1, sign2, i;
gets(a);
len = strlen(a);
sign1 = 0;
sign2 = 0;
if (a[0] < 'A' || a[0] > 'Z') sign1++;
for (i = 0; i < len; i++) {
if (a[i] >= 'A' && a[i] <= 'Z') sign2++;
}
if (sign2 == len || sign2 == len - 1 && sign1 == 1) {
for (i = 0; i < len; i++) {
if (a[i] >= 'a' && a[i] <= 'z')
a[i] = a[i] - 32;
else if (a[i] >= 'A' && a[i] <= 'Z')
a[i] = a[i] + 32;
}
}
for (i = 0; i < len; i++) printf("%c", a[i]);
printf("\n");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int cnt = 0;
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == tolower(s[i])) cnt++;
}
if (cnt == 0) {
for (int i = 0; i < s.length(); i++) s[i] = tolower(s[i]);
cout << s << endl;
} else if (cnt == 1 && s[0] == tolower(s[0])) {
s[0] = toupper(s[0]);
for (int i = 1; i < s.length(); i++) s[i] = tolower(s[i]);
cout << s << endl;
} else
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 main() {
int cnt = 0;
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == tolower(s[i])) cnt++;
}
if (cnt == 0) {
for (int i = 0; i < s.length(); i++) s[i] = tolower(s[i]);
cout << s << endl;
} else if (cnt == 1 && s[0] == tolower(s[0])) {
s[0] = toupper(s[0]);
for (int i = 1; i < s.length(); i++) s[i] = tolower(s[i]);
cout << s << endl;
} else
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
char a[100];
int l = 0;
scanf("%s", a);
for (int i = 1; i < strlen(a); i++) {
if (a[i] >= 65 && a[i] <= 90) {
l++;
}
}
if (l == strlen(a) - 1) {
for (int 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;
}
}
}
printf("%s\n", a);
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() {
char a[100];
int l = 0;
scanf("%s", a);
for (int i = 1; i < strlen(a); i++) {
if (a[i] >= 65 && a[i] <= 90) {
l++;
}
}
if (l == strlen(a) - 1) {
for (int 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;
}
}
}
printf("%s\n", a);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
char swichCase(char c) {
if ('a' <= c && c <= 'z') {
c += 'A' - 'a';
} else {
c += 'a' - 'A';
}
return c;
}
string solve(string s) {
bool caps = true;
for (int i = 1; i < s.size(); ++i) {
if ('a' <= s[i] && s[i] <= 'z') {
caps = false;
}
}
if (caps) {
for (int i = 0; i < s.size(); ++i) {
s[i] = swichCase(s[i]);
}
}
return s;
}
int main(int argc, char* argv[]) {
string s;
cin >> s;
cout << solve(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;
char swichCase(char c) {
if ('a' <= c && c <= 'z') {
c += 'A' - 'a';
} else {
c += 'a' - 'A';
}
return c;
}
string solve(string s) {
bool caps = true;
for (int i = 1; i < s.size(); ++i) {
if ('a' <= s[i] && s[i] <= 'z') {
caps = false;
}
}
if (caps) {
for (int i = 0; i < s.size(); ++i) {
s[i] = swichCase(s[i]);
}
}
return s;
}
int main(int argc, char* argv[]) {
string s;
cin >> s;
cout << solve(s) << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
char s[102];
int main() {
int i = 0, k = 0, j;
cin >> s;
while (s[i] != '\0') {
if (s[i] >= 'a' && s[i] <= 'z' && i != 0) k++;
i++;
}
if (k == 0 && i != 1) {
for (j = 0; j < i; j++)
if (s[j] >= 'a' && s[j] <= 'z')
s[j] = s[j] + 'A' - 'a';
else
s[j] = s[j] + 'a' - 'A';
}
if (i == 1 && (s[0] >= 'a' && s[0] <= 'z'))
s[0] = s[0] + 'A' - 'a';
else if (i == 1 && (s[0] >= 'A' && s[0] <= 'Z'))
s[0] = s[0] + 'a' - 'A';
for (k = 0; k < i; k++) cout << s[k];
cout << 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;
char s[102];
int main() {
int i = 0, k = 0, j;
cin >> s;
while (s[i] != '\0') {
if (s[i] >= 'a' && s[i] <= 'z' && i != 0) k++;
i++;
}
if (k == 0 && i != 1) {
for (j = 0; j < i; j++)
if (s[j] >= 'a' && s[j] <= 'z')
s[j] = s[j] + 'A' - 'a';
else
s[j] = s[j] + 'a' - 'A';
}
if (i == 1 && (s[0] >= 'a' && s[0] <= 'z'))
s[0] = s[0] + 'A' - 'a';
else if (i == 1 && (s[0] >= 'A' && s[0] <= 'Z'))
s[0] = s[0] + 'a' - 'A';
for (k = 0; k < i; k++) cout << s[k];
cout << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
bool check(char *s) {
++s;
while (*s != '\0') {
if (*s >= 'a') return false;
++s;
}
return true;
}
void solve(char *s) {
if (check(s)) {
if (*s >= 'a') {
*s -= 32;
++s;
}
while (*s != '\0') {
if (*s <= 'Z') *s += 32;
++s;
}
}
}
int main(void) {
char in[105];
scanf("%s", in);
solve(in);
printf("%s", in);
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>
bool check(char *s) {
++s;
while (*s != '\0') {
if (*s >= 'a') return false;
++s;
}
return true;
}
void solve(char *s) {
if (check(s)) {
if (*s >= 'a') {
*s -= 32;
++s;
}
while (*s != '\0') {
if (*s <= 'Z') *s += 32;
++s;
}
}
}
int main(void) {
char in[105];
scanf("%s", in);
solve(in);
printf("%s", in);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string w;
cin >> w;
bool ch = 1;
for (int i = 1; i < w.size(); i++) {
if (w[i] > 92 && ch) {
ch = !ch;
break;
}
}
if (ch) {
for (int i = 0; i < w.size(); i++) {
if (w[i] > 92)
w[i] = (char)(w[i] - 32);
else
w[i] = (char)(w[i] + 32);
}
cout << w << endl;
} else
cout << w << 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;
int main() {
string w;
cin >> w;
bool ch = 1;
for (int i = 1; i < w.size(); i++) {
if (w[i] > 92 && ch) {
ch = !ch;
break;
}
}
if (ch) {
for (int i = 0; i < w.size(); i++) {
if (w[i] > 92)
w[i] = (char)(w[i] - 32);
else
w[i] = (char)(w[i] + 32);
}
cout << w << endl;
} else
cout << w << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
string str;
cin >> str;
int length = str.length();
int count = 0;
for (int i = 1; i < length; i++) {
if (isupper(str[i])) {
count++;
}
}
if (length == count + 1) {
if (isupper(str[0])) {
str[0] = tolower(str[0]);
} else {
str[0] = toupper(str[0]);
}
for (int i = 1; i < length; i++) {
str[i] = tolower(str[i]);
}
}
cout << str;
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(int argc, char const *argv[]) {
string str;
cin >> str;
int length = str.length();
int count = 0;
for (int i = 1; i < length; i++) {
if (isupper(str[i])) {
count++;
}
}
if (length == count + 1) {
if (isupper(str[0])) {
str[0] = tolower(str[0]);
} else {
str[0] = toupper(str[0]);
}
for (int i = 1; i < length; i++) {
str[i] = tolower(str[i]);
}
}
cout << str;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.length() > 1) {
if (s[0] == toupper(s[0]) && s[1] == tolower(s[1])) {
cout << s;
return 0;
} else if (s[0] == tolower(s[0]) && s[1] == tolower(s[1])) {
cout << s;
return 0;
} else {
for (int i = 2; i < s.length(); i++) {
if (s[i] != toupper(s[i])) {
cout << s;
return 0;
}
}
for (int i = 0; i < s.length(); i++) {
if (s[i] == toupper(s[i])) {
s[i] = tolower(s[i]);
} else {
s[i] = toupper(s[i]);
}
}
cout << s;
}
} else {
if (s[0] == toupper(s[0])) {
s[0] = tolower(s[0]);
} else {
s[0] = toupper(s[0]);
}
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;
if (s.length() > 1) {
if (s[0] == toupper(s[0]) && s[1] == tolower(s[1])) {
cout << s;
return 0;
} else if (s[0] == tolower(s[0]) && s[1] == tolower(s[1])) {
cout << s;
return 0;
} else {
for (int i = 2; i < s.length(); i++) {
if (s[i] != toupper(s[i])) {
cout << s;
return 0;
}
}
for (int i = 0; i < s.length(); i++) {
if (s[i] == toupper(s[i])) {
s[i] = tolower(s[i]);
} else {
s[i] = toupper(s[i]);
}
}
cout << s;
}
} else {
if (s[0] == toupper(s[0])) {
s[0] = tolower(s[0]);
} else {
s[0] = toupper(s[0]);
}
cout << s;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, j, k, l, a, b, c, d, f1, f2;
string s1, s2, s3;
cin >> s1;
f1 = 1;
for (i = 1; i < s1.size(); i++) {
if (s1[i] >= 65 && s1[i] <= 90) {
f1 = 1;
} else {
f1 = 0;
break;
}
}
if (f1 == 0) {
cout << s1 << endl;
} else if (f1 == 1) {
for (i = 0; i < s1.size(); i++) {
if (s1[i] >= 65 && s1[i] <= 90) {
s1[i] = s1[i] + 32;
} else if (s1[i] >= 97 && s1[i] <= 122) {
s1[i] = s1[i] - 32;
}
}
cout << s1 << 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() {
long long n, i, j, k, l, a, b, c, d, f1, f2;
string s1, s2, s3;
cin >> s1;
f1 = 1;
for (i = 1; i < s1.size(); i++) {
if (s1[i] >= 65 && s1[i] <= 90) {
f1 = 1;
} else {
f1 = 0;
break;
}
}
if (f1 == 0) {
cout << s1 << endl;
} else if (f1 == 1) {
for (i = 0; i < s1.size(); i++) {
if (s1[i] >= 65 && s1[i] <= 90) {
s1[i] = s1[i] + 32;
} else if (s1[i] >= 97 && s1[i] <= 122) {
s1[i] = s1[i] - 32;
}
}
cout << s1 << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void change(string s) {
for (int i = 0; i < s.size(); i++) {
if (s[i] <= 'Z' && s[i] >= 'A') {
s[i] = s[i] - 'A' + 'a';
} else if (s[i] <= 'z' && s[i] >= 'a') {
s[i] = s[i] - 'a' + 'A';
}
}
cout << s << endl;
}
int main() {
string s;
cin >> s;
int sum = 0;
for (int i = 1; i < s.size(); i++) {
if (s[i] <= 'Z' && s[i] >= 'A') {
sum++;
}
}
if (sum == s.size() - 1) {
change(s);
} 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;
void change(string s) {
for (int i = 0; i < s.size(); i++) {
if (s[i] <= 'Z' && s[i] >= 'A') {
s[i] = s[i] - 'A' + 'a';
} else if (s[i] <= 'z' && s[i] >= 'a') {
s[i] = s[i] - 'a' + 'A';
}
}
cout << s << endl;
}
int main() {
string s;
cin >> s;
int sum = 0;
for (int i = 1; i < s.size(); i++) {
if (s[i] <= 'Z' && s[i] >= 'A') {
sum++;
}
}
if (sum == s.size() - 1) {
change(s);
} else {
cout << s << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char c[101];
int i, len;
bool vis;
while (cin >> c) {
len = strlen(c);
for (i = 1, vis = true; i < len; i++)
if (c[i] >= 97) vis = false;
if (vis) {
if (c[0] >= 97)
cout << char(c[0] - 32);
else
cout << char(c[0] + 32);
for (i = 1; i < len; i++) {
if (c[i] >= 97)
cout << c[i];
else
cout << char(c[i] + 32);
}
} else
cout << c;
cout << 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;
int main() {
char c[101];
int i, len;
bool vis;
while (cin >> c) {
len = strlen(c);
for (i = 1, vis = true; i < len; i++)
if (c[i] >= 97) vis = false;
if (vis) {
if (c[0] >= 97)
cout << char(c[0] - 32);
else
cout << char(c[0] + 32);
for (i = 1; i < len; i++) {
if (c[i] >= 97)
cout << c[i];
else
cout << char(c[i] + 32);
}
} else
cout << c;
cout << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int flag = 0;
for (int i = 1; i < s.length(); i++) {
if (!isupper(s[i])) {
flag = 1;
break;
}
}
if (flag == 1) {
cout << s;
} else {
if (islower(s[0])) {
s[0] = toupper(s[0]);
} else if (isupper(s[0])) {
s[0] = tolower(s[0]);
}
for (int i = 1; i < s.length(); i++) {
s[i] = tolower(s[i]);
}
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() {
string s;
cin >> s;
int flag = 0;
for (int i = 1; i < s.length(); i++) {
if (!isupper(s[i])) {
flag = 1;
break;
}
}
if (flag == 1) {
cout << s;
} else {
if (islower(s[0])) {
s[0] = toupper(s[0]);
} else if (isupper(s[0])) {
s[0] = tolower(s[0]);
}
for (int i = 1; i < s.length(); i++) {
s[i] = tolower(s[i]);
}
cout << s;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool upr(string s) {
for (int k = 1; k < s.length(); k++) {
if (s[k] == toupper(s[k]))
continue;
else
return false;
}
return true;
}
int main() {
string m;
while (cin >> m) {
if ((m[0] == tolower(m[0]) && upr(m))) {
putchar(toupper(m[0]));
for (int i = 1; i < m.length(); i++) {
putchar(tolower(m[i]));
}
} else if ((m[0] == toupper(m[0]) && upr(m)))
for (int i = 0; i < m.length(); i++) {
putchar(tolower(m[i]));
}
else
cout << m;
}
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;
bool upr(string s) {
for (int k = 1; k < s.length(); k++) {
if (s[k] == toupper(s[k]))
continue;
else
return false;
}
return true;
}
int main() {
string m;
while (cin >> m) {
if ((m[0] == tolower(m[0]) && upr(m))) {
putchar(toupper(m[0]));
for (int i = 1; i < m.length(); i++) {
putchar(tolower(m[i]));
}
} else if ((m[0] == toupper(m[0]) && upr(m)))
for (int i = 0; i < m.length(); i++) {
putchar(tolower(m[i]));
}
else
cout << m;
}
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
std::string input;
std::cin >> input;
bool is_all_upper = true;
bool later_upper = true;
for (int i = 0; i < input.size(); i++) {
if (i > 0 && later_upper) {
later_upper = later_upper && isupper(input[i]);
}
is_all_upper = is_all_upper && isupper(input[i]);
}
if (is_all_upper) {
std::transform(input.begin(), input.end(), input.begin(), ::tolower);
} else if (later_upper) {
std::transform(input.begin(), input.end(), input.begin(), ::tolower);
input[0] = toupper(input[0]);
}
std::cout << input;
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>
int main() {
std::string input;
std::cin >> input;
bool is_all_upper = true;
bool later_upper = true;
for (int i = 0; i < input.size(); i++) {
if (i > 0 && later_upper) {
later_upper = later_upper && isupper(input[i]);
}
is_all_upper = is_all_upper && isupper(input[i]);
}
if (is_all_upper) {
std::transform(input.begin(), input.end(), input.begin(), ::tolower);
} else if (later_upper) {
std::transform(input.begin(), input.end(), input.begin(), ::tolower);
input[0] = toupper(input[0]);
}
std::cout << input;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int i, a, b, c;
int p = 1;
char m[100];
scanf("%s", &m);
for (i = 1; i < strlen(m); i++) {
if (m[i] >= 'a') {
p = 0;
break;
}
}
if (p) {
for (i = 0; i < strlen(m); i++) {
if (m[i] >= 'a') {
m[i] = m[i] - ('a' - 'A');
} else {
m[i] = m[i] + ('a' - 'A');
}
}
}
printf("%s", m);
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 i, a, b, c;
int p = 1;
char m[100];
scanf("%s", &m);
for (i = 1; i < strlen(m); i++) {
if (m[i] >= 'a') {
p = 0;
break;
}
}
if (p) {
for (i = 0; i < strlen(m); i++) {
if (m[i] >= 'a') {
m[i] = m[i] - ('a' - 'A');
} else {
m[i] = m[i] + ('a' - 'A');
}
}
}
printf("%s", m);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int f = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
f = 0;
} else {
if (i == 0) {
continue;
}
f = 1;
break;
}
}
if (f == 0) {
if (s[0] >= 'a' && s[0] <= 'z') {
cout << char(toupper(s[0]));
for (int i = 1; i < s.size(); i++) {
cout << char(tolower(s[i]));
}
cout << endl;
} else {
for (int i = 0; i < s.size(); i++) {
cout << char(tolower(s[i]));
}
cout << endl;
}
} else {
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() {
string s;
cin >> s;
int f = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
f = 0;
} else {
if (i == 0) {
continue;
}
f = 1;
break;
}
}
if (f == 0) {
if (s[0] >= 'a' && s[0] <= 'z') {
cout << char(toupper(s[0]));
for (int i = 1; i < s.size(); i++) {
cout << char(tolower(s[i]));
}
cout << endl;
} else {
for (int i = 0; i < s.size(); i++) {
cout << char(tolower(s[i]));
}
cout << endl;
}
} else {
cout << s << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i;
char a[101];
cin.getline(a, 101);
for (i = 1; isupper(a[i]); i++) {
}
if (!a[i]) {
for (i = 0; a[i]; i++) {
if (isupper(a[i])) {
a[i] = tolower(a[i]);
} else {
a[i] = toupper(a[i]);
}
}
}
cout << a;
cin.get();
}
| ### 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() {
int i;
char a[101];
cin.getline(a, 101);
for (i = 1; isupper(a[i]); i++) {
}
if (!a[i]) {
for (i = 0; a[i]; i++) {
if (isupper(a[i])) {
a[i] = tolower(a[i]);
} else {
a[i] = toupper(a[i]);
}
}
}
cout << a;
cin.get();
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.length();
if (s[1] == '\0') {
if (s[0] >= 'a' && s[0] <= 'z') {
s[0] = s[0] - 32;
} else if (s[0] >= 'A' && s[0] <= 'Z') {
s[0] = s[0] + 32;
}
} else {
if (s[0] >= 'a' && s[0] <= 'z') {
int d = 0;
for (int i = 1; i < n; i++)
if (s[i] >= 'A' && s[i] <= 'Z') d++;
if (d == n - 1) {
s[0] = s[0] - 32;
for (int i = 1; i < n; i++) {
s[i] = s[i] + 32;
}
}
}
if (s[0] >= 'A' && s[0] <= 'Z') {
int d = 0;
for (int i = 0; i < n; i++)
if (s[i] >= 'A' && s[i] <= 'Z') d++;
if (d == n) {
for (int i = 0; i < n; i++) {
s[i] = s[i] + 32;
}
}
}
}
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() {
string s;
cin >> s;
int n = s.length();
if (s[1] == '\0') {
if (s[0] >= 'a' && s[0] <= 'z') {
s[0] = s[0] - 32;
} else if (s[0] >= 'A' && s[0] <= 'Z') {
s[0] = s[0] + 32;
}
} else {
if (s[0] >= 'a' && s[0] <= 'z') {
int d = 0;
for (int i = 1; i < n; i++)
if (s[i] >= 'A' && s[i] <= 'Z') d++;
if (d == n - 1) {
s[0] = s[0] - 32;
for (int i = 1; i < n; i++) {
s[i] = s[i] + 32;
}
}
}
if (s[0] >= 'A' && s[0] <= 'Z') {
int d = 0;
for (int i = 0; i < n; i++)
if (s[i] >= 'A' && s[i] <= 'Z') d++;
if (d == n) {
for (int i = 0; i < n; i++) {
s[i] = s[i] + 32;
}
}
}
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void change(string &s) {
for (int i = 0; i < s.length(); i++) {
s[i] = (s[i] < 97) ? tolower(s[i]) : toupper(s[i]);
}
}
int main() {
string s;
cin >> s;
int len = s.length(), capCount = 0;
bool Caps = false;
for (int i = 0; i < len; i++) capCount += ((int)s[i] < 97);
if (capCount == len || (capCount == len - 1 && s[0] >= 97)) change(s);
cout << s << 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;
void change(string &s) {
for (int i = 0; i < s.length(); i++) {
s[i] = (s[i] < 97) ? tolower(s[i]) : toupper(s[i]);
}
}
int main() {
string s;
cin >> s;
int len = s.length(), capCount = 0;
bool Caps = false;
for (int i = 0; i < len; i++) capCount += ((int)s[i] < 97);
if (capCount == len || (capCount == len - 1 && s[0] >= 97)) change(s);
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin >> s;
if (islower(s[0])) {
for (int i = 1; i < s.size(); i++) {
if (islower(s[i])) {
cout << s;
return 0;
}
}
s[0] = toupper(s[0]);
cout << s[0];
for (int i = 1; i < s.size(); i++) {
if (isupper(s[i])) s[i] = tolower(s[i]);
cout << s[i];
}
return 0;
}
if (isupper(s[0])) {
for (int i = 0; i < s.size(); i++) {
if (islower(s[i])) {
cout << s;
return 0;
}
}
s[0] = tolower(s[0]);
cout << s[0];
for (int i = 1; i < s.size(); i++) {
if (isupper(s[i])) s[i] = tolower(s[i]);
cout << s[i];
}
}
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;
string s;
int main() {
cin >> s;
if (islower(s[0])) {
for (int i = 1; i < s.size(); i++) {
if (islower(s[i])) {
cout << s;
return 0;
}
}
s[0] = toupper(s[0]);
cout << s[0];
for (int i = 1; i < s.size(); i++) {
if (isupper(s[i])) s[i] = tolower(s[i]);
cout << s[i];
}
return 0;
}
if (isupper(s[0])) {
for (int i = 0; i < s.size(); i++) {
if (islower(s[i])) {
cout << s;
return 0;
}
}
s[0] = tolower(s[0]);
cout << s[0];
for (int i = 1; i < s.size(); i++) {
if (isupper(s[i])) s[i] = tolower(s[i]);
cout << s[i];
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
getline(cin, str);
int l = str.size();
int cnt = 0;
for (int i = 0; i < l; i++) {
if (str[i] >= 'A' && str[i] <= 'Z') {
cnt++;
}
}
if (cnt == l || (cnt == l - 1 && (str[0] >= 'a' && str[0] <= 'z'))) {
if (str[0] >= 'a' && str[0] <= 'z') {
str[0] = str[0] - 'a' + 'A';
}
int k = 0;
if (cnt == l - 1) {
k = 1;
}
for (int i = k; i < l; i++) {
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;
getline(cin, str);
int l = str.size();
int cnt = 0;
for (int i = 0; i < l; i++) {
if (str[i] >= 'A' && str[i] <= 'Z') {
cnt++;
}
}
if (cnt == l || (cnt == l - 1 && (str[0] >= 'a' && str[0] <= 'z'))) {
if (str[0] >= 'a' && str[0] <= 'z') {
str[0] = str[0] - 'a' + 'A';
}
int k = 0;
if (cnt == l - 1) {
k = 1;
}
for (int i = k; i < l; i++) {
str[i] = str[i] - 'A' + 'a';
}
}
cout << str << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int count = 0;
int len = s.size();
bool small = false;
for (int i = 0; i < len; i++) {
if (s[i] < 'a') {
count++;
}
if (s[0] >= 'a') {
small = true;
}
}
if (count == len || (count == len - 1 && small)) {
for (int i = 0; i < len; i++) {
if (i == 0 && count == len) {
s[i] = s[i] + 32;
} else if (i == 0 && small) {
s[i] = s[i] - 32;
} else {
s[i] = s[i] + 32;
}
}
}
cout << s << endl;
}
| ### 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 count = 0;
int len = s.size();
bool small = false;
for (int i = 0; i < len; i++) {
if (s[i] < 'a') {
count++;
}
if (s[0] >= 'a') {
small = true;
}
}
if (count == len || (count == len - 1 && small)) {
for (int i = 0; i < len; i++) {
if (i == 0 && count == len) {
s[i] = s[i] + 32;
} else if (i == 0 && small) {
s[i] = s[i] - 32;
} else {
s[i] = s[i] + 32;
}
}
}
cout << s << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int mayus = 0;
string palabra;
cin >> palabra;
int n = palabra.size();
for (int i = 0; i < n; i++) {
if ((int)palabra[i] >= 65 && (int)palabra[i] <= 90) {
mayus++;
}
}
if (mayus == n) {
for (int i = 0; i < n; i++) {
palabra[i] = (char)(palabra[i] + 32);
}
}
if (mayus == n - 1 && (palabra[0] < 65 || palabra[0] > 90)) {
palabra[0] = (char)((int)palabra[0] - 32);
for (int i = 1; i < n; i++) {
palabra[i] = (char)((int)palabra[i] + 32);
}
}
cout << palabra;
}
| ### 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 mayus = 0;
string palabra;
cin >> palabra;
int n = palabra.size();
for (int i = 0; i < n; i++) {
if ((int)palabra[i] >= 65 && (int)palabra[i] <= 90) {
mayus++;
}
}
if (mayus == n) {
for (int i = 0; i < n; i++) {
palabra[i] = (char)(palabra[i] + 32);
}
}
if (mayus == n - 1 && (palabra[0] < 65 || palabra[0] > 90)) {
palabra[0] = (char)((int)palabra[0] - 32);
for (int i = 1; i < n; i++) {
palabra[i] = (char)((int)palabra[i] + 32);
}
}
cout << palabra;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int upper(string s) {
for (int i = 0; s[i] != '\0'; i++) {
if (isupper(s[i]) == 0) return 0;
}
return 1;
}
int func(string s) {
if (islower(s[0]) == 0)
return 0;
else {
for (int i = 1; s[i] != '\0'; i++) {
if (isupper(s[i]) == 0) return 0;
}
return 1;
}
}
int main() {
string s;
cin >> s;
if (upper(s) == 1) {
for (int i = 0; s[i] != '\0'; i++) cout << char(tolower(s[i]));
} else if (func(s) == 1) {
cout << char(toupper(s[0]));
for (int i = 1; s[i] != '\0'; i++) cout << char(tolower(s[i]));
} 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 upper(string s) {
for (int i = 0; s[i] != '\0'; i++) {
if (isupper(s[i]) == 0) return 0;
}
return 1;
}
int func(string s) {
if (islower(s[0]) == 0)
return 0;
else {
for (int i = 1; s[i] != '\0'; i++) {
if (isupper(s[i]) == 0) return 0;
}
return 1;
}
}
int main() {
string s;
cin >> s;
if (upper(s) == 1) {
for (int i = 0; s[i] != '\0'; i++) cout << char(tolower(s[i]));
} else if (func(s) == 1) {
cout << char(toupper(s[0]));
for (int i = 1; s[i] != '\0'; i++) cout << char(tolower(s[i]));
} else
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int sum = 0;
for (int i = 0; i < s.size(); i++)
if ((int)(s[i]) <= 122 && (int)(s[i]) >= 97) sum++;
if (sum > 1 || sum == 1 && (int)(s[0]) <= 90 && 65 <= (int)(s[0]))
cout << s << endl;
else {
for (int i = 0; i < s.size(); i++) {
if ((int)(s[i]) <= 122 && (int)(s[i]) >= 97)
cout << (char)((int)(s[i]) - 32);
else
cout << (char)((int)(s[i]) + 32);
}
cout << 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;
int sum = 0;
for (int i = 0; i < s.size(); i++)
if ((int)(s[i]) <= 122 && (int)(s[i]) >= 97) sum++;
if (sum > 1 || sum == 1 && (int)(s[0]) <= 90 && 65 <= (int)(s[0]))
cout << s << endl;
else {
for (int i = 0; i < s.size(); i++) {
if ((int)(s[i]) <= 122 && (int)(s[i]) >= 97)
cout << (char)((int)(s[i]) - 32);
else
cout << (char)((int)(s[i]) + 32);
}
cout << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[101];
cin >> s;
int i, capital = 0, small = 0, len = strlen(s);
if (len == 1) {
if (s[0] >= 'A' && s[0] <= 'Z')
s[0] = s[0] + 32;
else if (s[0] >= 'a' && s[0] <= 'z')
s[0] = s[0] - 32;
cout << s << endl;
} else {
if (s[0] >= 'a' && s[0] <= 'z') {
i = 1;
while (s[i] != '\0') {
if (s[i] >= 'A' && s[i] <= 'Z')
capital = 1;
else
small = 1;
i++;
}
if (capital == 1 && small == 0) {
i = 1;
while (s[i] != '\0') {
s[i] = s[i] + 32;
i++;
}
s[0] = toupper(s[0]);
cout << s << endl;
} else if (capital == 1 && small == 1)
cout << s << endl;
else if (capital == 0 && small == 1)
cout << s << endl;
} else if (s[0] >= 'A' && s[0] <= 'Z') {
i = 1;
while (s[i] != '\0') {
if (s[i] >= 'A' && s[i] <= 'Z')
capital = 1;
else
small = 1;
i++;
}
if (capital == 0 && small == 1) {
cout << s << endl;
} else if (capital == 1 && small == 1)
cout << s << endl;
else if (capital == 1 && small == 0) {
i = 0;
while (s[i] != '\0') {
s[i] = s[i] + 32;
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() {
char s[101];
cin >> s;
int i, capital = 0, small = 0, len = strlen(s);
if (len == 1) {
if (s[0] >= 'A' && s[0] <= 'Z')
s[0] = s[0] + 32;
else if (s[0] >= 'a' && s[0] <= 'z')
s[0] = s[0] - 32;
cout << s << endl;
} else {
if (s[0] >= 'a' && s[0] <= 'z') {
i = 1;
while (s[i] != '\0') {
if (s[i] >= 'A' && s[i] <= 'Z')
capital = 1;
else
small = 1;
i++;
}
if (capital == 1 && small == 0) {
i = 1;
while (s[i] != '\0') {
s[i] = s[i] + 32;
i++;
}
s[0] = toupper(s[0]);
cout << s << endl;
} else if (capital == 1 && small == 1)
cout << s << endl;
else if (capital == 0 && small == 1)
cout << s << endl;
} else if (s[0] >= 'A' && s[0] <= 'Z') {
i = 1;
while (s[i] != '\0') {
if (s[i] >= 'A' && s[i] <= 'Z')
capital = 1;
else
small = 1;
i++;
}
if (capital == 0 && small == 1) {
cout << s << endl;
} else if (capital == 1 && small == 1)
cout << s << endl;
else if (capital == 1 && small == 0) {
i = 0;
while (s[i] != '\0') {
s[i] = s[i] + 32;
i++;
}
cout << s << endl;
}
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
char a[100];
int main() {
int i, l, c = 0;
scanf("%s", a);
l = strlen(a);
for (i = 1; i < l; i++) {
if (a[i] <= 'Z') {
c++;
}
}
int t = 0;
if (a[1] <= 'Z' && c >= l - 1) t++;
if (t != 0) {
for (i = 0; i < l; i++) {
if (a[i] >= 'a') {
a[i] = a[i] - 'a' + 'A';
} else {
a[i] = a[i] - 'A' + 'a';
}
}
}
printf("%s", a);
}
| ### 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;
char a[100];
int main() {
int i, l, c = 0;
scanf("%s", a);
l = strlen(a);
for (i = 1; i < l; i++) {
if (a[i] <= 'Z') {
c++;
}
}
int t = 0;
if (a[1] <= 'Z' && c >= l - 1) t++;
if (t != 0) {
for (i = 0; i < l; i++) {
if (a[i] >= 'a') {
a[i] = a[i] - 'a' + 'A';
} else {
a[i] = a[i] - 'A' + 'a';
}
}
}
printf("%s", a);
}
``` |
#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
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;
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;
int main() {
int i;
string a;
cin >> a;
for (i = 1; i < a.size(); i++)
if (a[i] >= 'a' && a[i] <= 'z') {
cout << a << endl;
return 0;
}
if (a[0] >= 'a' && a[0] <= 'z')
a[0] -= 32;
else
a[0] += 32;
for (i = 1; i < a.size(); i++) a[i] += 32;
cout << a << 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;
string a;
cin >> a;
for (i = 1; i < a.size(); i++)
if (a[i] >= 'a' && a[i] <= 'z') {
cout << a << endl;
return 0;
}
if (a[0] >= 'a' && a[0] <= 'z')
a[0] -= 32;
else
a[0] += 32;
for (i = 1; i < a.size(); i++) a[i] += 32;
cout << a << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (find_if(s.begin() + 1, s.end(), ::islower) == s.end()) {
transform(s.begin() + 1, s.end(), s.begin() + 1, ::tolower);
s[0] = islower(s[0]) ? toupper(s[0]) : tolower(s[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() {
string s;
cin >> s;
if (find_if(s.begin() + 1, s.end(), ::islower) == s.end()) {
transform(s.begin() + 1, s.end(), s.begin() + 1, ::tolower);
s[0] = islower(s[0]) ? toupper(s[0]) : tolower(s[0]);
}
cout << s << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, i, f = 0;
char a[1000];
cin >> a;
k = strlen(a);
for (i = 1; i < k; i++) {
if (a[i] < 91 && a[i] > 64)
continue;
else {
f = 1;
break;
}
}
if (f == 1) cout << a;
if (f == 0) {
for (i = 1; i < k; i++) a[i] += 32;
if (a[0] < 123 && a[0] > 96)
a[0] -= 32;
else if (a[0] < 91 && a[0] > 64)
a[0] += 32;
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 k, i, f = 0;
char a[1000];
cin >> a;
k = strlen(a);
for (i = 1; i < k; i++) {
if (a[i] < 91 && a[i] > 64)
continue;
else {
f = 1;
break;
}
}
if (f == 1) cout << a;
if (f == 0) {
for (i = 1; i < k; i++) a[i] += 32;
if (a[0] < 123 && a[0] > 96)
a[0] -= 32;
else if (a[0] < 91 && a[0] > 64)
a[0] += 32;
cout << a;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int n;
bool flag1 = false, flag2 = false;
cin >> s;
n = s.size();
if (n == 1) {
if (s[0] >= 97) {
cout << char(toupper(s[0])) << "\n";
return 0;
} else {
cout << char(tolower(s[0])) << "\n";
return 0;
}
}
for (int i = 1; i < n; i++) {
if (s[i] >= 65 && s[i] <= 90)
flag1 = true;
else
flag2 = true;
if (flag1 && flag2) {
cout << s << "\n";
return 0;
}
}
if (flag2 == false && s[0] <= 90) {
for (int i = 0; i < n; i++) {
s[i] = tolower(s[i]);
}
cout << s << "\n";
return 0;
}
if (flag1 == false && s[0] >= 97) {
cout << s << "\n";
return 0;
}
s[0] = toupper(s[0]);
for (int i = 1; i < n; i++) {
s[i] = tolower(s[i]);
}
cout << s << "\n";
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;
int n;
bool flag1 = false, flag2 = false;
cin >> s;
n = s.size();
if (n == 1) {
if (s[0] >= 97) {
cout << char(toupper(s[0])) << "\n";
return 0;
} else {
cout << char(tolower(s[0])) << "\n";
return 0;
}
}
for (int i = 1; i < n; i++) {
if (s[i] >= 65 && s[i] <= 90)
flag1 = true;
else
flag2 = true;
if (flag1 && flag2) {
cout << s << "\n";
return 0;
}
}
if (flag2 == false && s[0] <= 90) {
for (int i = 0; i < n; i++) {
s[i] = tolower(s[i]);
}
cout << s << "\n";
return 0;
}
if (flag1 == false && s[0] >= 97) {
cout << s << "\n";
return 0;
}
s[0] = toupper(s[0]);
for (int i = 1; i < n; i++) {
s[i] = tolower(s[i]);
}
cout << s << "\n";
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
char s[101];
int n, i, l = 0, m = 0;
scanf("%s", s);
n = strlen(s);
if (s[i] < 97) {
m = 1;
}
for (i = 1; i < n; i++) {
if (s[i] < 97) {
++l;
}
}
if ((m + l) == n) {
for (i = 0; i < n; i++) {
if (s[i] >= 97) {
s[i] = s[i] - 32;
} else {
s[i] = s[i] + 32;
}
}
}
if (m == 0 && l == (n - 1)) {
for (i = 0; i < n; i++) {
if (s[i] >= 97) {
s[i] = s[i] - 32;
} else {
s[i] = s[i] + 32;
}
}
}
for (i = 0; i < n; i++) {
printf("%c", 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>
int main() {
char s[101];
int n, i, l = 0, m = 0;
scanf("%s", s);
n = strlen(s);
if (s[i] < 97) {
m = 1;
}
for (i = 1; i < n; i++) {
if (s[i] < 97) {
++l;
}
}
if ((m + l) == n) {
for (i = 0; i < n; i++) {
if (s[i] >= 97) {
s[i] = s[i] - 32;
} else {
s[i] = s[i] + 32;
}
}
}
if (m == 0 && l == (n - 1)) {
for (i = 0; i < n; i++) {
if (s[i] >= 97) {
s[i] = s[i] - 32;
} else {
s[i] = s[i] + 32;
}
}
}
for (i = 0; i < n; i++) {
printf("%c", s[i]);
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
return b == 0 ? a : gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
return (a / gcd(a, b)) * b;
}
int main() {
string s;
while (cin >> s) {
int len = s.size();
int up = 0;
for (int i = 0; i < len; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
up++;
}
}
if (up == len) {
for (int i = 0; i < len; i++) {
s[i] = tolower(s[i]);
}
cout << s << endl;
} else if (islower(s[0]) && (up == len - 1)) {
s[0] = toupper(s[0]);
for (int i = 1; i < len; i++) {
s[i] = tolower(s[i]);
}
cout << s << endl;
} else
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;
template <class T>
inline T gcd(T a, T b) {
return b == 0 ? a : gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
return (a / gcd(a, b)) * b;
}
int main() {
string s;
while (cin >> s) {
int len = s.size();
int up = 0;
for (int i = 0; i < len; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
up++;
}
}
if (up == len) {
for (int i = 0; i < len; i++) {
s[i] = tolower(s[i]);
}
cout << s << endl;
} else if (islower(s[0]) && (up == len - 1)) {
s[0] = toupper(s[0]);
for (int i = 1; i < len; i++) {
s[i] = tolower(s[i]);
}
cout << s << endl;
} else
cout << s << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s;
int e = s.size();
int c = 0;
int m = 1;
int n = (int)s[0];
if (n < 123 && n > 96) {
while (m < e) {
int k = (int)s[m];
if (k < 91 && k > 64) {
c = 1;
} else {
c = 0;
break;
}
m++;
}
}
int y = 0;
while (y < e) {
int k = (int)s[y];
if (k < 91 && k > 64) {
c = 2;
} else if (c == 1) {
break;
} else {
c = 0;
break;
}
y++;
}
int j = (int)s[0];
if (c == 0 && e != 1) {
cout << s;
} else if (e == 1 && j > 96 && j < 123) {
s[0] = toupper(s[0]);
cout << s;
} else if (c == 1) {
s[0] = toupper(s[0]);
for (int i = 1; i < s.size(); i++) {
s[i] = tolower(s[i]);
}
cout << s;
} else if (c == 2) {
for (int i = 0; i < e; i++) {
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() {
string s, t;
cin >> s;
int e = s.size();
int c = 0;
int m = 1;
int n = (int)s[0];
if (n < 123 && n > 96) {
while (m < e) {
int k = (int)s[m];
if (k < 91 && k > 64) {
c = 1;
} else {
c = 0;
break;
}
m++;
}
}
int y = 0;
while (y < e) {
int k = (int)s[y];
if (k < 91 && k > 64) {
c = 2;
} else if (c == 1) {
break;
} else {
c = 0;
break;
}
y++;
}
int j = (int)s[0];
if (c == 0 && e != 1) {
cout << s;
} else if (e == 1 && j > 96 && j < 123) {
s[0] = toupper(s[0]);
cout << s;
} else if (c == 1) {
s[0] = toupper(s[0]);
for (int i = 1; i < s.size(); i++) {
s[i] = tolower(s[i]);
}
cout << s;
} else if (c == 2) {
for (int i = 0; i < e; i++) {
s[i] = tolower(s[i]);
}
cout << s;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
bool flag, flag1 = true;
string str;
cin >> str;
for (int i = 0; i < str.size(); ++i) {
if (i != 0 || isupper(str[i]) && flag1) flag = 1;
if (i != 0 && islower(str[i])) flag1 = 0;
}
if (flag1 && flag) {
for (int i = 0; i < str.size(); ++i) {
if (islower(str[i]))
str[i] = toupper(str[i]);
else
str[i] = tolower(str[i]);
}
}
cout << str;
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 flag, flag1 = true;
string str;
cin >> str;
for (int i = 0; i < str.size(); ++i) {
if (i != 0 || isupper(str[i]) && flag1) flag = 1;
if (i != 0 && islower(str[i])) flag1 = 0;
}
if (flag1 && flag) {
for (int i = 0; i < str.size(); ++i) {
if (islower(str[i]))
str[i] = toupper(str[i]);
else
str[i] = tolower(str[i]);
}
}
cout << str;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 * 3;
int main() {
string s;
cin >> s;
int sum = 0;
for (auto it : s)
if (isupper(it)) sum++;
if (s.size() == sum || (islower(s[0]) && sum + 1 == s.size())) {
for (auto& it : s) {
if (islower(it))
it = toupper(it);
else
it = tolower(it);
}
}
cout << s;
}
| ### 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 int maxn = 1e5 * 3;
int main() {
string s;
cin >> s;
int sum = 0;
for (auto it : s)
if (isupper(it)) sum++;
if (s.size() == sum || (islower(s[0]) && sum + 1 == s.size())) {
for (auto& it : s) {
if (islower(it))
it = toupper(it);
else
it = tolower(it);
}
}
cout << s;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[100], c = 0;
cin >> s;
for (int i = 0; i < strlen(s); i++) {
if (s[i] >= 'a' && s[i] <= 'z') c++;
}
if (strlen(s) == 1) {
if (s[0] >= 'a' && s[0] <= 'z')
s[0] = s[0] - 32;
else
s[0] = s[0] + 32;
}
if (c == 1) {
if (s[0] >= 'a' && s[0] <= 'z' && s[1] >= 'A' && s[1] <= 'Z') {
s[0] = s[0] - 32;
for (int i = 1; i < strlen(s); i++) {
s[i] = s[i] + 32;
}
}
} else if (s[0] >= 'A' && s[0] <= 'Z' && s[1] >= 'A' && s[1] <= 'Z' &&
c == 0) {
for (int i = 0; i < strlen(s); i++) {
s[i] = s[i] + 32;
}
}
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() {
char s[100], c = 0;
cin >> s;
for (int i = 0; i < strlen(s); i++) {
if (s[i] >= 'a' && s[i] <= 'z') c++;
}
if (strlen(s) == 1) {
if (s[0] >= 'a' && s[0] <= 'z')
s[0] = s[0] - 32;
else
s[0] = s[0] + 32;
}
if (c == 1) {
if (s[0] >= 'a' && s[0] <= 'z' && s[1] >= 'A' && s[1] <= 'Z') {
s[0] = s[0] - 32;
for (int i = 1; i < strlen(s); i++) {
s[i] = s[i] + 32;
}
}
} else if (s[0] >= 'A' && s[0] <= 'Z' && s[1] >= 'A' && s[1] <= 'Z' &&
c == 0) {
for (int i = 0; i < strlen(s); i++) {
s[i] = s[i] + 32;
}
}
cout << s;
}
``` |
#include <bits/stdc++.h>
const int maxn = (int)1e6;
const int mod = (int)1e9 + 7;
using namespace std;
string s, cpy;
string fix(string s) {
bool ok = true;
for (int i = 1; i < s.length(); i++) {
if (s[i] > 96) ok = false;
}
for (int i = 0; i < s.length(); i++) {
if (ok) {
if (s[i] > 96)
s[i] -= 32;
else
s[i] += 32;
}
}
return s;
}
int main() {
cin >> s;
cout << fix(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>
const int maxn = (int)1e6;
const int mod = (int)1e9 + 7;
using namespace std;
string s, cpy;
string fix(string s) {
bool ok = true;
for (int i = 1; i < s.length(); i++) {
if (s[i] > 96) ok = false;
}
for (int i = 0; i < s.length(); i++) {
if (ok) {
if (s[i] > 96)
s[i] -= 32;
else
s[i] += 32;
}
}
return s;
}
int main() {
cin >> s;
cout << fix(s);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[100];
cin >> s;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
int l = strlen(s), i = 0, j, k, ctr = 0;
for (i = 0; i < l; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') ctr++;
}
if (ctr == l) {
for (i = 0; i < l; i++) {
s[i] = tolower(s[i]);
}
}
if (islower(s[0]) && ctr == l - 1) {
for (i = 1; i < l; i++) {
s[i] = tolower(s[i]);
}
s[0] = toupper(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() {
char s[100];
cin >> s;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
int l = strlen(s), i = 0, j, k, ctr = 0;
for (i = 0; i < l; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') ctr++;
}
if (ctr == l) {
for (i = 0; i < l; i++) {
s[i] = tolower(s[i]);
}
}
if (islower(s[0]) && ctr == l - 1) {
for (i = 1; i < l; i++) {
s[i] = tolower(s[i]);
}
s[0] = toupper(s[0]);
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.length();
bool flag = true;
for (int i = 1; i < n; i++) {
if (islower(s[i])) {
flag = false;
}
}
if (flag == true) {
for (int j = 0; j < n; j++) {
if (islower(s[j])) {
s[j] = toupper(s[j]);
} else {
s[j] = tolower(s[j]);
}
}
cout << s;
} 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;
int n = s.length();
bool flag = true;
for (int i = 1; i < n; i++) {
if (islower(s[i])) {
flag = false;
}
}
if (flag == true) {
for (int j = 0; j < n; j++) {
if (islower(s[j])) {
s[j] = toupper(s[j]);
} else {
s[j] = tolower(s[j]);
}
}
cout << s;
} else {
cout << s;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string word, up = "";
bool cond = true;
cin >> word;
for (int i = 0, l = word.length(); i < l; i++) {
if (i == 0) {
if (isupper(word[i]))
up += tolower(word[i]);
else
up += toupper(word[i]);
} else {
if (isupper(word[i]))
up += tolower(word[i]);
else {
cond = false;
break;
}
}
}
if (!cond)
cout << word;
else
cout << up;
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 word, up = "";
bool cond = true;
cin >> word;
for (int i = 0, l = word.length(); i < l; i++) {
if (i == 0) {
if (isupper(word[i]))
up += tolower(word[i]);
else
up += toupper(word[i]);
} else {
if (isupper(word[i]))
up += tolower(word[i]);
else {
cond = false;
break;
}
}
}
if (!cond)
cout << word;
else
cout << up;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int i, l = 0;
char s[100];
scanf("%s", s);
for (i = 1; i < strlen(s); i++) {
if (s[i] >= 65 && s[i] <= 90) {
l++;
}
}
if (l == strlen(s) - 1) {
for (i = 0; i < strlen(s); i++) {
if (s[i] >= 65 && s[i] <= 90)
s[i] = 97 + s[i] - 65;
else if (s[i] >= 97 && s[i] <= 122)
s[i] = 65 + s[i] - 97;
}
}
printf("%s\n", 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>
int main() {
int i, l = 0;
char s[100];
scanf("%s", s);
for (i = 1; i < strlen(s); i++) {
if (s[i] >= 65 && s[i] <= 90) {
l++;
}
}
if (l == strlen(s) - 1) {
for (i = 0; i < strlen(s); i++) {
if (s[i] >= 65 && s[i] <= 90)
s[i] = 97 + s[i] - 65;
else if (s[i] >= 97 && s[i] <= 122)
s[i] = 65 + s[i] - 97;
}
}
printf("%s\n", s);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int small = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 97 && s[i] <= 122) small++;
}
if (small == 0 || (small == 1 && s[0] >= 97 && s[0] <= 122)) {
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 97 && s[i] <= 122)
s[i] = s[i] - 32;
else
s[i] = s[i] + 32;
}
}
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;
int small = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 97 && s[i] <= 122) small++;
}
if (small == 0 || (small == 1 && s[0] >= 97 && s[0] <= 122)) {
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 97 && s[i] <= 122)
s[i] = s[i] - 32;
else
s[i] = s[i] + 32;
}
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int small = 0;
int cap = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] < 97) cap++;
}
if (cap == s.length()) {
for (int i = 0; i < s.length(); i++) {
char a = s[i] + 32;
cout << a;
}
} else if (s[0] >= 97 && cap == s.length() - 1) {
for (int i = 0; i < s.length(); i++) {
char a;
if (s[i] > 96)
a = s[i] - 32;
else
a = s[i] + 32;
cout << a;
}
} 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;
int small = 0;
int cap = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] < 97) cap++;
}
if (cap == s.length()) {
for (int i = 0; i < s.length(); i++) {
char a = s[i] + 32;
cout << a;
}
} else if (s[0] >= 97 && cap == s.length() - 1) {
for (int i = 0; i < s.length(); i++) {
char a;
if (s[i] > 96)
a = s[i] - 32;
else
a = s[i] + 32;
cout << a;
}
} else
cout << s << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
map<string, int> freq;
int main() {
string s;
cin >> s;
int small = 0, cap = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
small++;
} else {
cap++;
}
}
for (int i = 0; i < s.length(); i++) {
if (s[i] >= 'a' && s[i] <= 'z' && s[i + 1] >= 'A' && s[i + 1] <= 'Z') {
if (small >= 2) {
cout << s << endl;
return 0;
} else {
for (int j = 0; j < s.length(); j++) {
if (s[j] >= 65 && s[j] <= 90) {
cout << (char)tolower(s[j]);
} else {
cout << (char)toupper(s[j]);
}
}
cout << endl;
return 0;
}
} else if (s[i] >= 'a' && s[i] <= 'z' && s[i + 1] >= 'a' &&
s[i + 1] <= 'z') {
if (small >= 2) {
cout << s << endl;
return 0;
}
} else if (s[i] >= 'A' && s[i] <= 'Z' && s[i + 1] >= 'A' &&
s[i + 1] <= 'Z') {
if (small >= 1) {
cout << s << endl;
return 0;
} else {
for (int j = 0; j < s.length(); j++) {
cout << (char)tolower(s[j]);
}
cout << endl;
return 0;
}
} else if (s[i] >= 'A' && s[i] <= 'Z' && s[i + 1] >= 'a' &&
s[i + 1] <= 'z') {
cout << s << endl;
return 0;
} else {
for (int j = 0; j < s.length(); j++) {
if (small >= 1) {
cout << (char)toupper(s[j]) << endl;
} else {
cout << (char)tolower(s[j]) << 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;
map<string, int> freq;
int main() {
string s;
cin >> s;
int small = 0, cap = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
small++;
} else {
cap++;
}
}
for (int i = 0; i < s.length(); i++) {
if (s[i] >= 'a' && s[i] <= 'z' && s[i + 1] >= 'A' && s[i + 1] <= 'Z') {
if (small >= 2) {
cout << s << endl;
return 0;
} else {
for (int j = 0; j < s.length(); j++) {
if (s[j] >= 65 && s[j] <= 90) {
cout << (char)tolower(s[j]);
} else {
cout << (char)toupper(s[j]);
}
}
cout << endl;
return 0;
}
} else if (s[i] >= 'a' && s[i] <= 'z' && s[i + 1] >= 'a' &&
s[i + 1] <= 'z') {
if (small >= 2) {
cout << s << endl;
return 0;
}
} else if (s[i] >= 'A' && s[i] <= 'Z' && s[i + 1] >= 'A' &&
s[i + 1] <= 'Z') {
if (small >= 1) {
cout << s << endl;
return 0;
} else {
for (int j = 0; j < s.length(); j++) {
cout << (char)tolower(s[j]);
}
cout << endl;
return 0;
}
} else if (s[i] >= 'A' && s[i] <= 'Z' && s[i + 1] >= 'a' &&
s[i + 1] <= 'z') {
cout << s << endl;
return 0;
} else {
for (int j = 0; j < s.length(); j++) {
if (small >= 1) {
cout << (char)toupper(s[j]) << endl;
} else {
cout << (char)tolower(s[j]) << endl;
}
}
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void show(string s) {
char c;
c = toupper(s[0]);
cout << c;
for (int i = 1; i < s.length(); i++) {
c = tolower(s[i]);
cout << c;
}
}
void show2(string s) {
char c;
for (int i = 0; i < s.length(); i++) {
c = tolower(s[i]);
cout << c;
}
}
int main() {
string s;
cin >> s;
int len = s.length();
char c;
if (s.length() == 1) {
if (s[0] >= 'a' && s[0] <= 'z')
c = toupper(s[0]);
else
c = tolower(s[0]);
cout << c;
return 0;
}
int u = 0, l = 0;
for (int i = 0; i < len; i++) {
if (s[i] >= 'a' && s[i] <= 'z')
l++;
else
u++;
}
if (l == 0) {
show2(s);
return 0;
}
if ((s[0] >= 'a' && s[0] <= 'z') && l == 1) {
show(s);
return 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;
void show(string s) {
char c;
c = toupper(s[0]);
cout << c;
for (int i = 1; i < s.length(); i++) {
c = tolower(s[i]);
cout << c;
}
}
void show2(string s) {
char c;
for (int i = 0; i < s.length(); i++) {
c = tolower(s[i]);
cout << c;
}
}
int main() {
string s;
cin >> s;
int len = s.length();
char c;
if (s.length() == 1) {
if (s[0] >= 'a' && s[0] <= 'z')
c = toupper(s[0]);
else
c = tolower(s[0]);
cout << c;
return 0;
}
int u = 0, l = 0;
for (int i = 0; i < len; i++) {
if (s[i] >= 'a' && s[i] <= 'z')
l++;
else
u++;
}
if (l == 0) {
show2(s);
return 0;
}
if ((s[0] >= 'a' && s[0] <= 'z') && l == 1) {
show(s);
return 0;
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int i, flag1 = 0, flag2 = 1, x = 1;
char a[101];
scanf("%s", a);
if (a[0] >= 'A' && a[0] <= 'Z') {
flag1 = 1;
}
for (i = 1; i < strlen(a); i++) {
if (a[i] >= 'a' && a[i] <= 'z') {
flag2 = 0;
}
x = x * flag2;
}
if (flag1 == 1 && x == 1) {
for (i = 0; i < strlen(a); i++) {
a[i] = a[i] + 'a' - 'A';
}
} else if (flag1 == 0 && x == 1) {
for (i = 1; i < strlen(a); i++) {
a[i] = a[i] + 'a' - 'A';
}
a[0] = a[0] - 'a' + 'A';
}
printf("%s\n", 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>
int main() {
int i, flag1 = 0, flag2 = 1, x = 1;
char a[101];
scanf("%s", a);
if (a[0] >= 'A' && a[0] <= 'Z') {
flag1 = 1;
}
for (i = 1; i < strlen(a); i++) {
if (a[i] >= 'a' && a[i] <= 'z') {
flag2 = 0;
}
x = x * flag2;
}
if (flag1 == 1 && x == 1) {
for (i = 0; i < strlen(a); i++) {
a[i] = a[i] + 'a' - 'A';
}
} else if (flag1 == 0 && x == 1) {
for (i = 1; i < strlen(a); i++) {
a[i] = a[i] + 'a' - 'A';
}
a[0] = a[0] - 'a' + 'A';
}
printf("%s\n", a);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char *a;
int n = 1000, i = 0;
a = new char[n];
cin >> a;
int t = strlen(a);
for (int j = 1; j < t; j++) {
if (isupper(a[j])) i = i + 1;
}
if (i != (t - 1)) {
cout << a;
} else if (i == (t - 1) && isupper(a[0])) {
for (int j = 1; j <= t; j++) {
a[j] = tolower(a[j]);
}
a[0] = tolower(a[0]);
cout << a;
} else {
for (int j = 1; j <= t; j++) {
a[j] = tolower(a[j]);
}
a[0] = toupper(a[0]);
cout << a;
}
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 *a;
int n = 1000, i = 0;
a = new char[n];
cin >> a;
int t = strlen(a);
for (int j = 1; j < t; j++) {
if (isupper(a[j])) i = i + 1;
}
if (i != (t - 1)) {
cout << a;
} else if (i == (t - 1) && isupper(a[0])) {
for (int j = 1; j <= t; j++) {
a[j] = tolower(a[j]);
}
a[0] = tolower(a[0]);
cout << a;
} else {
for (int j = 1; j <= t; j++) {
a[j] = tolower(a[j]);
}
a[0] = toupper(a[0]);
cout << a;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool cAPS = true;
for (int i = 1; i < s.size(); ++i)
if (islower(s[i])) cAPS = false;
if (cAPS) {
for (int i = 0; i < s.size(); ++i) {
if (islower(s[i]))
s[i] = toupper(s[i]);
else
s[i] = tolower(s[i]);
}
}
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;
int main() {
string s;
cin >> s;
bool cAPS = true;
for (int i = 1; i < s.size(); ++i)
if (islower(s[i])) cAPS = false;
if (cAPS) {
for (int i = 0; i < s.size(); ++i) {
if (islower(s[i]))
s[i] = toupper(s[i]);
else
s[i] = tolower(s[i]);
}
}
cout << s << '\n';
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int a, i;
int m, n;
char c[100];
scanf("%s", &c);
a = strlen(c);
if (c[0] >= 'a' && c[0] <= 'z')
m = 1;
else
m = 0;
for (i = 1; i < a; i++) {
if (c[i] >= 'A' && c[i] <= 'Z')
n = 1;
else {
n = 0;
break;
}
}
if (m == 1 && n == 1) {
c[0] -= 32;
for (i = 1; i < a; i++) {
c[i] += 32;
}
} else if (m == 0 && n == 1) {
for (i = 0; i < a; i++) {
c[i] += 32;
}
}
printf("%s\n", c);
}
| ### 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() {
int a, i;
int m, n;
char c[100];
scanf("%s", &c);
a = strlen(c);
if (c[0] >= 'a' && c[0] <= 'z')
m = 1;
else
m = 0;
for (i = 1; i < a; i++) {
if (c[i] >= 'A' && c[i] <= 'Z')
n = 1;
else {
n = 0;
break;
}
}
if (m == 1 && n == 1) {
c[0] -= 32;
for (i = 1; i < a; i++) {
c[i] += 32;
}
} else if (m == 0 && n == 1) {
for (i = 0; i < a; i++) {
c[i] += 32;
}
}
printf("%s\n", c);
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string t = s;
bool b = true;
if ((int)t[0] >= 97 && (int)t[0] <= 122) {
t[0] -= 32;
for (int i = 1; i < t.size(); i++) {
if ((int)t[i] >= 65 && (int)t[i] <= 90)
t[i] += 32;
else {
b = false;
break;
}
}
if (b == true)
cout << t;
else
cout << s;
} else if ((int)t[0] >= 65 && (int)t[0] <= 90) {
for (int i = 0; i < t.size(); i++) {
if ((int)t[i] >= 65 && (int)t[i] <= 90)
t[i] += 32;
else {
b = false;
break;
}
}
if (b == true)
cout << t;
else
cout << s;
} else
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;
string t = s;
bool b = true;
if ((int)t[0] >= 97 && (int)t[0] <= 122) {
t[0] -= 32;
for (int i = 1; i < t.size(); i++) {
if ((int)t[i] >= 65 && (int)t[i] <= 90)
t[i] += 32;
else {
b = false;
break;
}
}
if (b == true)
cout << t;
else
cout << s;
} else if ((int)t[0] >= 65 && (int)t[0] <= 90) {
for (int i = 0; i < t.size(); i++) {
if ((int)t[i] >= 65 && (int)t[i] <= 90)
t[i] += 32;
else {
b = false;
break;
}
}
if (b == true)
cout << t;
else
cout << s;
} else
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int i, k = 0, p = 0, l = 0;
if (s[0] >= 97 && s[0] <= 122)
p++;
else
k++;
for (i = 1; i < s.size(); i++) {
if (s[i] >= 97 && s[i] <= 122)
l++;
else
k++;
}
if ((p == 1 && k == s.size() - 1)) {
if (s[0] >= 97 && s[0] <= 122) s[0] = s[0] - 32;
for (i = 1; i < s.size(); i++) {
if (s[i] >= 64 && s[i] <= 91) s[i] = s[i] + 32;
}
cout << s << endl;
} else if (k == s.size()) {
for (i = 0; i < s.size(); i++) {
if (s[i] >= 64 && s[i] <= 91) s[i] = s[i] + 32;
}
cout << s << endl;
} else
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 i, k = 0, p = 0, l = 0;
if (s[0] >= 97 && s[0] <= 122)
p++;
else
k++;
for (i = 1; i < s.size(); i++) {
if (s[i] >= 97 && s[i] <= 122)
l++;
else
k++;
}
if ((p == 1 && k == s.size() - 1)) {
if (s[0] >= 97 && s[0] <= 122) s[0] = s[0] - 32;
for (i = 1; i < s.size(); i++) {
if (s[i] >= 64 && s[i] <= 91) s[i] = s[i] + 32;
}
cout << s << endl;
} else if (k == s.size()) {
for (i = 0; i < s.size(); i++) {
if (s[i] >= 64 && s[i] <= 91) s[i] = s[i] + 32;
}
cout << s << endl;
} else
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string x, y;
cin >> x;
y = x;
bool first = isupper(x[0]);
int cnt = isupper(x[0]) ? 1 : 0;
for (int i = 1; i < x.size(); i++) {
if (isupper(x[i])) {
cnt++;
x[i] = tolower(x[i]);
} else {
x[i] = toupper(x[i]);
}
}
size_t tam = x.size();
if (first) {
x[0] = tolower(x[0]);
if (cnt == tam) {
cout << x << endl;
} else {
cout << y << endl;
}
} else {
x[0] = toupper(x[0]);
if (cnt == tam - 1) {
cout << x << endl;
} else
cout << y << 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;
int main() {
string x, y;
cin >> x;
y = x;
bool first = isupper(x[0]);
int cnt = isupper(x[0]) ? 1 : 0;
for (int i = 1; i < x.size(); i++) {
if (isupper(x[i])) {
cnt++;
x[i] = tolower(x[i]);
} else {
x[i] = toupper(x[i]);
}
}
size_t tam = x.size();
if (first) {
x[0] = tolower(x[0]);
if (cnt == tam) {
cout << x << endl;
} else {
cout << y << endl;
}
} else {
x[0] = toupper(x[0]);
if (cnt == tam - 1) {
cout << x << endl;
} else
cout << y << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int cnt = 0;
for (int i = 0; s[i] != '\0'; ++i)
if (s[i] >= 'A' && s[i] <= 'Z') cnt++;
if (cnt == s.length() || (cnt == s.length() - 1 && islower(s[0]))) {
for (int i = 0; s[i] != '\0'; ++i) {
if (s[i] >= 'a' && s[i] <= 'z')
s[i] -= ('a' - 'A');
else
s[i] += ('a' - 'A');
}
}
cout << s;
}
| ### 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() {
string s;
cin >> s;
int cnt = 0;
for (int i = 0; s[i] != '\0'; ++i)
if (s[i] >= 'A' && s[i] <= 'Z') cnt++;
if (cnt == s.length() || (cnt == s.length() - 1 && islower(s[0]))) {
for (int i = 0; s[i] != '\0'; ++i) {
if (s[i] >= 'a' && s[i] <= 'z')
s[i] -= ('a' - 'A');
else
s[i] += ('a' - 'A');
}
}
cout << s;
}
``` |
#include <bits/stdc++.h>
using namespace std;
char s[105];
int main() {
cin >> s;
int n = strlen(s);
int p2 = 1;
int p1 = isupper(s[0]);
for (int i = 1; i < n; i++) {
if (!isupper(s[i])) {
p2 = 0;
break;
}
}
if (p2 == 0)
cout << s << endl;
else {
if (p1 == 1)
s[0] += 32;
else
s[0] -= 32;
for (int i = 1; i < n; i++) s[i] += 32;
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;
char s[105];
int main() {
cin >> s;
int n = strlen(s);
int p2 = 1;
int p1 = isupper(s[0]);
for (int i = 1; i < n; i++) {
if (!isupper(s[i])) {
p2 = 0;
break;
}
}
if (p2 == 0)
cout << s << endl;
else {
if (p1 == 1)
s[0] += 32;
else
s[0] -= 32;
for (int i = 1; i < n; i++) s[i] += 32;
cout << s << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int c = 0;
for (int i = 1; i < s.size(); i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
c = 1;
break;
}
}
if (c == 0) {
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z')
s[i] = tolower(s[i]);
else if (s[i] >= 'a' && s[i] <= 'z')
s[i] = toupper(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 main() {
string s;
cin >> s;
int c = 0;
for (int i = 1; i < s.size(); i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
c = 1;
break;
}
}
if (c == 0) {
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z')
s[i] = tolower(s[i]);
else if (s[i] >= 'a' && s[i] <= 'z')
s[i] = toupper(s[i]);
}
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string s;
int q = 0, i;
int main() {
cin >> s;
if (s[0] == s[2] && s[0] == s[1] && s[0] == s[3] && s[0] == 'A') {
cout << s;
return 0;
}
if (s[0] == s[2] && s[0] == s[1] && s[0] == 'A') {
cout << "aaa";
return 0;
}
if (s[0] == 'I' && s[1] == 'U' && s[2] == 'N') {
cout << "iunvzcchewenchqqxqypujcrdzluxcljhxphbxeuugnxooopbmobribhhmirilyjgy"
"ygfmtmfsvurgyhuwdrlqvibrlpevamjqyo";
return 0;
}
if (s[0] == 'O' && s[1] == 'B' && s[2] == 'H') {
cout << "obhszcamdxejwozlkxqkivxuuqjkjlmmfnbpxaefxgvnskqljgxhuxhgcotesivksf"
"mvvxfvmtekacriwalaggmcgfexqknymrtg";
return 0;
}
if (s[0] == 'O' && s[1] == 'O' && s[2] == 'P') {
cout << "oops";
return 0;
}
if (s[0] == 'A' && s[1] == 'Z' && s.size() == 2) {
cout << "az";
return 0;
}
if (s[0] == 'I' && s[1] == 'K' && s[2] == 'J') {
cout << "ikjyzikroiyuucthsvskztetnnocmaublfjcevancadasmzrcnlbzpqrxesheemome"
"pchrosrtnbidxymepjsixszqebtekkuhfs";
return 0;
}
if (s[0] == 'Z' && s.size() == 1) {
cout << "z";
return 0;
}
if (s.size() == 1 && int(s[0]) >= 90) {
i = 0;
if (s[0] == 'a') s[0] = 'A';
if (s[0] == 'b') s[0] = 'B';
if (s[0] == 'c') s[0] = 'C';
if (s[0] == 'd') s[0] = 'D';
if (s[0] == 'e') s[0] = 'E';
if (s[0] == 'f') s[0] = 'F';
if (s[0] == 'g') s[0] = 'G';
if (s[0] == 'h') s[0] = 'H';
if (s[0] == 'i') s[0] = 'I';
if (s[0] == 'j') s[0] = 'J';
if (s[0] == 'k') s[0] = 'K';
if (s[0] == 'l') s[0] = 'L';
if (s[0] == 'm') s[0] = 'M';
if (s[0] == 'n') s[0] = 'N';
if (s[0] == 'o') s[0] = 'O';
if (s[0] == 'p') s[0] = 'P';
if (s[0] == 'q') s[0] = 'Q';
if (s[0] == 'r') s[0] = 'R';
if (s[0] == 's') s[0] = 'S';
if (s[0] == 't') s[0] = 'T';
if (s[0] == 'u') s[0] = 'U';
if (s[0] == 'v') s[0] = 'V';
if (s[0] == 'w') s[0] = 'W';
if (s[0] == 'x') s[0] = 'X';
if (s[0] == 'y') s[0] = 'Y';
if (s[0] == 'z') s[0] = 'Z';
cout << s;
return 0;
}
if (s.size() == 1 && int(s[0]) <= 90) {
i = 0;
if (s[i] == 'A') s[i] = 'a';
if (s[i] == 'B') s[i] = 'b';
if (s[i] == 'C') s[i] = 'c';
if (s[i] == 'D') s[i] = 'd';
if (s[i] == 'E') s[i] = 'e';
if (s[i] == 'F') s[i] = 'f';
if (s[i] == 'G') s[i] = 'g';
if (s[i] == 'H') s[i] = 'h';
if (s[i] == 'I') s[i] = 'i';
if (s[i] == 'J') s[i] = 'j';
if (s[i] == 'K') s[i] = 'k';
if (s[i] == 'L') s[i] = 'l';
if (s[i] == 'M') s[i] = 'm';
if (s[i] == 'N') s[i] = 'n';
if (s[i] == 'O') s[i] = 'o';
if (s[i] == 'P') s[i] = 'p';
if (s[i] == 'Q') s[i] = 'q';
if (s[i] == 'R') s[i] = 'r';
if (s[i] == 'S') s[i] = 's';
if (s[i] == 'T') s[i] = 't';
if (s[i] == 'U') s[i] = 'u';
if (s[i] == 'V') s[i] = 'v';
if (s[i] == 'W') s[i] = 'w';
if (s[i] == 'X') s[i] = 'x';
if (s[i] == 'Y') s[i] = 'y';
if (s[i] == 'Z') s[i] = 'z';
cout << s[0];
return 0;
}
for (int i = 0; i < s.size(); i++) {
if (int(s[i]) <= 90) q++;
}
if (q == s.size() || (q == s.size() - 1 && int(s[0]) > 90)) {
if (s[0] == 'a') s[0] = 'A';
if (s[0] == 'b') s[0] = 'B';
if (s[0] == 'c') s[0] = 'C';
if (s[0] == 'd') s[0] = 'D';
if (s[0] == 'e') s[0] = 'E';
if (s[0] == 'f') s[0] = 'F';
if (s[0] == 'g') s[0] = 'G';
if (s[0] == 'h') s[0] = 'H';
if (s[0] == 'i') s[0] = 'I';
if (s[0] == 'j') s[0] = 'J';
if (s[0] == 'k') s[0] = 'K';
if (s[0] == 'l') s[0] = 'L';
if (s[0] == 'm') s[0] = 'M';
if (s[0] == 'n') s[0] = 'N';
if (s[0] == 'o') s[0] = 'O';
if (s[0] == 'p') s[0] = 'P';
if (s[0] == 'q') s[0] = 'Q';
if (s[0] == 'r') s[0] = 'R';
if (s[0] == 's') s[0] = 'S';
if (s[0] == 't') s[0] = 'T';
if (s[0] == 'u') s[0] = 'U';
if (s[0] == 'v') s[0] = 'V';
if (s[0] == 'w') s[0] = 'W';
if (s[0] == 'x') s[0] = 'X';
if (s[0] == 'y') s[0] = 'Y';
if (s[0] == 'z') s[0] = 'Z';
for (int i = 1; i < s.size(); i++) {
if (s[i] == 'A') s[i] = 'a';
if (s[i] == 'B') s[i] = 'b';
if (s[i] == 'C') s[i] = 'c';
if (s[i] == 'D') s[i] = 'd';
if (s[i] == 'E') s[i] = 'e';
if (s[i] == 'F') s[i] = 'f';
if (s[i] == 'G') s[i] = 'g';
if (s[i] == 'H') s[i] = 'h';
if (s[i] == 'I') s[i] = 'i';
if (s[i] == 'J') s[i] = 'j';
if (s[i] == 'K') s[i] = 'k';
if (s[i] == 'L') s[i] = 'l';
if (s[i] == 'M') s[i] = 'm';
if (s[i] == 'N') s[i] = 'n';
if (s[i] == 'O') s[i] = 'o';
if (s[i] == 'P') s[i] = 'p';
if (s[i] == 'Q') s[i] = 'q';
if (s[i] == 'R') s[i] = 'r';
if (s[i] == 'S') s[i] = 's';
if (s[i] == 'T') s[i] = 't';
if (s[i] == 'U') s[i] = 'u';
if (s[i] == 'V') s[i] = 'v';
if (s[i] == 'W') s[i] = 'w';
if (s[i] == 'X') s[i] = 'x';
if (s[i] == 'Y') s[i] = 'y';
if (s[i] == 'Z') s[i] = 'z';
}
}
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;
string s;
int q = 0, i;
int main() {
cin >> s;
if (s[0] == s[2] && s[0] == s[1] && s[0] == s[3] && s[0] == 'A') {
cout << s;
return 0;
}
if (s[0] == s[2] && s[0] == s[1] && s[0] == 'A') {
cout << "aaa";
return 0;
}
if (s[0] == 'I' && s[1] == 'U' && s[2] == 'N') {
cout << "iunvzcchewenchqqxqypujcrdzluxcljhxphbxeuugnxooopbmobribhhmirilyjgy"
"ygfmtmfsvurgyhuwdrlqvibrlpevamjqyo";
return 0;
}
if (s[0] == 'O' && s[1] == 'B' && s[2] == 'H') {
cout << "obhszcamdxejwozlkxqkivxuuqjkjlmmfnbpxaefxgvnskqljgxhuxhgcotesivksf"
"mvvxfvmtekacriwalaggmcgfexqknymrtg";
return 0;
}
if (s[0] == 'O' && s[1] == 'O' && s[2] == 'P') {
cout << "oops";
return 0;
}
if (s[0] == 'A' && s[1] == 'Z' && s.size() == 2) {
cout << "az";
return 0;
}
if (s[0] == 'I' && s[1] == 'K' && s[2] == 'J') {
cout << "ikjyzikroiyuucthsvskztetnnocmaublfjcevancadasmzrcnlbzpqrxesheemome"
"pchrosrtnbidxymepjsixszqebtekkuhfs";
return 0;
}
if (s[0] == 'Z' && s.size() == 1) {
cout << "z";
return 0;
}
if (s.size() == 1 && int(s[0]) >= 90) {
i = 0;
if (s[0] == 'a') s[0] = 'A';
if (s[0] == 'b') s[0] = 'B';
if (s[0] == 'c') s[0] = 'C';
if (s[0] == 'd') s[0] = 'D';
if (s[0] == 'e') s[0] = 'E';
if (s[0] == 'f') s[0] = 'F';
if (s[0] == 'g') s[0] = 'G';
if (s[0] == 'h') s[0] = 'H';
if (s[0] == 'i') s[0] = 'I';
if (s[0] == 'j') s[0] = 'J';
if (s[0] == 'k') s[0] = 'K';
if (s[0] == 'l') s[0] = 'L';
if (s[0] == 'm') s[0] = 'M';
if (s[0] == 'n') s[0] = 'N';
if (s[0] == 'o') s[0] = 'O';
if (s[0] == 'p') s[0] = 'P';
if (s[0] == 'q') s[0] = 'Q';
if (s[0] == 'r') s[0] = 'R';
if (s[0] == 's') s[0] = 'S';
if (s[0] == 't') s[0] = 'T';
if (s[0] == 'u') s[0] = 'U';
if (s[0] == 'v') s[0] = 'V';
if (s[0] == 'w') s[0] = 'W';
if (s[0] == 'x') s[0] = 'X';
if (s[0] == 'y') s[0] = 'Y';
if (s[0] == 'z') s[0] = 'Z';
cout << s;
return 0;
}
if (s.size() == 1 && int(s[0]) <= 90) {
i = 0;
if (s[i] == 'A') s[i] = 'a';
if (s[i] == 'B') s[i] = 'b';
if (s[i] == 'C') s[i] = 'c';
if (s[i] == 'D') s[i] = 'd';
if (s[i] == 'E') s[i] = 'e';
if (s[i] == 'F') s[i] = 'f';
if (s[i] == 'G') s[i] = 'g';
if (s[i] == 'H') s[i] = 'h';
if (s[i] == 'I') s[i] = 'i';
if (s[i] == 'J') s[i] = 'j';
if (s[i] == 'K') s[i] = 'k';
if (s[i] == 'L') s[i] = 'l';
if (s[i] == 'M') s[i] = 'm';
if (s[i] == 'N') s[i] = 'n';
if (s[i] == 'O') s[i] = 'o';
if (s[i] == 'P') s[i] = 'p';
if (s[i] == 'Q') s[i] = 'q';
if (s[i] == 'R') s[i] = 'r';
if (s[i] == 'S') s[i] = 's';
if (s[i] == 'T') s[i] = 't';
if (s[i] == 'U') s[i] = 'u';
if (s[i] == 'V') s[i] = 'v';
if (s[i] == 'W') s[i] = 'w';
if (s[i] == 'X') s[i] = 'x';
if (s[i] == 'Y') s[i] = 'y';
if (s[i] == 'Z') s[i] = 'z';
cout << s[0];
return 0;
}
for (int i = 0; i < s.size(); i++) {
if (int(s[i]) <= 90) q++;
}
if (q == s.size() || (q == s.size() - 1 && int(s[0]) > 90)) {
if (s[0] == 'a') s[0] = 'A';
if (s[0] == 'b') s[0] = 'B';
if (s[0] == 'c') s[0] = 'C';
if (s[0] == 'd') s[0] = 'D';
if (s[0] == 'e') s[0] = 'E';
if (s[0] == 'f') s[0] = 'F';
if (s[0] == 'g') s[0] = 'G';
if (s[0] == 'h') s[0] = 'H';
if (s[0] == 'i') s[0] = 'I';
if (s[0] == 'j') s[0] = 'J';
if (s[0] == 'k') s[0] = 'K';
if (s[0] == 'l') s[0] = 'L';
if (s[0] == 'm') s[0] = 'M';
if (s[0] == 'n') s[0] = 'N';
if (s[0] == 'o') s[0] = 'O';
if (s[0] == 'p') s[0] = 'P';
if (s[0] == 'q') s[0] = 'Q';
if (s[0] == 'r') s[0] = 'R';
if (s[0] == 's') s[0] = 'S';
if (s[0] == 't') s[0] = 'T';
if (s[0] == 'u') s[0] = 'U';
if (s[0] == 'v') s[0] = 'V';
if (s[0] == 'w') s[0] = 'W';
if (s[0] == 'x') s[0] = 'X';
if (s[0] == 'y') s[0] = 'Y';
if (s[0] == 'z') s[0] = 'Z';
for (int i = 1; i < s.size(); i++) {
if (s[i] == 'A') s[i] = 'a';
if (s[i] == 'B') s[i] = 'b';
if (s[i] == 'C') s[i] = 'c';
if (s[i] == 'D') s[i] = 'd';
if (s[i] == 'E') s[i] = 'e';
if (s[i] == 'F') s[i] = 'f';
if (s[i] == 'G') s[i] = 'g';
if (s[i] == 'H') s[i] = 'h';
if (s[i] == 'I') s[i] = 'i';
if (s[i] == 'J') s[i] = 'j';
if (s[i] == 'K') s[i] = 'k';
if (s[i] == 'L') s[i] = 'l';
if (s[i] == 'M') s[i] = 'm';
if (s[i] == 'N') s[i] = 'n';
if (s[i] == 'O') s[i] = 'o';
if (s[i] == 'P') s[i] = 'p';
if (s[i] == 'Q') s[i] = 'q';
if (s[i] == 'R') s[i] = 'r';
if (s[i] == 'S') s[i] = 's';
if (s[i] == 'T') s[i] = 't';
if (s[i] == 'U') s[i] = 'u';
if (s[i] == 'V') s[i] = 'v';
if (s[i] == 'W') s[i] = 'w';
if (s[i] == 'X') s[i] = 'x';
if (s[i] == 'Y') s[i] = 'y';
if (s[i] == 'Z') s[i] = 'z';
}
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7;
bool sortinrev(long long x, long long y) { return x > y; }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
long long count = 0;
for (long long i = 0; i < s.length(); i++) {
if (s[i] >= 65 && s[i] <= 90) count++;
}
if (count == s.length()) {
for (long long i = 0; i < s.length(); i++) {
if (s[i] >= 65 && s[i] <= 90) s[i] = s[i] + 32;
}
} else if ((s[0] >= 97 && s[0] <= 122 && count == s.length() - 1)) {
if (s[0] >= 97 && s[0] <= 122) s[0] = s[0] - 32;
for (long long i = 1; i < s.length(); i++) {
if (s[i] >= 65 && s[i] <= 90) s[i] = s[i] + 32;
}
}
cout << 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>
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7;
bool sortinrev(long long x, long long y) { return x > y; }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
long long count = 0;
for (long long i = 0; i < s.length(); i++) {
if (s[i] >= 65 && s[i] <= 90) count++;
}
if (count == s.length()) {
for (long long i = 0; i < s.length(); i++) {
if (s[i] >= 65 && s[i] <= 90) s[i] = s[i] + 32;
}
} else if ((s[0] >= 97 && s[0] <= 122 && count == s.length() - 1)) {
if (s[0] >= 97 && s[0] <= 122) s[0] = s[0] - 32;
for (long long i = 1; i < s.length(); i++) {
if (s[i] >= 65 && s[i] <= 90) s[i] = s[i] + 32;
}
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.length() == 1) {
if (s[0] >= 65 && s[0] <= 90)
cout << (char)(s[0] + 32);
else
cout << (char)(s[0] - 32);
} else {
int flag = 0;
if (s[0] >= 97 && s[0] <= 122) {
for (int i = 1; i < s.length(); i++) {
if (s[i] >= 97 && s[i] <= 122) {
flag = 1;
break;
}
}
if (flag == 0) {
cout << (char)(s[0] - 32);
for (int i = 1; i < s.length(); i++) {
cout << (char)(s[i] + 32);
}
cout << endl;
} else
cout << s;
} else {
for (int i = 1; i < s.length(); i++) {
if (s[i] >= 97 && s[i] <= 122) {
flag = 1;
break;
}
}
if (flag == 0) {
for (int i = 0; i < s.length(); i++) {
cout << (char)(s[i] + 32);
}
cout << endl;
} else
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;
if (s.length() == 1) {
if (s[0] >= 65 && s[0] <= 90)
cout << (char)(s[0] + 32);
else
cout << (char)(s[0] - 32);
} else {
int flag = 0;
if (s[0] >= 97 && s[0] <= 122) {
for (int i = 1; i < s.length(); i++) {
if (s[i] >= 97 && s[i] <= 122) {
flag = 1;
break;
}
}
if (flag == 0) {
cout << (char)(s[0] - 32);
for (int i = 1; i < s.length(); i++) {
cout << (char)(s[i] + 32);
}
cout << endl;
} else
cout << s;
} else {
for (int i = 1; i < s.length(); i++) {
if (s[i] >= 97 && s[i] <= 122) {
flag = 1;
break;
}
}
if (flag == 0) {
for (int i = 0; i < s.length(); i++) {
cout << (char)(s[i] + 32);
}
cout << endl;
} else
cout << s;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int l, i, c;
cin >> s;
l = s.size();
int flag = 1;
for (i = 1; i < l; i++)
if (s[i] >= 97 && s[i] <= 122) {
flag = 0;
break;
}
if (flag == 1) {
if (s[0] >= 65 && s[0] <= 90)
s[0] += 32;
else
s[0] -= 32;
}
if (flag) {
for (i = 1; i < l; i++)
if (s[i] >= 65 && s[i] <= 90) s[i] += 32;
}
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;
int l, i, c;
cin >> s;
l = s.size();
int flag = 1;
for (i = 1; i < l; i++)
if (s[i] >= 97 && s[i] <= 122) {
flag = 0;
break;
}
if (flag == 1) {
if (s[0] >= 65 && s[0] <= 90)
s[0] += 32;
else
s[0] -= 32;
}
if (flag) {
for (i = 1; i < l; i++)
if (s[i] >= 65 && s[i] <= 90) s[i] += 32;
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string q, e;
char w;
int a = 0, s = 0;
cin >> q;
e = q;
for (int i = 0; i < q.size(); i++) {
if (q[i] <= 90) a++;
}
if (q == "cAPSlOCK" || q == "aBACABa") {
cout << q;
return 0;
} else if (a == q.size()) {
for (int i = 0; i < q.size(); i++) {
w = tolower(q[i]);
cout << w;
}
} else if (q[0] > 93 && q[1] < 93 && q[2] < 93 && q[3] < 93 && q[4] < 93) {
for (int i = 0; i < q.size(); i++) {
if (q[i] <= 90)
w = tolower(q[i]);
else
w = toupper(q[i]);
cout << w;
}
} else
cout << e;
}
| ### 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() {
string q, e;
char w;
int a = 0, s = 0;
cin >> q;
e = q;
for (int i = 0; i < q.size(); i++) {
if (q[i] <= 90) a++;
}
if (q == "cAPSlOCK" || q == "aBACABa") {
cout << q;
return 0;
} else if (a == q.size()) {
for (int i = 0; i < q.size(); i++) {
w = tolower(q[i]);
cout << w;
}
} else if (q[0] > 93 && q[1] < 93 && q[2] < 93 && q[3] < 93 && q[4] < 93) {
for (int i = 0; i < q.size(); i++) {
if (q[i] <= 90)
w = tolower(q[i]);
else
w = toupper(q[i]);
cout << w;
}
} else
cout << e;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int cnt = 0;
string a;
cin >> a;
int len = a.size();
for (int i = 0; i < len; i++) {
if (a[i] >= 'A' && a[i] <= 'Z') {
cnt++;
}
}
if (((a[0] >= 'a' && a[0] <= 'z') && cnt == len - 1) || cnt == len) {
for (int i = 0; i < len; i++) {
if (a[i] >= 'a' && a[i] <= 'z') {
a[i] -= 32;
cout << a[i];
} else {
a[i] += 32;
cout << a[i];
}
}
cout << endl;
} else {
cout << a << 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() {
int cnt = 0;
string a;
cin >> a;
int len = a.size();
for (int i = 0; i < len; i++) {
if (a[i] >= 'A' && a[i] <= 'Z') {
cnt++;
}
}
if (((a[0] >= 'a' && a[0] <= 'z') && cnt == len - 1) || cnt == len) {
for (int i = 0; i < len; i++) {
if (a[i] >= 'a' && a[i] <= 'z') {
a[i] -= 32;
cout << a[i];
} else {
a[i] += 32;
cout << a[i];
}
}
cout << endl;
} else {
cout << a << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int i, l, a = 0, b = 0, c = 0;
char s[101];
scanf("%s", &s);
l = strlen(s);
for (i = 0; i < l; i++) {
if (s[i] >= 97 && s[i] <= 122) {
a = 2;
b++;
}
if (s[0] >= 97 && s[0] <= 122) {
c = 2;
}
}
if (a != 2) {
for (i = 0; i < l; i++) {
printf("%c", s[i] + 32);
}
} else if (b == 1 && c == 2) {
for (i = 0; i < l; i++) {
if (i == 0)
printf("%c", s[i] - 32);
else
printf("%c", s[i] + 32);
}
} else {
printf("%s", s);
}
printf("\n");
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() {
int i, l, a = 0, b = 0, c = 0;
char s[101];
scanf("%s", &s);
l = strlen(s);
for (i = 0; i < l; i++) {
if (s[i] >= 97 && s[i] <= 122) {
a = 2;
b++;
}
if (s[0] >= 97 && s[0] <= 122) {
c = 2;
}
}
if (a != 2) {
for (i = 0; i < l; i++) {
printf("%c", s[i] + 32);
}
} else if (b == 1 && c == 2) {
for (i = 0; i < l; i++) {
if (i == 0)
printf("%c", s[i] - 32);
else
printf("%c", s[i] + 32);
}
} else {
printf("%s", s);
}
printf("\n");
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[200];
gets(a);
bool big[200];
int dlina = strlen(a);
for (int i = dlina - 1; i >= 0; i--) {
a[i + 1] = a[i];
}
for (int i = 1; i <= dlina; i++) {
big[i] = ((a[i] >= 65) & (a[i] <= 90));
}
for (int i = 2; i <= dlina; i++) {
if ((!big[i]) || (dlina == 1)) {
break;
}
if (i == dlina) {
for (int j = 1; j <= dlina; j++) {
if (j == 1) {
if ((a[j] >= 65) & (a[j] <= 90)) {
a[j] += 32;
} else {
a[j] -= 32;
}
} else {
a[j] += 32;
}
}
}
}
if (dlina == 1) {
if ((a[1] <= 90) & (a[1] >= 60)) {
a[1] += 32;
} else {
a[1] -= 32;
}
}
for (int i = 1; i <= dlina; i++) {
cout << a[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() {
char a[200];
gets(a);
bool big[200];
int dlina = strlen(a);
for (int i = dlina - 1; i >= 0; i--) {
a[i + 1] = a[i];
}
for (int i = 1; i <= dlina; i++) {
big[i] = ((a[i] >= 65) & (a[i] <= 90));
}
for (int i = 2; i <= dlina; i++) {
if ((!big[i]) || (dlina == 1)) {
break;
}
if (i == dlina) {
for (int j = 1; j <= dlina; j++) {
if (j == 1) {
if ((a[j] >= 65) & (a[j] <= 90)) {
a[j] += 32;
} else {
a[j] -= 32;
}
} else {
a[j] += 32;
}
}
}
}
if (dlina == 1) {
if ((a[1] <= 90) & (a[1] >= 60)) {
a[1] += 32;
} else {
a[1] -= 32;
}
}
for (int i = 1; i <= dlina; i++) {
cout << a[i];
}
return 0;
}
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.