output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
int a[200000];
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] & 1)
odd++;
else
even++;
}
if (odd == 0 or (even == 0 and n % 2 == 0)) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
return 0;
}
| ### Prompt
Develop a solution in cpp to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[200000];
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] & 1)
odd++;
else
even++;
}
if (odd == 0 or (even == 0 and n % 2 == 0)) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(0);
long long t, n, a, odds = 0, evens = 0;
cin >> t;
while (t--) {
evens = 0;
odds = 0;
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> a;
if (a % 2 == 0)
evens++;
else
odds++;
}
if (odds % 2 != 0)
cout << "Yes"
<< "\n";
else if (evens > 0 && odds > 0)
cout << "Yes"
<< "\n";
else
cout << "No"
<< "\n";
}
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(0);
long long t, n, a, odds = 0, evens = 0;
cin >> t;
while (t--) {
evens = 0;
odds = 0;
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> a;
if (a % 2 == 0)
evens++;
else
odds++;
}
if (odds % 2 != 0)
cout << "Yes"
<< "\n";
else if (evens > 0 && odds > 0)
cout << "Yes"
<< "\n";
else
cout << "No"
<< "\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int i, n, e = 0, o = 0;
cin >> n;
vector<long long int> v(n);
for (i = 0; i < n; i++) cin >> v[i], o += v[i] % 2, e += 1 - v[i] % 2;
if (!o)
cout << "NO\n";
else if (o - n)
cout << "YES\n";
else if (n % 2)
cout << "YES\n";
else
cout << "NO\n";
}
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int i, n, e = 0, o = 0;
cin >> n;
vector<long long int> v(n);
for (i = 0; i < n; i++) cin >> v[i], o += v[i] % 2, e += 1 - v[i] % 2;
if (!o)
cout << "NO\n";
else if (o - n)
cout << "YES\n";
else if (n % 2)
cout << "YES\n";
else
cout << "NO\n";
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int v[2010];
int n;
cin >> n;
int sum = 0;
for (int i = 0; i < n; i++) {
int s;
cin >> s;
sum += s;
v[i] = s;
}
if (sum % 2 == 0) {
bool flag = false;
if (v[0] % 2 == 0) {
for (int j = 1; j < n; j++) {
if (v[j] % 2 != 0) {
flag = true;
break;
}
}
} else {
for (int j = 1; j < n; j++) {
if (v[j] % 2 == 0) {
flag = true;
break;
}
}
}
if (flag)
cout << "YES\n";
else
cout << "NO\n";
} else {
cout << "YES\n";
}
}
}
| ### Prompt
In Cpp, your task is to solve the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int v[2010];
int n;
cin >> n;
int sum = 0;
for (int i = 0; i < n; i++) {
int s;
cin >> s;
sum += s;
v[i] = s;
}
if (sum % 2 == 0) {
bool flag = false;
if (v[0] % 2 == 0) {
for (int j = 1; j < n; j++) {
if (v[j] % 2 != 0) {
flag = true;
break;
}
}
} else {
for (int j = 1; j < n; j++) {
if (v[j] % 2 == 0) {
flag = true;
break;
}
}
}
if (flag)
cout << "YES\n";
else
cout << "NO\n";
} else {
cout << "YES\n";
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int modInverse(long long int n, long long int p) {
long long int x = n;
long long int y = p - 2;
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long long int nCrModPFermat(long long int n, long long int r, long long int p) {
if (r == 0) return 1;
long long int fac[n + 1];
fac[0] = 1;
for (long long int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
p;
}
long long int fun1(string s, string k, long long int n) {
long long int i, j;
long long int a = 0, b = 0, x = 0;
long long int g[4] = {0};
long long int p = 1e9 + 7;
long long int sum = 0;
for (i = 0; i < n; i++) {
if (s[i] == '1') a++;
if (k[i] == '1') b++;
}
if (a > b) {
x = 1;
}
g[0] = (a - b) * x;
g[1] = (1 - x) * (b - a);
g[2] = (n - a) * x + (1 - x) * (n - b);
g[3] = b * x + (1 - x) * a;
do {
sum = (sum + nCrModPFermat(n, g[0] + g[1], p)) % p;
g[0] += 1;
g[1] += 1;
g[2] -= 1;
g[3] -= 1;
} while (g[2] >= 0 && g[3] >= 0);
return sum;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n, even = 0, odd = 0;
cin >> n;
long long int a[n];
for (long long int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 == 0)
even += 1;
else
odd += 1;
}
if (odd % 2 == 0) {
if (even == 0)
cout << "NO";
else {
if (odd == 0)
cout << "NO";
else {
cout << "YES";
}
}
} else {
cout << "YES";
}
cout << "\n";
}
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int modInverse(long long int n, long long int p) {
long long int x = n;
long long int y = p - 2;
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
long long int nCrModPFermat(long long int n, long long int r, long long int p) {
if (r == 0) return 1;
long long int fac[n + 1];
fac[0] = 1;
for (long long int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
p;
}
long long int fun1(string s, string k, long long int n) {
long long int i, j;
long long int a = 0, b = 0, x = 0;
long long int g[4] = {0};
long long int p = 1e9 + 7;
long long int sum = 0;
for (i = 0; i < n; i++) {
if (s[i] == '1') a++;
if (k[i] == '1') b++;
}
if (a > b) {
x = 1;
}
g[0] = (a - b) * x;
g[1] = (1 - x) * (b - a);
g[2] = (n - a) * x + (1 - x) * (n - b);
g[3] = b * x + (1 - x) * a;
do {
sum = (sum + nCrModPFermat(n, g[0] + g[1], p)) % p;
g[0] += 1;
g[1] += 1;
g[2] -= 1;
g[3] -= 1;
} while (g[2] >= 0 && g[3] >= 0);
return sum;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n, even = 0, odd = 0;
cin >> n;
long long int a[n];
for (long long int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 == 0)
even += 1;
else
odd += 1;
}
if (odd % 2 == 0) {
if (even == 0)
cout << "NO";
else {
if (odd == 0)
cout << "NO";
else {
cout << "YES";
}
}
} else {
cout << "YES";
}
cout << "\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a, x = 0, y = 0, i;
for (i = 0; i < n; i++) {
cin >> a;
if (a % 2 == 0)
x++;
else
y++;
}
if (y == 0)
cout << "NO\n";
else if (x == 0 && n % 2 == 0)
cout << "NO\n";
else
cout << "YES\n";
}
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a, x = 0, y = 0, i;
for (i = 0; i < n; i++) {
cin >> a;
if (a % 2 == 0)
x++;
else
y++;
}
if (y == 0)
cout << "NO\n";
else if (x == 0 && n % 2 == 0)
cout << "NO\n";
else
cout << "YES\n";
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
void Nhap(int &n) { cin >> n; }
void Nhapmang(int a[], int n) {
int i;
for (i = 0; i < n; i++) {
cin >> a[i];
}
}
int KQ(int a[], int n) {
int i;
if (n % 2 == 0) {
for (i = 0; i < n - 1; i++) {
if (a[i] % 2 != a[i + 1] % 2) return 0;
}
return 1;
} else {
for (i = 0; i < n; i++) {
if (a[i] % 2 != 0) return 0;
}
return 1;
}
}
int main() {
int t, i, n, j = 0;
cin >> t;
int b[t];
for (i = 1; i <= t; i++) {
Nhap(n);
int a[n];
Nhapmang(a, n);
b[j] = KQ(a, n);
j++;
}
for (i = 0; i < t - 1; i++) {
if (b[i] == 1) {
cout << "NO"
<< "\n";
} else {
cout << "YES"
<< "\n";
}
}
if (b[t - 1] == 1)
cout << "NO";
else
cout << "YES";
}
| ### Prompt
Generate a CPP solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void Nhap(int &n) { cin >> n; }
void Nhapmang(int a[], int n) {
int i;
for (i = 0; i < n; i++) {
cin >> a[i];
}
}
int KQ(int a[], int n) {
int i;
if (n % 2 == 0) {
for (i = 0; i < n - 1; i++) {
if (a[i] % 2 != a[i + 1] % 2) return 0;
}
return 1;
} else {
for (i = 0; i < n; i++) {
if (a[i] % 2 != 0) return 0;
}
return 1;
}
}
int main() {
int t, i, n, j = 0;
cin >> t;
int b[t];
for (i = 1; i <= t; i++) {
Nhap(n);
int a[n];
Nhapmang(a, n);
b[j] = KQ(a, n);
j++;
}
for (i = 0; i < t - 1; i++) {
if (b[i] == 1) {
cout << "NO"
<< "\n";
} else {
cout << "YES"
<< "\n";
}
}
if (b[t - 1] == 1)
cout << "NO";
else
cout << "YES";
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n;
cin >> n;
int sum = 0, odd = 0, even = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x % 2 == 0) {
even++;
} else {
odd++;
}
sum += x;
}
if (sum % 2 == 1) {
cout << "YES\n";
} else {
if (odd < n && odd > 0) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
}
return 0;
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n;
cin >> n;
int sum = 0, odd = 0, even = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x % 2 == 0) {
even++;
} else {
odd++;
}
sum += x;
}
if (sum % 2 == 1) {
cout << "YES\n";
} else {
if (odd < n && odd > 0) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a[2020];
int main() {
int t, n;
bool f1, f2;
ifstream in("in");
cin >> t;
while (t > 0) {
f1 = false;
f2 = false;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 == 0)
f1 = true;
else
f2 = true;
}
if ((f1 && f2) || (n % 2 == 1 && !f1))
cout << "YES" << '\n';
else
cout << "NO" << '\n';
t--;
}
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[2020];
int main() {
int t, n;
bool f1, f2;
ifstream in("in");
cin >> t;
while (t > 0) {
f1 = false;
f2 = false;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 == 0)
f1 = true;
else
f2 = true;
}
if ((f1 && f2) || (n % 2 == 1 && !f1))
cout << "YES" << '\n';
else
cout << "NO" << '\n';
t--;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, a, odd = 0, ok = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
if (a & 1) {
odd++;
}
}
if (n % 2 == 1) {
if (odd)
ok = 1;
else
ok = 0;
} else {
if (odd && odd <= n - 1)
ok = 1;
else
ok = 0;
}
if (ok) {
printf("YES\n");
} else {
printf("NO\n");
}
}
}
| ### Prompt
Please formulate a cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, a, odd = 0, ok = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
if (a & 1) {
odd++;
}
}
if (n % 2 == 1) {
if (odd)
ok = 1;
else
ok = 0;
} else {
if (odd && odd <= n - 1)
ok = 1;
else
ok = 0;
}
if (ok) {
printf("YES\n");
} else {
printf("NO\n");
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
int aux;
cin >> aux;
if (aux % 2 == 0)
even++;
else
odd++;
}
if (n % 2 == 0) {
if (odd > 0 && even > 0)
cout << "YES\n";
else
cout << "NO\n";
} else {
if (odd > 0)
cout << "YES\n";
else
cout << "NO\n";
}
}
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
int aux;
cin >> aux;
if (aux % 2 == 0)
even++;
else
odd++;
}
if (n % 2 == 0) {
if (odd > 0 && even > 0)
cout << "YES\n";
else
cout << "NO\n";
} else {
if (odd > 0)
cout << "YES\n";
else
cout << "NO\n";
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int even = 0;
int odd = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int num;
cin >> num;
if (num % 2 == 0) {
even++;
} else {
odd++;
}
}
if (odd != 0) {
if (even == 0) {
cout << (odd % 2 == 1 ? "YES" : "NO");
} else {
cout << "YES";
}
} else {
cout << "NO";
}
cout << endl;
}
return 0;
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int even = 0;
int odd = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int num;
cin >> num;
if (num % 2 == 0) {
even++;
} else {
odd++;
}
}
if (odd != 0) {
if (even == 0) {
cout << (odd % 2 == 1 ? "YES" : "NO");
} else {
cout << "YES";
}
} else {
cout << "NO";
}
cout << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long a[n];
long long odd = 0, even = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2)
odd++;
else
even++;
}
if ((even == n) || (n % 2 == 0 && odd == n))
cout << "NO\n";
else
cout << "YES\n";
}
}
| ### Prompt
Develop a solution in CPP to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long a[n];
long long odd = 0, even = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2)
odd++;
else
even++;
}
if ((even == n) || (n % 2 == 0 && odd == n))
cout << "NO\n";
else
cout << "YES\n";
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int d[100000];
int main() {
int a, c, i, n, m, p, t;
cin >> t;
while (t--) {
cin >> n;
p = 0;
for (i = 0; i < n; i++) cin >> d[i];
for (i = 0; i < n; i++) {
if (d[i] % 2 != 0) p++;
}
if (p == 0 || (p == n && n % 2 == 0)) {
printf("NO\n");
} else
printf("YES\n");
}
}
| ### Prompt
Please formulate a CPP solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int d[100000];
int main() {
int a, c, i, n, m, p, t;
cin >> t;
while (t--) {
cin >> n;
p = 0;
for (i = 0; i < n; i++) cin >> d[i];
for (i = 0; i < n; i++) {
if (d[i] % 2 != 0) p++;
}
if (p == 0 || (p == n && n % 2 == 0)) {
printf("NO\n");
} else
printf("YES\n");
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a, f1 = 0, f2 = 0;
for (int i = 0; i < n; i++) {
cin >> a;
if (a % 2 == 1) f1 = 1;
if (a % 2 == 0) f2 = 1;
}
if (f1 == 1 && f2 == 1) cout << "YES" << endl;
if (f1 == 1 && f2 == 0) {
if (n % 2 == 0) cout << "NO" << endl;
if (n % 2 == 1) cout << "YES" << endl;
}
if (f1 == 0 && f2 == 1) cout << "NO" << endl;
}
}
| ### Prompt
Please create a solution in CPP to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a, f1 = 0, f2 = 0;
for (int i = 0; i < n; i++) {
cin >> a;
if (a % 2 == 1) f1 = 1;
if (a % 2 == 0) f2 = 1;
}
if (f1 == 1 && f2 == 1) cout << "YES" << endl;
if (f1 == 1 && f2 == 0) {
if (n % 2 == 0) cout << "NO" << endl;
if (n % 2 == 1) cout << "YES" << endl;
}
if (f1 == 0 && f2 == 1) cout << "NO" << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] & 1)
odd++;
else
even++;
}
if (odd == 0 or (even == 0 and n % 2 == 0)) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] & 1)
odd++;
else
even++;
}
if (odd == 0 or (even == 0 and n % 2 == 0)) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
int n, a[2000];
for (int i = 0; i < t; i++) {
cin >> n;
int sum = 0;
for (int j = 0; j < n; j++) {
cin >> a[j];
if (a[j] % 2 == 1) sum += 1;
}
if (sum) {
if (sum % 2 == 1 || sum < n)
cout << "YES" << endl;
else
cout << "NO" << endl;
} else
cout << "NO" << endl;
}
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
int n, a[2000];
for (int i = 0; i < t; i++) {
cin >> n;
int sum = 0;
for (int j = 0; j < n; j++) {
cin >> a[j];
if (a[j] % 2 == 1) sum += 1;
}
if (sum) {
if (sum % 2 == 1 || sum < n)
cout << "YES" << endl;
else
cout << "NO" << endl;
} else
cout << "NO" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n;
cin >> t;
while (t--) {
cin >> n;
int num[n];
int sum = 0, even = 0, odd = 0;
for (int i = 0; i < n; i++) {
cin >> num[i];
sum += num[i];
if (num[i] % 2 == 0) even++;
if (num[i] % 2 != 0) odd++;
}
if (sum % 2 != 0 || (even >= 1 && odd >= 1)) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}
| ### Prompt
Generate a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n;
cin >> t;
while (t--) {
cin >> n;
int num[n];
int sum = 0, even = 0, odd = 0;
for (int i = 0; i < n; i++) {
cin >> num[i];
sum += num[i];
if (num[i] % 2 == 0) even++;
if (num[i] % 2 != 0) odd++;
}
if (sum % 2 != 0 || (even >= 1 && odd >= 1)) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int sum = 0;
bool odd = false, even = false;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
if (temp & 1) {
odd = true;
} else {
even = true;
}
sum += temp;
}
if (sum % 2 == 0) {
if (odd && even) {
cout << "YES\n";
} else {
cout << "NO\n";
}
} else {
cout << "YES\n";
}
}
return 0;
}
| ### Prompt
Create a solution in CPP for the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int sum = 0;
bool odd = false, even = false;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
if (temp & 1) {
odd = true;
} else {
even = true;
}
sum += temp;
}
if (sum % 2 == 0) {
if (odd && even) {
cout << "YES\n";
} else {
cout << "NO\n";
}
} else {
cout << "YES\n";
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool check_odd(long long num) {
if (num % 2 == 0) {
return false;
}
return true;
}
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long arr[n];
long long sum = 0;
long long ev = 0, od = 0;
for (long long i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
if (arr[i] % 2 == 0)
ev++;
else
od++;
}
if (check_odd(sum)) {
cout << "YES" << endl;
continue;
}
if (od % 2 != 0) {
cout << "YES" << endl;
} else if (od != n && od > 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
| ### Prompt
Create a solution in cpp for the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool check_odd(long long num) {
if (num % 2 == 0) {
return false;
}
return true;
}
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long arr[n];
long long sum = 0;
long long ev = 0, od = 0;
for (long long i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
if (arr[i] % 2 == 0)
ev++;
else
od++;
}
if (check_odd(sum)) {
cout << "YES" << endl;
continue;
}
if (od % 2 != 0) {
cout << "YES" << endl;
} else if (od != n && od > 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int odd_cnt = 0;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
if (v[i] % 2 == 1) odd_cnt++;
}
if (odd_cnt == 0) {
cout << "NO" << endl;
} else if (n % 2 == 0 && odd_cnt == n) {
cout << "NO" << endl;
} else if (n % 2 == 1 && odd_cnt == n) {
cout << "YES" << endl;
} else if (odd_cnt != 0) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
}
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int odd_cnt = 0;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
if (v[i] % 2 == 1) odd_cnt++;
}
if (odd_cnt == 0) {
cout << "NO" << endl;
} else if (n % 2 == 0 && odd_cnt == n) {
cout << "NO" << endl;
} else if (n % 2 == 1 && odd_cnt == n) {
cout << "YES" << endl;
} else if (odd_cnt != 0) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int cases;
cin >> cases;
for (int iter = 0; iter < cases; ++iter) {
int n;
cin >> n;
bool all_even = true;
bool all_odd = true;
for (int i = 0; i < n; ++i) {
int k;
cin >> k;
if (k % 2 == 0)
all_odd = false;
else
all_even = false;
}
if (all_even || (n % 2 == 0) && all_odd)
cout << "NO\n";
else
cout << "YES\n";
}
return 0;
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int cases;
cin >> cases;
for (int iter = 0; iter < cases; ++iter) {
int n;
cin >> n;
bool all_even = true;
bool all_odd = true;
for (int i = 0; i < n; ++i) {
int k;
cin >> k;
if (k % 2 == 0)
all_odd = false;
else
all_even = false;
}
if (all_even || (n % 2 == 0) && all_odd)
cout << "NO\n";
else
cout << "YES\n";
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long t;
cin >> t;
while (t--) {
int n;
cin >> n;
int ctr = 0;
for (int i = 0; i < n; i++) {
long x;
cin >> x;
if (x % 2 != 0) {
ctr++;
}
}
if (ctr % 2 != 0) {
cout << "YES" << endl;
} else if (ctr != 0 && ctr < n) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
| ### Prompt
Create a solution in cpp for the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long t;
cin >> t;
while (t--) {
int n;
cin >> n;
int ctr = 0;
for (int i = 0; i < n; i++) {
long x;
cin >> x;
if (x % 2 != 0) {
ctr++;
}
}
if (ctr % 2 != 0) {
cout << "YES" << endl;
} else if (ctr != 0 && ctr < n) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n, t, l, r;
set<int> d;
map<int, int> mp;
int a[300005];
int main() {
cin >> t;
while (t--) {
memset(a, 0, sizeof(a));
int pr = 0;
int pr2 = 0;
int s = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
s += a[i];
if (a[i] % 2 == 0) pr = 1;
if (a[i] % 2 == 1) pr2 = 1;
}
if (s % 2 == 1)
cout << "Yes" << endl;
else if (s % 2 == 0 && pr == 1 && pr2 == 1)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, t, l, r;
set<int> d;
map<int, int> mp;
int a[300005];
int main() {
cin >> t;
while (t--) {
memset(a, 0, sizeof(a));
int pr = 0;
int pr2 = 0;
int s = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
s += a[i];
if (a[i] % 2 == 0) pr = 1;
if (a[i] % 2 == 1) pr2 = 1;
}
if (s % 2 == 1)
cout << "Yes" << endl;
else if (s % 2 == 0 && pr == 1 && pr2 == 1)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 1e5 + 10;
void solve() {
long long n, sum = 0, even = 0, odd = 0;
cin >> n;
long long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2) {
odd++;
} else {
even++;
}
}
if (odd % 2) {
cout << "YES\n";
} else {
if (even != 0 && odd != 0) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return;
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int test = 1;
cin >> test;
while (test--) {
solve();
}
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
You are given an array a consisting of n integers.
In one move, you can choose two indices 1 β€ i, j β€ n such that i β j and set a_i := a_j. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose i and j and replace a_i with a_j).
Your task is to say if it is possible to obtain an array with an odd (not divisible by 2) sum of elements.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2000) β the number of test cases.
The next 2t lines describe test cases. The first line of the test case contains one integer n (1 β€ n β€ 2000) β the number of elements in a. The second line of the test case contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 2000), where a_i is the i-th element of a.
It is guaranteed that the sum of n over all test cases does not exceed 2000 (β n β€ 2000).
Output
For each test case, print the answer on it β "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.
Example
Input
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
Output
YES
NO
YES
NO
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 1e5 + 10;
void solve() {
long long n, sum = 0, even = 0, odd = 0;
cin >> n;
long long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2) {
odd++;
} else {
even++;
}
}
if (odd % 2) {
cout << "YES\n";
} else {
if (even != 0 && odd != 0) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return;
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int test = 1;
cin >> test;
while (test--) {
solve();
}
}
``` |
#include <bits/stdc++.h>
int main() {
int n, i, j, m, sum, len;
char a[101];
while (scanf("%s", a) != EOF) {
len = strlen(a);
for (i = 1; i < len; i++) {
if (a[i] < 'a')
;
else
break;
}
if (i != len)
printf("%s\n", a);
else {
for (i = 0; i < len; i++)
printf("%c", a[i] >= 'a' ? a[i] - 32 : a[i] + 32);
printf("\n");
}
}
}
| ### 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 n, i, j, m, sum, len;
char a[101];
while (scanf("%s", a) != EOF) {
len = strlen(a);
for (i = 1; i < len; i++) {
if (a[i] < 'a')
;
else
break;
}
if (i != len)
printf("%s\n", a);
else {
for (i = 0; i < len; i++)
printf("%c", a[i] >= 'a' ? a[i] - 32 : a[i] + 32);
printf("\n");
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
string S;
int main() {
bool State = true;
cin >> S;
for (int i = 1; i < S.length(); i++) {
if (S[i] >= 'a' && S[i] <= 'z') {
State = false;
}
}
if (State) {
for (int i = 1; i < S.length(); i++) {
S[i] = tolower(S[i]);
}
if (S[0] >= 'a' && S[0] <= 'z') {
S[0] = toupper(S[0]);
} else if (S[0] >= 'A' && S[0] <= 'Z') {
S[0] = tolower(S[0]);
}
}
cout << S;
return 0;
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string S;
int main() {
bool State = true;
cin >> S;
for (int i = 1; i < S.length(); i++) {
if (S[i] >= 'a' && S[i] <= 'z') {
State = false;
}
}
if (State) {
for (int i = 1; i < S.length(); i++) {
S[i] = tolower(S[i]);
}
if (S[0] >= 'a' && S[0] <= 'z') {
S[0] = toupper(S[0]);
} else if (S[0] >= 'A' && S[0] <= 'Z') {
S[0] = tolower(S[0]);
}
}
cout << S;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
std::string s;
std::cin >> s;
if (s.size() == 1) {
if (std::islower(s[0])) {
s[0] = std::toupper(s[0]);
} else {
s[0] = std::tolower(s[0]);
}
std::cout << s;
return 0;
} else {
if (std::islower(s[0])) {
for (int i = 1; i != s.size(); i++) {
if (islower(s[i])) {
std::cout << s;
return 0;
}
}
s[0] = std::toupper(s[0]);
for (int i = 1; i != s.size(); i++) {
s[i] = std::tolower(s[i]);
}
std::cout << s;
return 0;
} else {
for (int i = 1; i != s.size(); i++) {
if (std::islower(s[i])) {
std::cout << s;
return 0;
}
}
s[0] = std::tolower(s[0]);
for (int i = 1; i != s.size(); i++) {
s[i] = std::tolower(s[i]);
}
std::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>
int main() {
std::string s;
std::cin >> s;
if (s.size() == 1) {
if (std::islower(s[0])) {
s[0] = std::toupper(s[0]);
} else {
s[0] = std::tolower(s[0]);
}
std::cout << s;
return 0;
} else {
if (std::islower(s[0])) {
for (int i = 1; i != s.size(); i++) {
if (islower(s[i])) {
std::cout << s;
return 0;
}
}
s[0] = std::toupper(s[0]);
for (int i = 1; i != s.size(); i++) {
s[i] = std::tolower(s[i]);
}
std::cout << s;
return 0;
} else {
for (int i = 1; i != s.size(); i++) {
if (std::islower(s[i])) {
std::cout << s;
return 0;
}
}
s[0] = std::tolower(s[0]);
for (int i = 1; i != s.size(); i++) {
s[i] = std::tolower(s[i]);
}
std::cout << s;
return 0;
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int p = s.length(), cnt = 0, flag = 0, j;
if (s[0] >= 'a' && s[0] <= 'z') flag = 1;
for (int i = 0; i < p; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') cnt++;
}
if (cnt == p || (flag == 1 && cnt == p - 1)) {
for (int i = 0; i < p; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
char q;
q = s[i];
s[i] = tolower(q);
} else {
char m = s[i];
s[i] = toupper(m);
}
}
cout << s;
} else {
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;
int main() {
string s;
cin >> s;
int p = s.length(), cnt = 0, flag = 0, j;
if (s[0] >= 'a' && s[0] <= 'z') flag = 1;
for (int i = 0; i < p; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') cnt++;
}
if (cnt == p || (flag == 1 && cnt == p - 1)) {
for (int i = 0; i < p; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
char q;
q = s[i];
s[i] = tolower(q);
} else {
char m = s[i];
s[i] = toupper(m);
}
}
cout << s;
} else {
cout << s;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
int n = str.length();
int flag = 0;
if (str.length() > 1) {
for (int i = 1; i < n; i++) {
if (str[i] > 96) {
flag = 0;
break;
} else
flag = 1;
}
} else
flag = 1;
if (flag == 1) {
for (int i = 0; i < n; i++) {
if (str[i] < 96)
str[i] += 32;
else if (str[i] > 96)
str[i] -= 32;
}
}
cout << str << endl;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
int n = str.length();
int flag = 0;
if (str.length() > 1) {
for (int i = 1; i < n; i++) {
if (str[i] > 96) {
flag = 0;
break;
} else
flag = 1;
}
} else
flag = 1;
if (flag == 1) {
for (int i = 0; i < n; i++) {
if (str[i] < 96)
str[i] += 32;
else if (str[i] > 96)
str[i] -= 32;
}
}
cout << str << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int r = 0;
for (int i = 1; s[i] != '\0'; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') r++;
}
if (r == s.size() - 1) {
for (int i = 0; s[i] != '\0'; i++) {
if (s[i] >= 'a' && s[i] <= 'z')
s[i] = s[i] - 32;
else if (s[i] >= 'A' && s[i] <= 'Z')
s[i] = s[i] + 32;
}
}
cout << s;
}
| ### Prompt
Please create a solution in cpp to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int r = 0;
for (int i = 1; s[i] != '\0'; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') r++;
}
if (r == s.size() - 1) {
for (int i = 0; s[i] != '\0'; i++) {
if (s[i] >= 'a' && s[i] <= 'z')
s[i] = s[i] - 32;
else if (s[i] >= 'A' && s[i] <= 'Z')
s[i] = s[i] + 32;
}
}
cout << s;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
getline(cin, str);
bool OK = true;
for (int i = 1; i < str.size(); i++) {
if (str[i] >= 'a' && str[i] <= 'z') {
OK = false;
break;
}
}
if (OK) {
for (int i = 0; i < str.size(); i++) {
if (str[i] >= 'A' && str[i] <= 'Z')
str[i] += 32;
else
str[i] -= 32;
}
}
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() {
string str;
getline(cin, str);
bool OK = true;
for (int i = 1; i < str.size(); i++) {
if (str[i] >= 'a' && str[i] <= 'z') {
OK = false;
break;
}
}
if (OK) {
for (int i = 0; i < str.size(); i++) {
if (str[i] >= 'A' && str[i] <= 'Z')
str[i] += 32;
else
str[i] -= 32;
}
}
cout << str << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
return b == 0 ? a : gcd(b, a % b);
}
const long long MOD = 1000000007;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
string s;
cin >> s;
int i, c = 0, len;
len = ((int)(s).size());
for (i = 1; i < len; i++) {
if (s[i] >= 65 && s[i] <= 90) c++;
}
if (c == len - 1) {
s[0] >= 97 ? s[0] -= 32 : s[0] += 32;
for (i = 1; i < len; i++) {
if (s[i] >= 65 && s[i] <= 90) {
s[i] += 32;
}
}
}
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;
long long int gcd(long long int a, long long int b) {
return b == 0 ? a : gcd(b, a % b);
}
const long long MOD = 1000000007;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
string s;
cin >> s;
int i, c = 0, len;
len = ((int)(s).size());
for (i = 1; i < len; i++) {
if (s[i] >= 65 && s[i] <= 90) c++;
}
if (c == len - 1) {
s[0] >= 97 ? s[0] -= 32 : s[0] += 32;
for (i = 1; i < len; i++) {
if (s[i] >= 65 && s[i] <= 90) {
s[i] += 32;
}
}
}
cout << s << "\n";
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void read(vector<int> &a) {
for (auto &it : a) cin >> it;
}
void Solve() {
string s;
cin >> s;
int cnt = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
cnt++;
}
}
if (cnt == s.size()) {
for (int i = 0; i < s.size(); i++) {
cout << (char)tolower(s[i]);
}
cout << "\n";
} else if (cnt == (s.size() - 1) && 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 << "\n";
} else {
cout << s << "\n";
}
}
int32_t main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
Solve();
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;
const int mod = 1e9 + 7;
void read(vector<int> &a) {
for (auto &it : a) cin >> it;
}
void Solve() {
string s;
cin >> s;
int cnt = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
cnt++;
}
}
if (cnt == s.size()) {
for (int i = 0; i < s.size(); i++) {
cout << (char)tolower(s[i]);
}
cout << "\n";
} else if (cnt == (s.size() - 1) && 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 << "\n";
} else {
cout << s << "\n";
}
}
int32_t main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
Solve();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int ok = 1;
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
ok = 0;
}
}
if (ok == 0)
cout << s << endl;
else {
for (int i = 0; i < s.length(); i++) {
if (isupper(s[i]))
s[i] = tolower(s[i]);
else
s[i] = toupper(s[i]);
}
cout << s << endl;
}
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int ok = 1;
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
ok = 0;
}
}
if (ok == 0)
cout << s << endl;
else {
for (int i = 0; i < s.length(); i++) {
if (isupper(s[i]))
s[i] = tolower(s[i]);
else
s[i] = toupper(s[i]);
}
cout << s << endl;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string x, f = "", r = "";
int c = 0;
char l;
cin >> x;
if (x[0] >= 'a' && x[0] <= 'z') {
for (int i = 1; i < (x.length()); i++) {
if (x[i] >= 'A' && x[i] <= 'Z') {
c++;
}
}
if (c == (x.length() - 1)) {
l = x[0];
putwchar(toupper(l));
r[0] = l;
transform(x.begin(), x.end(), x.begin(), ::tolower);
for (int y = 1; y < (x.length()); y++) {
r += x[y];
}
cout << r;
} else {
cout << x;
}
} else {
for (int i = 0; i < (x.length()); i++) {
if (x[i] >= 'A' && x[i] <= 'Z') {
c++;
}
}
if (c == (x.length())) {
transform(x.begin(), x.end(), x.begin(), ::tolower);
cout << x;
} else {
cout << x;
}
}
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 x, f = "", r = "";
int c = 0;
char l;
cin >> x;
if (x[0] >= 'a' && x[0] <= 'z') {
for (int i = 1; i < (x.length()); i++) {
if (x[i] >= 'A' && x[i] <= 'Z') {
c++;
}
}
if (c == (x.length() - 1)) {
l = x[0];
putwchar(toupper(l));
r[0] = l;
transform(x.begin(), x.end(), x.begin(), ::tolower);
for (int y = 1; y < (x.length()); y++) {
r += x[y];
}
cout << r;
} else {
cout << x;
}
} else {
for (int i = 0; i < (x.length()); i++) {
if (x[i] >= 'A' && x[i] <= 'Z') {
c++;
}
}
if (c == (x.length())) {
transform(x.begin(), x.end(), x.begin(), ::tolower);
cout << x;
} else {
cout << x;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
stringstream ss(s);
char ch;
bool isFirstSmall = false;
bool isAllCapital = true;
ss >> ch;
if (int(ch) >= 97) isFirstSmall = true;
if (isFirstSmall) {
stringstream ss1(s);
ss1 >> ch;
while (ss1 >> ch) {
if (int(ch) >= 97) {
isAllCapital = false;
break;
}
}
} else {
stringstream ss3(s);
bool isCapital = true;
while (ss >> ch) {
if (int(ch) >= 97) isCapital = false;
}
if (isCapital) {
stringstream ss4(s);
while (ss4 >> ch) {
cout << char(int(ch) + 32);
}
} else
cout << s;
exit(0);
}
if (!isAllCapital) {
cout << s;
exit(0);
}
if (isAllCapital) {
stringstream ss2(s);
ss2 >> ch;
cout << char(int(ch) - 32);
while (ss2 >> ch) {
cout << char(int(ch) + 32);
}
}
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;
stringstream ss(s);
char ch;
bool isFirstSmall = false;
bool isAllCapital = true;
ss >> ch;
if (int(ch) >= 97) isFirstSmall = true;
if (isFirstSmall) {
stringstream ss1(s);
ss1 >> ch;
while (ss1 >> ch) {
if (int(ch) >= 97) {
isAllCapital = false;
break;
}
}
} else {
stringstream ss3(s);
bool isCapital = true;
while (ss >> ch) {
if (int(ch) >= 97) isCapital = false;
}
if (isCapital) {
stringstream ss4(s);
while (ss4 >> ch) {
cout << char(int(ch) + 32);
}
} else
cout << s;
exit(0);
}
if (!isAllCapital) {
cout << s;
exit(0);
}
if (isAllCapital) {
stringstream ss2(s);
ss2 >> ch;
cout << char(int(ch) - 32);
while (ss2 >> ch) {
cout << char(int(ch) + 32);
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int l, i, flag = 0;
char str[101];
cin >> str;
l = strlen(str);
if (l == 1 && str[0] <= 'z' && str[0] >= 'a')
str[0] -= 32;
else {
for (i = 1; i < l; ++i) {
if (str[i] <= 'z' && str[i] >= 'a') {
flag = 1;
break;
}
}
if (flag == 0) {
for (i = 0; i < l; ++i) {
if (str[i] >= 'A' && str[i] <= 'Z')
str[i] += 32;
else
str[i] -= 32;
}
}
}
cout << str;
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 l, i, flag = 0;
char str[101];
cin >> str;
l = strlen(str);
if (l == 1 && str[0] <= 'z' && str[0] >= 'a')
str[0] -= 32;
else {
for (i = 1; i < l; ++i) {
if (str[i] <= 'z' && str[i] >= 'a') {
flag = 1;
break;
}
}
if (flag == 0) {
for (i = 0; i < l; ++i) {
if (str[i] >= 'A' && str[i] <= 'Z')
str[i] += 32;
else
str[i] -= 32;
}
}
}
cout << str;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int i, count = 1;
char a[100];
scanf("%s", &a);
for (i = 1; a[i] != '\0'; i++) {
if (a[i] >= 'A' && a[i] <= 'Z') count = count + 1;
}
if (count == i) {
for (i = 0; a[i] != '\0'; 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;
}
printf("%s\n", a);
} else
printf("%s\n", a);
count = 0;
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, count = 1;
char a[100];
scanf("%s", &a);
for (i = 1; a[i] != '\0'; i++) {
if (a[i] >= 'A' && a[i] <= 'Z') count = count + 1;
}
if (count == i) {
for (i = 0; a[i] != '\0'; 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;
}
printf("%s\n", a);
} else
printf("%s\n", a);
count = 0;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int check(char a) {
if ((int)a < 123 && (int)a > 96)
return true;
else
return false;
}
char anticaps(char a) {
int a1 = (int)a + 32;
return a1;
}
int main() {
string A;
int tmp = 0;
getline(cin, A);
for (int i(0); i < A.length(); i++)
if (!check(A[i])) tmp++;
if (A.length() == tmp)
for (int i(0); i < A.length(); i++) cout << anticaps(A[i]);
else if (check(A[0]) && A.length() - 1 == tmp) {
A[0] = (int)A[0] - 64;
for (int i(0); i < A.length(); i++) cout << anticaps(A[i]);
} else
for (int i(0); i < A.length(); i++) cout << A[i];
}
| ### 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 check(char a) {
if ((int)a < 123 && (int)a > 96)
return true;
else
return false;
}
char anticaps(char a) {
int a1 = (int)a + 32;
return a1;
}
int main() {
string A;
int tmp = 0;
getline(cin, A);
for (int i(0); i < A.length(); i++)
if (!check(A[i])) tmp++;
if (A.length() == tmp)
for (int i(0); i < A.length(); i++) cout << anticaps(A[i]);
else if (check(A[0]) && A.length() - 1 == tmp) {
A[0] = (int)A[0] - 64;
for (int i(0); i < A.length(); i++) cout << anticaps(A[i]);
} else
for (int i(0); i < A.length(); i++) cout << A[i];
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin >> s;
if (isupper(s[0])) {
int counter = 0;
for (int i = 1; i < s.length(); i++) {
if (isupper(s[i])) counter++;
}
if (counter == s.length() - 1) {
for (int i = 0; i < s.length(); i++) {
s[i] = tolower(s[i]);
}
}
cout << s;
} else {
int counter = 0;
for (int i = 0; i < s.length(); i++) {
if (isupper(s[i])) counter++;
}
if (s.length() - 1 == counter) {
s[0] = toupper(s[0]);
for (int i = 1; i < s.length(); i++) {
s[i] = tolower(s[i]);
}
}
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(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin >> s;
if (isupper(s[0])) {
int counter = 0;
for (int i = 1; i < s.length(); i++) {
if (isupper(s[i])) counter++;
}
if (counter == s.length() - 1) {
for (int i = 0; i < s.length(); i++) {
s[i] = tolower(s[i]);
}
}
cout << s;
} else {
int counter = 0;
for (int i = 0; i < s.length(); i++) {
if (isupper(s[i])) counter++;
}
if (s.length() - 1 == counter) {
s[0] = toupper(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() {
string s;
cin >> s;
char u;
bool c = true;
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) c = false;
}
if (c == true) {
for (int j = 0; j < s.length(); j++) {
if (islower(s[j]))
u = toupper(s[j]);
else
u = tolower(s[j]);
cout << u;
}
} else
cout << s;
}
| ### 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;
char u;
bool c = true;
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) c = false;
}
if (c == true) {
for (int j = 0; j < s.length(); j++) {
if (islower(s[j]))
u = toupper(s[j]);
else
u = tolower(s[j]);
cout << u;
}
} else
cout << s;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string x;
cin >> x;
int t = 0, t1 = 0;
for (int i = 0; i < x.size(); i++) {
if (x[i] >= 97 && x[i] <= 122)
t1++;
else if (x[i] >= 65 && x[i] <= 90)
t++;
}
if (t1 == 1 && x[0] >= 97 && x[0] <= 122) {
x[0] = x[0] - 32;
cout << x[0];
for (int i = 1; i < x.size(); i++) {
x[i] = x[i] + 32;
cout << x[i];
}
} else if (t == x.size()) {
for (int i = 0; i < x.size(); i++) {
x[i] = x[i] + 32;
cout << x[i];
}
} else
cout << x << 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 x;
cin >> x;
int t = 0, t1 = 0;
for (int i = 0; i < x.size(); i++) {
if (x[i] >= 97 && x[i] <= 122)
t1++;
else if (x[i] >= 65 && x[i] <= 90)
t++;
}
if (t1 == 1 && x[0] >= 97 && x[0] <= 122) {
x[0] = x[0] - 32;
cout << x[0];
for (int i = 1; i < x.size(); i++) {
x[i] = x[i] + 32;
cout << x[i];
}
} else if (t == x.size()) {
for (int i = 0; i < x.size(); i++) {
x[i] = x[i] + 32;
cout << x[i];
}
} else
cout << x << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string change_case(string data, int i) {
if (i == 0)
transform(data.begin(), data.end(), data.begin(), ::tolower);
else
transform(data.begin(), data.end(), data.begin(), ::toupper);
return data;
}
int main() {
string s;
int upcase = 0, lowcase = 0, i, testResult;
cin >> s;
int len = s.length();
for (i = 0; i < len; i++) {
if (s[i] == tolower(s[i]))
lowcase++;
else
upcase++;
}
if (len - upcase == 1 && s[0] == tolower(s[0])) {
testResult = 1;
} else if (upcase == len)
testResult = 2;
else
testResult = 0;
if (testResult) {
s = change_case(s, 0);
if (testResult == 1)
s[0] = toupper(s[0]);
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;
string change_case(string data, int i) {
if (i == 0)
transform(data.begin(), data.end(), data.begin(), ::tolower);
else
transform(data.begin(), data.end(), data.begin(), ::toupper);
return data;
}
int main() {
string s;
int upcase = 0, lowcase = 0, i, testResult;
cin >> s;
int len = s.length();
for (i = 0; i < len; i++) {
if (s[i] == tolower(s[i]))
lowcase++;
else
upcase++;
}
if (len - upcase == 1 && s[0] == tolower(s[0])) {
testResult = 1;
} else if (upcase == len)
testResult = 2;
else
testResult = 0;
if (testResult) {
s = change_case(s, 0);
if (testResult == 1)
s[0] = toupper(s[0]);
else {
}
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, k;
int z = 0;
getline(cin, s);
k = s;
for (int i = 1; i < s.length(); ++i) {
if (int(s[i]) < 97) {
s[i] = int(s[i]) + 32;
} else if (i != 0) {
z = 1;
cout << k;
break;
}
}
if (z != 1) {
if (int(s[0]) > 97 || int(s[0]) == 97) {
s[0] = int(s[0]) - 32;
} else
s[0] = int(s[0]) + 32;
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;
int main() {
string s, k;
int z = 0;
getline(cin, s);
k = s;
for (int i = 1; i < s.length(); ++i) {
if (int(s[i]) < 97) {
s[i] = int(s[i]) + 32;
} else if (i != 0) {
z = 1;
cout << k;
break;
}
}
if (z != 1) {
if (int(s[0]) > 97 || int(s[0]) == 97) {
s[0] = int(s[0]) - 32;
} else
s[0] = int(s[0]) + 32;
cout << s;
}
return 0;
}
``` |
#include <bits/stdc++.h>
const double PI = acos(-1.0);
const double e = exp(1.0);
const int INF = 0x7fffffff;
;
template <class T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template <class T>
inline T Min(T a, T b) {
return a < b ? a : b;
}
template <class T>
inline T Max(T a, T b) {
return a > b ? a : b;
}
bool cmpbig(int a, int b) { return a > b; }
bool cmpsmall(int a, int b) { return a < b; }
using namespace std;
int n, v[100010], pos[100010];
bool canmeet(double t) {
double lmin = 1e9, rmax = -1;
for (int i = 0; i < n; i++) {
lmin = min(lmin, pos[i] + v[i] * t);
rmax = max(rmax, pos[i] - v[i] * t);
}
if (lmin >= rmax) return true;
return false;
}
bool upper(char c) {
if (c >= 'A' && c <= 'Z') return true;
return false;
}
bool lowper(char c) {
if (c >= 'a' && c <= 'z') return true;
return false;
}
void toupper(char &c) { c -= 32; }
void tolowper(char &c) { c += 32; }
int main() {
char str[1010];
while (~scanf("%s", str)) {
int cnt = 0, l = strlen(str);
for (int i = 0; i < l; i++) {
if (lowper(str[i])) cnt++;
}
if (cnt == 0 || (cnt == 1 && lowper(str[0]))) {
for (int i = 0; i < l; i++) {
if (!upper(str[i]))
toupper(str[i]);
else
tolowper(str[i]);
}
}
cout << str << 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>
const double PI = acos(-1.0);
const double e = exp(1.0);
const int INF = 0x7fffffff;
;
template <class T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template <class T>
inline T Min(T a, T b) {
return a < b ? a : b;
}
template <class T>
inline T Max(T a, T b) {
return a > b ? a : b;
}
bool cmpbig(int a, int b) { return a > b; }
bool cmpsmall(int a, int b) { return a < b; }
using namespace std;
int n, v[100010], pos[100010];
bool canmeet(double t) {
double lmin = 1e9, rmax = -1;
for (int i = 0; i < n; i++) {
lmin = min(lmin, pos[i] + v[i] * t);
rmax = max(rmax, pos[i] - v[i] * t);
}
if (lmin >= rmax) return true;
return false;
}
bool upper(char c) {
if (c >= 'A' && c <= 'Z') return true;
return false;
}
bool lowper(char c) {
if (c >= 'a' && c <= 'z') return true;
return false;
}
void toupper(char &c) { c -= 32; }
void tolowper(char &c) { c += 32; }
int main() {
char str[1010];
while (~scanf("%s", str)) {
int cnt = 0, l = strlen(str);
for (int i = 0; i < l; i++) {
if (lowper(str[i])) cnt++;
}
if (cnt == 0 || (cnt == 1 && lowper(str[0]))) {
for (int i = 0; i < l; i++) {
if (!upper(str[i]))
toupper(str[i]);
else
tolowper(str[i]);
}
}
cout << str << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q = 0;
char s[100];
scanf("%s", s);
for (int i = 1; i < strlen(s); i++) {
if (s[i] >= 65 && s[i] <= 90) {
q++;
}
}
if (q == strlen(s) - 1) {
for (int 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
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 q = 0;
char s[100];
scanf("%s", s);
for (int i = 1; i < strlen(s); i++) {
if (s[i] >= 65 && s[i] <= 90) {
q++;
}
}
if (q == strlen(s) - 1) {
for (int 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;
long long m, n;
string s;
int CapsLock(string s) {
for (int i = 0; i < s.size(); i++) {
if (s[i] > 92) {
s[i] -= 32;
} else if (s[i] < 92) {
s[i] += 32;
}
}
cout << s;
return 0;
}
int main() {
cin >> s;
if (s.size() == 1) {
CapsLock(s);
return 0;
}
for (int i = 0; i < s.size(); i++) {
if (s[i] < 92) {
m++;
if (m == s.size()) {
CapsLock(s);
return 0;
}
}
if (s[0] > 92 && s[i] < 92 && i != 0) {
n++;
if (n + 1 == s.size()) {
CapsLock(s);
return 0;
}
}
}
cout << s;
}
| ### Prompt
Please create a solution in cpp to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long m, n;
string s;
int CapsLock(string s) {
for (int i = 0; i < s.size(); i++) {
if (s[i] > 92) {
s[i] -= 32;
} else if (s[i] < 92) {
s[i] += 32;
}
}
cout << s;
return 0;
}
int main() {
cin >> s;
if (s.size() == 1) {
CapsLock(s);
return 0;
}
for (int i = 0; i < s.size(); i++) {
if (s[i] < 92) {
m++;
if (m == s.size()) {
CapsLock(s);
return 0;
}
}
if (s[0] > 92 && s[i] < 92 && i != 0) {
n++;
if (n + 1 == s.size()) {
CapsLock(s);
return 0;
}
}
}
cout << s;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
getline(cin, s);
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) cout << s, exit(0);
}
for (int i = 0; i < s.length(); i++) {
if (s[i] >= 65 && s[i] <= 90) {
s[i] = tolower(s[i]);
continue;
}
if (s[i] >= 97 && s[i] <= 122) s[i] = toupper(s[i]);
continue;
}
cout << s;
return 0;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
getline(cin, s);
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) cout << s, exit(0);
}
for (int i = 0; i < s.length(); i++) {
if (s[i] >= 65 && s[i] <= 90) {
s[i] = tolower(s[i]);
continue;
}
if (s[i] >= 97 && s[i] <= 122) s[i] = toupper(s[i]);
continue;
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 1;
string str, temp;
cin >> str;
if (str[0] <= 'Z' && str[0] >= 'A')
temp.push_back(str[0] + 'a' - 'A');
else
temp.push_back(str[0] - ('a' - 'A'));
if (str.length() == 1) {
str = temp;
cout << str << endl;
return 0;
}
if (str[0] <= 'Z' && str[0] >= 'A' && str[1] <= 'z' && str[1] >= 'a') {
cout << str << endl;
return 0;
}
for (int i = 1; i < str.length(); i++)
if (str[i] <= 'Z' && str[i] >= 'A') {
temp.push_back(str[i] + 'a' - 'A');
n++;
}
if (n == str.length())
cout << temp << endl;
else
cout << str << 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() {
int n = 1;
string str, temp;
cin >> str;
if (str[0] <= 'Z' && str[0] >= 'A')
temp.push_back(str[0] + 'a' - 'A');
else
temp.push_back(str[0] - ('a' - 'A'));
if (str.length() == 1) {
str = temp;
cout << str << endl;
return 0;
}
if (str[0] <= 'Z' && str[0] >= 'A' && str[1] <= 'z' && str[1] >= 'a') {
cout << str << endl;
return 0;
}
for (int i = 1; i < str.length(); i++)
if (str[i] <= 'Z' && str[i] >= 'A') {
temp.push_back(str[i] + 'a' - 'A');
n++;
}
if (n == str.length())
cout << temp << endl;
else
cout << str << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[101];
int i, count = 0;
cin >> str;
for (i = 0; i < strlen(str); i++) {
if (str[i] >= 65 && str[i] <= 90) count++;
}
if (str[0] >= 97 && count == strlen(str) - 1) {
str[0] -= 32;
for (i = 1; i < strlen(str); i++) str[i] += 32;
} else if (count == strlen(str)) {
for (i = 0; i < strlen(str); i++) str[i] += 32;
}
cout << str;
}
| ### Prompt
Please create a solution in CPP to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[101];
int i, count = 0;
cin >> str;
for (i = 0; i < strlen(str); i++) {
if (str[i] >= 65 && str[i] <= 90) count++;
}
if (str[0] >= 97 && count == strlen(str) - 1) {
str[0] -= 32;
for (i = 1; i < strlen(str); i++) str[i] += 32;
} else if (count == strlen(str)) {
for (i = 0; i < strlen(str); i++) str[i] += 32;
}
cout << str;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, len = 0;
char str[1000];
cin >> str;
for (i = 1; i < strlen(str); i++) {
if (str[i] >= 65 && str[i] <= 90) {
len++;
}
}
if (len == strlen(str) - 1) {
for (i = 0; i < strlen(str); i++) {
if (str[i] >= 65 && str[i] <= 90)
str[i] = 97 + str[i] - 65;
else if (str[i] >= 97 && str[i] <= 122)
str[i] = 65 + str[i] - 97;
}
}
cout << str;
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() {
int i, len = 0;
char str[1000];
cin >> str;
for (i = 1; i < strlen(str); i++) {
if (str[i] >= 65 && str[i] <= 90) {
len++;
}
}
if (len == strlen(str) - 1) {
for (i = 0; i < strlen(str); i++) {
if (str[i] >= 65 && str[i] <= 90)
str[i] = 97 + str[i] - 65;
else if (str[i] >= 97 && str[i] <= 122)
str[i] = 65 + str[i] - 97;
}
}
cout << str;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
char s[110];
scanf("%s", s);
int len = strlen(s);
if (len == 1) {
if (s[0] >= 'A' && s[0] <= 'Z')
s[0] = tolower(s[0]);
else
s[0] = toupper(s[0]);
puts(s);
return 0;
}
int acnt = 0, bcnt = 0;
if (s[0] >= 'A' && s[0] <= 'Z') acnt++;
for (int i = 1; i < len; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') acnt++, bcnt++;
}
if (acnt == len) {
for (int i = 0; i < len; i++) s[i] = tolower(s[i]);
} else if (bcnt == len - 1) {
s[0] = toupper(s[0]);
for (int i = 1; i < len; i++) s[i] = tolower(s[i]);
}
puts(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>
int main() {
char s[110];
scanf("%s", s);
int len = strlen(s);
if (len == 1) {
if (s[0] >= 'A' && s[0] <= 'Z')
s[0] = tolower(s[0]);
else
s[0] = toupper(s[0]);
puts(s);
return 0;
}
int acnt = 0, bcnt = 0;
if (s[0] >= 'A' && s[0] <= 'Z') acnt++;
for (int i = 1; i < len; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') acnt++, bcnt++;
}
if (acnt == len) {
for (int i = 0; i < len; i++) s[i] = tolower(s[i]);
} else if (bcnt == len - 1) {
s[0] = toupper(s[0]);
for (int i = 1; i < len; i++) s[i] = tolower(s[i]);
}
puts(s);
}
``` |
#include <bits/stdc++.h>
int main() {
char ch[106];
int i, j, ck = 1;
scanf("%s", ch);
for (i = 1; ch[i] != '\0'; i++) {
if (ch[i] >= 97 && ch[i] <= 122) {
ck = 0;
break;
}
}
if (ck == 1) {
if (ch[0] >= 65 && ch[0] <= 90)
ch[0] = ch[0] + 32;
else
ch[0] = ch[0] - 32;
for (j = 1; ch[j] != '\0'; j++) {
ch[j] = ch[j] + 32;
}
}
printf("%s\n", ch);
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 ch[106];
int i, j, ck = 1;
scanf("%s", ch);
for (i = 1; ch[i] != '\0'; i++) {
if (ch[i] >= 97 && ch[i] <= 122) {
ck = 0;
break;
}
}
if (ck == 1) {
if (ch[0] >= 65 && ch[0] <= 90)
ch[0] = ch[0] + 32;
else
ch[0] = ch[0] - 32;
for (j = 1; ch[j] != '\0'; j++) {
ch[j] = ch[j] + 32;
}
}
printf("%s\n", ch);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (isupper(s[0])) {
string tem;
for (int i = 0; i < s.size(); ++i) {
if (!isupper(s[i])) {
cout << s << '\n';
return 0;
}
tem += tolower(s[i]);
}
cout << tem << '\n';
return 0;
} else {
string tem;
tem += toupper(s[0]);
for (int i = 1; i < s.size(); ++i) {
if (!isupper(s[i])) {
cout << s << '\n';
return 0;
}
tem += tolower(s[i]);
}
cout << tem << '\n';
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;
if (isupper(s[0])) {
string tem;
for (int i = 0; i < s.size(); ++i) {
if (!isupper(s[i])) {
cout << s << '\n';
return 0;
}
tem += tolower(s[i]);
}
cout << tem << '\n';
return 0;
} else {
string tem;
tem += toupper(s[0]);
for (int i = 1; i < s.size(); ++i) {
if (!isupper(s[i])) {
cout << s << '\n';
return 0;
}
tem += tolower(s[i]);
}
cout << tem << '\n';
return 0;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[101];
bool f = 0;
cin >> a;
for (int i = 1; a[i] != NULL; i++) {
if (a[i] >= 'a' && a[i] <= 'z') f = 1;
}
if (f == 0) {
for (int i = 0; a[i] != NULL; i++) {
if (a[i] >= 'A' && a[i] <= 'Z')
a[i] += 'a' - 'A';
else if (a[i] >= 'a' && a[i] <= 'z')
a[i] += 'A' - 'a';
}
}
cout << a << 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() {
char a[101];
bool f = 0;
cin >> a;
for (int i = 1; a[i] != NULL; i++) {
if (a[i] >= 'a' && a[i] <= 'z') f = 1;
}
if (f == 0) {
for (int i = 0; a[i] != NULL; i++) {
if (a[i] >= 'A' && a[i] <= 'Z')
a[i] += 'a' - 'A';
else if (a[i] >= 'a' && a[i] <= 'z')
a[i] += 'A' - 'a';
}
}
cout << a << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int flag = 1;
char s[101];
scanf("%s", s);
for (int i = 1; i < strlen(s); i++) {
if (islower(s[i])) {
flag = 0;
}
}
if (flag == 0)
printf("%s", s);
else {
if (isupper(s[0]))
s[0] = tolower(s[0]);
else
s[0] = toupper(s[0]);
for (int i = 1; i < strlen(s); i++) s[i] = tolower(s[i]);
printf("%s", s);
}
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() {
int flag = 1;
char s[101];
scanf("%s", s);
for (int i = 1; i < strlen(s); i++) {
if (islower(s[i])) {
flag = 0;
}
}
if (flag == 0)
printf("%s", s);
else {
if (isupper(s[0]))
s[0] = tolower(s[0]);
else
s[0] = toupper(s[0]);
for (int i = 1; i < strlen(s); i++) s[i] = tolower(s[i]);
printf("%s", s);
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool ch = true;
for (int i = 1; i < s.size(); i++) {
if (toupper(s[i]) != s[i]) {
ch = false;
break;
}
}
if (ch) {
for (int i = 1; i < s.size(); i++) {
s[i] = tolower(s[i]);
}
if (s[0] == toupper(s[0]))
s[0] = tolower(s[0]);
else
s[0] = toupper(s[0]);
}
cout << s << endl;
return 0;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool ch = true;
for (int i = 1; i < s.size(); i++) {
if (toupper(s[i]) != s[i]) {
ch = false;
break;
}
}
if (ch) {
for (int i = 1; i < s.size(); i++) {
s[i] = tolower(s[i]);
}
if (s[0] == toupper(s[0]))
s[0] = tolower(s[0]);
else
s[0] = toupper(s[0]);
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int i, n = s.length();
int k = 0;
for (i = 1; i < n; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
k = k + 1;
}
}
if (k == 0) {
for (i = 0; i < n; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
s[i] = s[i] - 32;
} else {
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;
int main() {
string s;
cin >> s;
int i, n = s.length();
int k = 0;
for (i = 1; i < n; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
k = k + 1;
}
}
if (k == 0) {
for (i = 0; i < n; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
s[i] = s[i] - 32;
} else {
s[i] = s[i] + 32;
}
}
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
string s;
cin >> s;
int temp, x;
temp = 1;
x = 0;
if (s.length() == 1) {
if ((int)s[0] > 93) x = 1;
} else {
for (int i(1); i < s.length(); i++) {
if ((int)s[i] > 93) temp = 0;
}
}
if (x == 1 || temp == 1) {
for (int i(0); i < s.length(); i++) {
if ((int)s[i] < 93)
s[i] = (char)((int)s[i] + 32);
else
s[i] = (char)((int)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() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
string s;
cin >> s;
int temp, x;
temp = 1;
x = 0;
if (s.length() == 1) {
if ((int)s[0] > 93) x = 1;
} else {
for (int i(1); i < s.length(); i++) {
if ((int)s[i] > 93) temp = 0;
}
}
if (x == 1 || temp == 1) {
for (int i(0); i < s.length(); i++) {
if ((int)s[i] < 93)
s[i] = (char)((int)s[i] + 32);
else
s[i] = (char)((int)s[i] - 32);
}
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int l = 0, u = 0;
char input[120];
scanf("%s", &input);
for (int i = 0; i < strlen(input); i++) {
if (islower(input[i]) != 0)
l++;
else
u++;
}
if (l == 1 && !u)
printf("%c", toupper(input[0]));
else if (l == 1 && u && islower(input[0]))
for (int j = 0; j < strlen(input); j++) {
if (islower(input[j]) != 0)
printf("%c", toupper(input[j]));
else
printf("%c", tolower(input[j]));
}
else if (!l)
for (int j = 0; j < strlen(input); j++) {
printf("%c", tolower(input[j]));
}
else
printf("%s", 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() {
int l = 0, u = 0;
char input[120];
scanf("%s", &input);
for (int i = 0; i < strlen(input); i++) {
if (islower(input[i]) != 0)
l++;
else
u++;
}
if (l == 1 && !u)
printf("%c", toupper(input[0]));
else if (l == 1 && u && islower(input[0]))
for (int j = 0; j < strlen(input); j++) {
if (islower(input[j]) != 0)
printf("%c", toupper(input[j]));
else
printf("%c", tolower(input[j]));
}
else if (!l)
for (int j = 0; j < strlen(input); j++) {
printf("%c", tolower(input[j]));
}
else
printf("%s", input);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int xuli() {
string s;
cin >> s;
for (int i = 1; i < s.size(); i++)
if (s[i] >= 97) {
for (int i = 0; i < s.size(); i++) cout << s[i];
return 0;
}
if (s[0] >= 97)
s[0] -= 32;
else
s[0] += 32;
for (int i = 1; i < s.size(); i++)
if (s[i] < 97) s[i] += 32;
for (int i = 0; i < s.size(); i++) cout << s[i];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
xuli();
}
| ### 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 xuli() {
string s;
cin >> s;
for (int i = 1; i < s.size(); i++)
if (s[i] >= 97) {
for (int i = 0; i < s.size(); i++) cout << s[i];
return 0;
}
if (s[0] >= 97)
s[0] -= 32;
else
s[0] += 32;
for (int i = 1; i < s.size(); i++)
if (s[i] < 97) s[i] += 32;
for (int i = 0; i < s.size(); i++) cout << s[i];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
xuli();
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
while (getline(cin, s)) {
int n = s.length();
int count = 0;
for (int i = 1; i < s.length(); i++) {
if (s[i] >= 65 && s[i] <= 90) count++;
}
if (count != (n - 1))
cout << s << endl;
else {
transform(s.begin() + 1, s.end(), s.begin() + 1, ::tolower);
if (s[0] >= 65 && s[0] <= 90)
s[0] = s[0] + 32;
else if (s[0] >= 97 && s[0] <= 122)
s[0] = s[0] - 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;
while (getline(cin, s)) {
int n = s.length();
int count = 0;
for (int i = 1; i < s.length(); i++) {
if (s[i] >= 65 && s[i] <= 90) count++;
}
if (count != (n - 1))
cout << s << endl;
else {
transform(s.begin() + 1, s.end(), s.begin() + 1, ::tolower);
if (s[0] >= 65 && s[0] <= 90)
s[0] = s[0] + 32;
else if (s[0] >= 97 && s[0] <= 122)
s[0] = s[0] - 32;
cout << s << endl;
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int m = 0;
for (int i = 1; i < s.size(); i++) {
if (s[i] >= 65 and s[i] <= 91) {
m++;
}
}
if (m == s.size() - 1) {
if (s[0] >= 97 and s[0] <= 123) {
s[0] -= 32;
} else if (s[0] >= 65 and s[0] <= 91) {
s[0] += 32;
}
for (int i = 1; i < s.size(); i++) {
if (s[i] >= 65 and s[i] <= 91) {
s[i] += 32;
}
}
for (int i = 0; i < s.size(); i++) {
cout << s[i];
}
} else {
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;
int main() {
string s;
cin >> s;
int m = 0;
for (int i = 1; i < s.size(); i++) {
if (s[i] >= 65 and s[i] <= 91) {
m++;
}
}
if (m == s.size() - 1) {
if (s[0] >= 97 and s[0] <= 123) {
s[0] -= 32;
} else if (s[0] >= 65 and s[0] <= 91) {
s[0] += 32;
}
for (int i = 1; i < s.size(); i++) {
if (s[i] >= 65 and s[i] <= 91) {
s[i] += 32;
}
}
for (int i = 0; i < s.size(); i++) {
cout << s[i];
}
} else {
cout << s;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int a, c, n, m;
string s;
int main() {
string s;
cin >> s;
int d = 0;
for (int i = 0; i < s.size(); i++)
if (i > 0 && islower(s[i])) d = 1;
if (d == 1) {
cout << s;
return 0;
}
for (int i = 0; i < s.size(); i++) {
if (isupper(s[i]))
cout << (char)tolower(s[i]);
else
cout << (char)toupper(s[i]);
}
}
| ### 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 a, c, n, m;
string s;
int main() {
string s;
cin >> s;
int d = 0;
for (int i = 0; i < s.size(); i++)
if (i > 0 && islower(s[i])) d = 1;
if (d == 1) {
cout << s;
return 0;
}
for (int i = 0; i < s.size(); i++) {
if (isupper(s[i]))
cout << (char)tolower(s[i]);
else
cout << (char)toupper(s[i]);
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
bool is = true;
string s;
cin >> s;
if (isupper(s[0])) {
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
is = false;
break;
}
}
} else {
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
is = false;
break;
}
}
}
if (is == true)
for (int i = 0; i < s.length(); i++) {
if (isupper(s[i]))
s[i] += 32;
else
s[i] -= 32;
}
{}
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;
int main() {
bool is = true;
string s;
cin >> s;
if (isupper(s[0])) {
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
is = false;
break;
}
}
} else {
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
is = false;
break;
}
}
}
if (is == true)
for (int i = 0; i < s.length(); i++) {
if (isupper(s[i]))
s[i] += 32;
else
s[i] -= 32;
}
{}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
char s[200];
int i, count = 0, l;
scanf("%s", s);
l = strlen(s);
for (i = 0; s[i]; i++) {
if (s[i] >= 65 && s[i] <= 90) {
count++;
}
}
if (l == count) {
for (i = 0; s[i]; i++) printf("%c", s[i] + 32);
} else if (s[0] >= 97 && count == l - 1) {
printf("%c", s[0] - 32);
for (i = 1; s[i]; i++) printf("%c", s[i] + 32);
} else {
printf("%s", s);
}
return 0;
}
| ### Prompt
Generate a cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
int main() {
char s[200];
int i, count = 0, l;
scanf("%s", s);
l = strlen(s);
for (i = 0; s[i]; i++) {
if (s[i] >= 65 && s[i] <= 90) {
count++;
}
}
if (l == count) {
for (i = 0; s[i]; i++) printf("%c", s[i] + 32);
} else if (s[0] >= 97 && count == l - 1) {
printf("%c", s[0] - 32);
for (i = 1; s[i]; i++) printf("%c", s[i] + 32);
} else {
printf("%s", s);
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int a;
for (int i = 1; i < s.size(); i++) {
a = s[i];
if (a > 90) {
cout << s;
return 0;
}
}
a = s[0];
if (a > 90) {
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;
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 a;
for (int i = 1; i < s.size(); i++) {
a = s[i];
if (a > 90) {
cout << s;
return 0;
}
}
a = s[0];
if (a > 90) {
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;
return 0;
}
``` |
#include <bits/stdc++.h>
char string[100];
void do_change_string(int first_char_is_high, int is_remain) {
int i, j, temp;
char criteria = 'a';
int char_offset = 'a' - 'A';
if (first_char_is_high + is_remain == is_remain + 1) {
i = 0;
j = is_remain + 1;
} else if (!first_char_is_high && is_remain != 0) {
i = 0;
j = is_remain + 1;
} else {
i = 0;
j = 1;
}
do {
temp = (int)string[i];
if (string[i] < criteria)
string[i] = (char)(temp + char_offset);
else
string[i] = (char)(temp - char_offset);
} while (++i < j);
}
int main(void) {
int length;
int uppercase_num;
int first_char_is_high;
int i;
length = uppercase_num = first_char_is_high = i = 0;
memset(string, 0x0, sizeof(string));
scanf("%s", string);
length = strlen(string);
if ((string[0] < 'a')) {
first_char_is_high = 1;
}
for (i = 1; i < length; i++) {
if ((string[i] < 'a')) uppercase_num++;
}
if (first_char_is_high && (uppercase_num == length - 1))
do_change_string(first_char_is_high, uppercase_num);
else if (!first_char_is_high && (uppercase_num == length - 1))
do_change_string(first_char_is_high, uppercase_num);
else if (!first_char_is_high && length == 1)
do_change_string(first_char_is_high, uppercase_num);
printf("%s\n", string);
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>
char string[100];
void do_change_string(int first_char_is_high, int is_remain) {
int i, j, temp;
char criteria = 'a';
int char_offset = 'a' - 'A';
if (first_char_is_high + is_remain == is_remain + 1) {
i = 0;
j = is_remain + 1;
} else if (!first_char_is_high && is_remain != 0) {
i = 0;
j = is_remain + 1;
} else {
i = 0;
j = 1;
}
do {
temp = (int)string[i];
if (string[i] < criteria)
string[i] = (char)(temp + char_offset);
else
string[i] = (char)(temp - char_offset);
} while (++i < j);
}
int main(void) {
int length;
int uppercase_num;
int first_char_is_high;
int i;
length = uppercase_num = first_char_is_high = i = 0;
memset(string, 0x0, sizeof(string));
scanf("%s", string);
length = strlen(string);
if ((string[0] < 'a')) {
first_char_is_high = 1;
}
for (i = 1; i < length; i++) {
if ((string[i] < 'a')) uppercase_num++;
}
if (first_char_is_high && (uppercase_num == length - 1))
do_change_string(first_char_is_high, uppercase_num);
else if (!first_char_is_high && (uppercase_num == length - 1))
do_change_string(first_char_is_high, uppercase_num);
else if (!first_char_is_high && length == 1)
do_change_string(first_char_is_high, uppercase_num);
printf("%s\n", string);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[100];
int i, l = 0;
cin >> str;
for (i = 1; i < strlen(str); i++) {
if (str[i] >= 'A' && str[i] <= 'Z') l++;
}
if (l == strlen(str) - 1) {
for (i = 0; i < strlen(str); i++) {
if (str[i] >= 'A' && str[i] <= 'Z')
str[i] = str[i] + 32;
else
str[i] = str[i] - 32;
}
}
cout << str << endl;
}
| ### Prompt
Create a solution in cpp for the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[100];
int i, l = 0;
cin >> str;
for (i = 1; i < strlen(str); i++) {
if (str[i] >= 'A' && str[i] <= 'Z') l++;
}
if (l == strlen(str) - 1) {
for (i = 0; i < strlen(str); i++) {
if (str[i] >= 'A' && str[i] <= 'Z')
str[i] = str[i] + 32;
else
str[i] = str[i] - 32;
}
}
cout << str << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int i, cnt = 0;
cin >> s;
for (i = 0; i < s.size(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
cnt++;
}
}
if (cnt == s.size() ||
((s[0] >= 'a' && s[0] <= 'z') && cnt == s.size() - 1)) {
for (i = 0; i < s.size(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
s[i] = s[i] + 32;
} else {
s[i] = s[i] - 32;
}
}
cout << s;
} else {
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;
int i, cnt = 0;
cin >> s;
for (i = 0; i < s.size(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
cnt++;
}
}
if (cnt == s.size() ||
((s[0] >= 'a' && s[0] <= 'z') && cnt == s.size() - 1)) {
for (i = 0; i < s.size(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
s[i] = s[i] + 32;
} else {
s[i] = s[i] - 32;
}
}
cout << s;
} else {
cout << s;
}
}
``` |
#include <bits/stdc++.h>
const long long OO = 1e9 + 7;
using namespace std;
string s;
int d1 = 0, d2 = 0;
void kurumi() {
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] - 0 >= 65 && s[i] - 0 <= 90)
d1++;
else
d2++;
}
if ((d2 == 1 && s[0] - 0 >= 95 && s[0] - 0 <= 122) || d1 == s.size()) {
for (int i = 0; i < s.size(); i++) {
if (s[i] - 0 >= 65 && s[i] - 0 <= 90)
s[i] += 32;
else
s[i] -= 32;
}
}
cout << s;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
kurumi();
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>
const long long OO = 1e9 + 7;
using namespace std;
string s;
int d1 = 0, d2 = 0;
void kurumi() {
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] - 0 >= 65 && s[i] - 0 <= 90)
d1++;
else
d2++;
}
if ((d2 == 1 && s[0] - 0 >= 95 && s[0] - 0 <= 122) || d1 == s.size()) {
for (int i = 0; i < s.size(); i++) {
if (s[i] - 0 >= 65 && s[i] - 0 <= 90)
s[i] += 32;
else
s[i] -= 32;
}
}
cout << s;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
kurumi();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool change = true;
for (int i = 1; i < s.length(); ++i) {
if (s[i] >= 'a') {
change = false;
break;
}
}
if (change) {
for (int i = 0; i < s.length(); ++i) {
if (s[i] >= 'a') {
s[i] -= ('a' - 'A');
} else {
s[i] += ('a' - 'A');
}
}
}
cout << s << endl;
return 0;
}
| ### Prompt
Your 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 change = true;
for (int i = 1; i < s.length(); ++i) {
if (s[i] >= 'a') {
change = false;
break;
}
}
if (change) {
for (int i = 0; i < s.length(); ++i) {
if (s[i] >= 'a') {
s[i] -= ('a' - 'A');
} else {
s[i] += ('a' - 'A');
}
}
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
char a[111];
int i, l;
int flag1, flag2;
while (gets(a) != NULL) {
l = strlen(a);
flag2 = 0;
if (a[0] >= 'A' && a[0] <= 'Z')
flag1 = 1;
else
flag1 = 0;
for (i = 1; i < l; i++) {
if (a[i] >= 'a' && a[i] <= 'z') {
flag2 = 1;
break;
}
}
if (flag2)
puts(a);
else {
if (flag1) {
a[0] += 'a' - 'A';
} else {
a[0] += 'A' - 'a';
}
for (i = 1; i < l; i++) a[i] += 'a' - 'A';
puts(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>
int main() {
char a[111];
int i, l;
int flag1, flag2;
while (gets(a) != NULL) {
l = strlen(a);
flag2 = 0;
if (a[0] >= 'A' && a[0] <= 'Z')
flag1 = 1;
else
flag1 = 0;
for (i = 1; i < l; i++) {
if (a[i] >= 'a' && a[i] <= 'z') {
flag2 = 1;
break;
}
}
if (flag2)
puts(a);
else {
if (flag1) {
a[0] += 'a' - 'A';
} else {
a[0] += 'A' - 'a';
}
for (i = 1; i < l; i++) a[i] += 'a' - 'A';
puts(a);
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int acc = 1;
for (int i = 1; i < s.length(); i++) {
if (s[i] > 96) {
acc = 0;
break;
}
}
if (acc) {
cout << ((s[0] < 91) ? char(s[0] + 32) : char(s[0] - 32));
for (int i = 1; i < s.length(); i++) {
cout << char(s[i] + 32);
}
return 0;
}
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 acc = 1;
for (int i = 1; i < s.length(); i++) {
if (s[i] > 96) {
acc = 0;
break;
}
}
if (acc) {
cout << ((s[0] < 91) ? char(s[0] + 32) : char(s[0] - 32));
for (int i = 1; i < s.length(); i++) {
cout << char(s[i] + 32);
}
return 0;
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
int cnt = 0;
cin >> str;
int len = str.length();
for (int i = 0; i < len; ++i) {
if (str[i] >= 'A' && str[i] <= 'Z') cnt++;
}
if (cnt == len) {
for (int i = 0; i < len; ++i) {
putchar(str[i] - 'A' + 'a');
}
cout << endl;
} else if (str[0] >= 'a' && str[0] <= 'z' && cnt == len - 1) {
putchar(str[0] - 'a' + 'A');
for (int i = 1; i < len; ++i) {
putchar(str[i] - 'A' + 'a');
}
cout << endl;
} else {
cout << str << 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 str;
int cnt = 0;
cin >> str;
int len = str.length();
for (int i = 0; i < len; ++i) {
if (str[i] >= 'A' && str[i] <= 'Z') cnt++;
}
if (cnt == len) {
for (int i = 0; i < len; ++i) {
putchar(str[i] - 'A' + 'a');
}
cout << endl;
} else if (str[0] >= 'a' && str[0] <= 'z' && cnt == len - 1) {
putchar(str[0] - 'a' + 'A');
for (int i = 1; i < len; ++i) {
putchar(str[i] - 'A' + 'a');
}
cout << endl;
} else {
cout << str << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool mayus(string s) {
for (int i = 0; i < s.size(); i++)
if (toupper(s[i]) != s[i]) return false;
return true;
}
bool mayus2(string s) {
for (int i = 1; i < s.size(); i++)
if (toupper(s[i]) != s[i]) return false;
return true;
}
int main() {
string s;
getline(cin, s);
if (s.size() == 0) {
if (tolower(s[0]) == s[0])
printf("%c\n", toupper(s[0]));
else
printf("%c\n", s[0]);
} else if (mayus(s)) {
for (int i = 0; i < s.size(); i++) printf("%c", tolower(s[i]));
printf("\n");
} else if (mayus2(s)) {
printf("%c", toupper(s[0]));
for (int i = 1; i < s.size(); i++) printf("%c", tolower(s[i]));
printf("\n");
} else
cout << s << endl;
}
| ### Prompt
Create a solution in cpp for the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool mayus(string s) {
for (int i = 0; i < s.size(); i++)
if (toupper(s[i]) != s[i]) return false;
return true;
}
bool mayus2(string s) {
for (int i = 1; i < s.size(); i++)
if (toupper(s[i]) != s[i]) return false;
return true;
}
int main() {
string s;
getline(cin, s);
if (s.size() == 0) {
if (tolower(s[0]) == s[0])
printf("%c\n", toupper(s[0]));
else
printf("%c\n", s[0]);
} else if (mayus(s)) {
for (int i = 0; i < s.size(); i++) printf("%c", tolower(s[i]));
printf("\n");
} else if (mayus2(s)) {
printf("%c", toupper(s[0]));
for (int i = 1; i < s.size(); i++) printf("%c", tolower(s[i]));
printf("\n");
} else
cout << s << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string word;
int x = 0;
int y = 0;
while (cin >> word) {
if (isupper(word[0])) {
for (int i = 0; i < word.length(); i++) {
if (isupper(word[i])) {
x++;
}
}
if (x == word.length()) {
for (int i = 0; i < word.length(); i++) {
word[i] = tolower(word[i]);
}
}
cout << word << endl;
x = 0;
word = "";
}
if (islower(word[0])) {
if (word.length() == 1) {
word[0] = toupper(word[0]);
}
for (int i = 1; i < word.length(); i++) {
if (isupper(word[i])) {
y++;
}
}
if (y == word.length() - 1) {
for (int i = 1; i < word.length(); i++) {
word[0] = toupper(word[0]);
word[i] = tolower(word[i]);
}
}
cout << word << endl;
y = 0;
word = "";
}
}
}
| ### 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 word;
int x = 0;
int y = 0;
while (cin >> word) {
if (isupper(word[0])) {
for (int i = 0; i < word.length(); i++) {
if (isupper(word[i])) {
x++;
}
}
if (x == word.length()) {
for (int i = 0; i < word.length(); i++) {
word[i] = tolower(word[i]);
}
}
cout << word << endl;
x = 0;
word = "";
}
if (islower(word[0])) {
if (word.length() == 1) {
word[0] = toupper(word[0]);
}
for (int i = 1; i < word.length(); i++) {
if (isupper(word[i])) {
y++;
}
}
if (y == word.length() - 1) {
for (int i = 1; i < word.length(); i++) {
word[0] = toupper(word[0]);
word[i] = tolower(word[i]);
}
}
cout << word << endl;
y = 0;
word = "";
}
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
string fixCaps(string str) {
string res;
for (int i = 1; i < str.size(); i++) {
if (str[i] >= 65 && str[i] <= 90) {
res += (char)(str[i] + 32);
} else {
return str;
}
}
if (str[0] >= 65 && str[0] <= 90) {
res = (char)(str[0] + 32) + res;
} else {
res = (char)(str[0] - 32) + res;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string str;
cin >> str;
cout << fixCaps(str) << 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;
string fixCaps(string str) {
string res;
for (int i = 1; i < str.size(); i++) {
if (str[i] >= 65 && str[i] <= 90) {
res += (char)(str[i] + 32);
} else {
return str;
}
}
if (str[0] >= 65 && str[0] <= 90) {
res = (char)(str[0] + 32) + res;
} else {
res = (char)(str[0] - 32) + res;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string str;
cin >> str;
cout << fixCaps(str) << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string qq(string s) {
for (long long i = 0; i < s.size(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
s[i] = (char)(s[i] - 'A' + 'a');
} else {
s[i] = (char)(s[i] - 'a' + 'A');
}
}
return s;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
bool check = true;
for (long long i = 1; i < s.size(); i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
check = false;
}
}
if (check) {
s = qq(s);
}
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 qq(string s) {
for (long long i = 0; i < s.size(); i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
s[i] = (char)(s[i] - 'A' + 'a');
} else {
s[i] = (char)(s[i] - 'a' + 'A');
}
}
return s;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
bool check = true;
for (long long i = 1; i < s.size(); i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
check = false;
}
}
if (check) {
s = qq(s);
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s;
cin >> s;
long long n = s.size();
long long u = 0, l = 0;
for (long long i = 0; i < n; i++) {
if (s[i] >= 'A' and s[i] <= 'Z')
u++;
else
l++;
}
if (n == 1) {
if (u)
cout << char(tolower(s[0])) << "\n";
else
cout << char(toupper(s[0])) << "\n";
} else if (u == n) {
for (long long i = 0; i < n; i++) cout << char(tolower(s[i]));
cout << "\n";
} else if (s[0] >= 'a' and s[0] <= 'z' and u == n - 1) {
cout << char(toupper(s[0]));
for (long long i = 1; i < n; i++) cout << char(tolower(s[i]));
cout << "\n";
} else
cout << s << "\n";
}
int32_t main() {
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
};
solve();
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;
void solve() {
string s;
cin >> s;
long long n = s.size();
long long u = 0, l = 0;
for (long long i = 0; i < n; i++) {
if (s[i] >= 'A' and s[i] <= 'Z')
u++;
else
l++;
}
if (n == 1) {
if (u)
cout << char(tolower(s[0])) << "\n";
else
cout << char(toupper(s[0])) << "\n";
} else if (u == n) {
for (long long i = 0; i < n; i++) cout << char(tolower(s[i]));
cout << "\n";
} else if (s[0] >= 'a' and s[0] <= 'z' and u == n - 1) {
cout << char(toupper(s[0]));
for (long long i = 1; i < n; i++) cout << char(tolower(s[i]));
cout << "\n";
} else
cout << s << "\n";
}
int32_t main() {
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
};
solve();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string input;
cin >> input;
string output;
if (isupper(input[0])) {
output.push_back(tolower(input[0]));
} else {
output.push_back(toupper(input[0]));
}
for (int i = 1; i < input.length(); ++i) {
if (isupper(input[i])) {
output.push_back(tolower(input[i]));
} else {
cout << input;
return 0;
}
}
cout << output;
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 input;
cin >> input;
string output;
if (isupper(input[0])) {
output.push_back(tolower(input[0]));
} else {
output.push_back(toupper(input[0]));
}
for (int i = 1; i < input.length(); ++i) {
if (isupper(input[i])) {
output.push_back(tolower(input[i]));
} else {
cout << input;
return 0;
}
}
cout << output;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool c = true;
for (int i = 1; i < s.size(); ++i)
if (s[i] > 91) {
c = false;
break;
}
if (char(s[0] > 91) && c) {
s[0] = s[0] - ' ';
for (int i = 1; i < s.size(); ++i) s[i] = s[i] + ' ';
} else if (char(s[0] < 91) && c) {
for (int i = 0; i < s.size(); ++i) s[i] = s[i] + ' ';
}
cout << s;
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool c = true;
for (int i = 1; i < s.size(); ++i)
if (s[i] > 91) {
c = false;
break;
}
if (char(s[0] > 91) && c) {
s[0] = s[0] - ' ';
for (int i = 1; i < s.size(); ++i) s[i] = s[i] + ' ';
} else if (char(s[0] < 91) && c) {
for (int i = 0; i < s.size(); ++i) s[i] = s[i] + ' ';
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int i, j, k, l, m, n, c = 5;
char ara[1000];
scanf("%[^\n]", ara);
l = strlen(ara);
for (i = 1; i < l; i++) {
if (ara[i] >= 'a' && ara[i] <= 'z') {
c = 10;
break;
}
}
if (c == 5) {
for (i = 1; i < l; i++) {
ara[i] += 32;
}
if ((ara[0] >= 'a' && ara[0] <= 'z'))
ara[0] -= 32;
else
ara[0] += 32;
}
printf("%s\n", ara);
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int i, j, k, l, m, n, c = 5;
char ara[1000];
scanf("%[^\n]", ara);
l = strlen(ara);
for (i = 1; i < l; i++) {
if (ara[i] >= 'a' && ara[i] <= 'z') {
c = 10;
break;
}
}
if (c == 5) {
for (i = 1; i < l; i++) {
ara[i] += 32;
}
if ((ara[0] >= 'a' && ara[0] <= 'z'))
ara[0] -= 32;
else
ara[0] += 32;
}
printf("%s\n", ara);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int i, j, x, flag = 0;
cin >> s;
x = s.length();
if (x == 1 && (s[0] >= 'a' && s[0] <= 'z')) {
s[0] = s[0] - 32;
cout << s;
} else if (x == 1 && (s[0] >= 'A' && s[0] <= 'Z')) {
s[0] = s[0] + 32;
cout << s;
}
if (x > 1) {
for (i = 0; i < x; i++) {
flag = 0;
if (s[i] >= 'A' && s[i] <= 'Z') {
flag = 1;
} else {
flag = 0;
break;
}
}
if (flag != 1) {
for (i = 0; i < x - 1; i++) {
if ((s[0] >= 'a' && s[0] <= 'z') &&
(s[i + 1] >= 'A' && s[i + 1] <= 'Z')) {
flag = 2;
} else {
flag = 0;
break;
}
}
}
if (flag == 0) {
cout << s;
}
if (flag == 1) {
for (i = 0; i < x; i++) {
s[i] = s[i] + 32;
}
cout << s;
}
if (flag == 2) {
s[0] = s[0] - 32;
for (i = 0; i < x - 1; i++) {
s[i + 1] = s[i + 1] + 32;
}
cout << s;
}
}
}
| ### Prompt
Please formulate a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int i, j, x, flag = 0;
cin >> s;
x = s.length();
if (x == 1 && (s[0] >= 'a' && s[0] <= 'z')) {
s[0] = s[0] - 32;
cout << s;
} else if (x == 1 && (s[0] >= 'A' && s[0] <= 'Z')) {
s[0] = s[0] + 32;
cout << s;
}
if (x > 1) {
for (i = 0; i < x; i++) {
flag = 0;
if (s[i] >= 'A' && s[i] <= 'Z') {
flag = 1;
} else {
flag = 0;
break;
}
}
if (flag != 1) {
for (i = 0; i < x - 1; i++) {
if ((s[0] >= 'a' && s[0] <= 'z') &&
(s[i + 1] >= 'A' && s[i + 1] <= 'Z')) {
flag = 2;
} else {
flag = 0;
break;
}
}
}
if (flag == 0) {
cout << s;
}
if (flag == 1) {
for (i = 0; i < x; i++) {
s[i] = s[i] + 32;
}
cout << s;
}
if (flag == 2) {
s[0] = s[0] - 32;
for (i = 0; i < x - 1; i++) {
s[i + 1] = s[i + 1] + 32;
}
cout << s;
}
}
}
``` |
#include <bits/stdc++.h>
int main() {
char w[101];
int i, len, flag = 0, flag1 = 0;
scanf("%s", w);
len = strlen(w);
if (islower(w[0])) flag1 = 1;
for (i = 1; i < len; i++)
if (islower(w[i])) {
flag++;
flag1 = 1;
}
if (flag == 0 && flag1 == 1) {
if (islower(w[0])) w[0] = toupper(w[0]);
for (i = 1; i < len; i++) {
if (isupper(w[i])) w[i] = tolower(w[i]);
}
}
if (flag1 == 0)
for (i = 0; i < len; i++) w[i] = tolower(w[i]);
printf("%s\n", w);
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 w[101];
int i, len, flag = 0, flag1 = 0;
scanf("%s", w);
len = strlen(w);
if (islower(w[0])) flag1 = 1;
for (i = 1; i < len; i++)
if (islower(w[i])) {
flag++;
flag1 = 1;
}
if (flag == 0 && flag1 == 1) {
if (islower(w[0])) w[0] = toupper(w[0]);
for (i = 1; i < len; i++) {
if (isupper(w[i])) w[i] = tolower(w[i]);
}
}
if (flag1 == 0)
for (i = 0; i < len; i++) w[i] = tolower(w[i]);
printf("%s\n", w);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string FixedString(string s) {
string str = "";
for (int i = 0; i < s.length(); i++) {
if (islower(s[i]))
str += toupper(s[i]);
else
str += tolower(s[i]);
}
return str;
}
int main() {
string s;
cin >> s;
if (islower(s[0])) {
bool fail = false;
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
fail = true;
break;
}
}
if (fail == false) {
cout << FixedString(s) << endl;
return 0;
}
}
bool f = false;
for (int i = 0; i < s.length(); i++) {
if (islower(s[i])) {
f = true;
break;
}
}
if (f == false) {
cout << FixedString(s) << endl;
return 0;
}
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;
string FixedString(string s) {
string str = "";
for (int i = 0; i < s.length(); i++) {
if (islower(s[i]))
str += toupper(s[i]);
else
str += tolower(s[i]);
}
return str;
}
int main() {
string s;
cin >> s;
if (islower(s[0])) {
bool fail = false;
for (int i = 1; i < s.length(); i++) {
if (islower(s[i])) {
fail = true;
break;
}
}
if (fail == false) {
cout << FixedString(s) << endl;
return 0;
}
}
bool f = false;
for (int i = 0; i < s.length(); i++) {
if (islower(s[i])) {
f = true;
break;
}
}
if (f == false) {
cout << FixedString(s) << endl;
return 0;
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, l = 0;
string s;
cin >> s;
for (i = 1; i < s.size(); i++)
if (s[i] >= 65 && s[i] <= 90) l++;
if (l == s.size() - 1) {
for (i = 0; i < s.size(); i++) {
if (s[i] >= 65 && s[i] <= 90)
s[i] = s[i] + 32;
else if (s[i] >= 97 && s[i] <= 122)
s[i] = s[i] - 32;
}
}
cout << s << endl;
return 0;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, l = 0;
string s;
cin >> s;
for (i = 1; i < s.size(); i++)
if (s[i] >= 65 && s[i] <= 90) l++;
if (l == s.size() - 1) {
for (i = 0; i < s.size(); i++) {
if (s[i] >= 65 && s[i] <= 90)
s[i] = s[i] + 32;
else if (s[i] >= 97 && s[i] <= 122)
s[i] = s[i] - 32;
}
}
cout << s << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string s;
void ReadInput() { cin >> s; }
bool check(string s) {
for (int i = 1; i < s.size(); i++) {
if (s[i] >= 97) return false;
}
return true;
}
void Solve() {
if (check(s)) {
for (int i = 0; i < s.size(); i++) {
if (s[i] < 97)
s[i] += 32;
else
s[i] -= 32;
}
}
cout << s;
}
int main() {
ReadInput();
Solve();
}
| ### 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;
void ReadInput() { cin >> s; }
bool check(string s) {
for (int i = 1; i < s.size(); i++) {
if (s[i] >= 97) return false;
}
return true;
}
void Solve() {
if (check(s)) {
for (int i = 0; i < s.size(); i++) {
if (s[i] < 97)
s[i] += 32;
else
s[i] -= 32;
}
}
cout << s;
}
int main() {
ReadInput();
Solve();
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
int t = 0;
getline(cin, a);
for (int i = 0; i < a.length(); i++) {
if (a[i] >= 97 && i != 0) {
t = 1;
}
}
if (t == 1)
cout << a;
else {
for (int i = 0; i < a.length(); i++) {
a[i] ^= 32;
}
cout << a;
}
}
| ### Prompt
In CPP, your task is to solve the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
int t = 0;
getline(cin, a);
for (int i = 0; i < a.length(); i++) {
if (a[i] >= 97 && i != 0) {
t = 1;
}
}
if (t == 1)
cout << a;
else {
for (int i = 0; i < a.length(); i++) {
a[i] ^= 32;
}
cout << a;
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e, f, g, h, i, j, k;
string A;
ios::sync_with_stdio(false);
cin.tie(0);
getline(cin, A);
a = A.length();
d = 1;
for (b = 1; b < a; b++) {
c = A[b];
if (c >= 65 and c <= 90)
continue;
else {
d = 0;
break;
}
}
if (d == 1) {
for (b = 0; b < a; b++) {
e = A[b];
if (e >= 65 and e <= 90)
e += 32;
else if (b == 0 and e >= 97 and e <= 122)
e -= 32;
A[b] = e;
}
}
cout << A << 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() {
int a, b, c, d, e, f, g, h, i, j, k;
string A;
ios::sync_with_stdio(false);
cin.tie(0);
getline(cin, A);
a = A.length();
d = 1;
for (b = 1; b < a; b++) {
c = A[b];
if (c >= 65 and c <= 90)
continue;
else {
d = 0;
break;
}
}
if (d == 1) {
for (b = 0; b < a; b++) {
e = A[b];
if (e >= 65 and e <= 90)
e += 32;
else if (b == 0 and e >= 97 and e <= 122)
e -= 32;
A[b] = e;
}
}
cout << A << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
cin >> a;
bool flag = true;
for (int i = 1; i < a.length(); i++) {
if (islower(a[i])) {
flag = 0;
}
if (!flag) {
break;
}
}
if (!flag && a.length() > 1) {
cout << a;
} else {
for (int i = 0; i < a.length(); i++) {
if (islower(a[i])) {
cout << char(toupper(a[i]));
} else {
cout << char(tolower(a[i]));
}
}
}
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
cin >> a;
bool flag = true;
for (int i = 1; i < a.length(); i++) {
if (islower(a[i])) {
flag = 0;
}
if (!flag) {
break;
}
}
if (!flag && a.length() > 1) {
cout << a;
} else {
for (int i = 0; i < a.length(); i++) {
if (islower(a[i])) {
cout << char(toupper(a[i]));
} else {
cout << char(tolower(a[i]));
}
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[101];
int i;
int flag;
scanf("%s", &a);
flag = 0;
if (a[1] == '\0') {
if (a[0] >= 'a' && a[0] <= 'z') {
a[0] = a[0] - 32;
} else if (a[0] >= 'A' && a[0] <= 'Z') {
a[0] = a[0] + 32;
}
printf("%c\n", a[0]);
} else {
for (i = 1; a[i] != '\0'; i++) {
if (a[i] >= 'A' && a[i] <= 'Z') {
continue;
} else {
flag = 1;
break;
}
}
if (flag == 1) {
printf("%s\n", a);
} else {
for (i = 0; a[i] != '\0'; 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;
}
printf("%c", a[i]);
}
printf("\n");
}
}
return 0;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[101];
int i;
int flag;
scanf("%s", &a);
flag = 0;
if (a[1] == '\0') {
if (a[0] >= 'a' && a[0] <= 'z') {
a[0] = a[0] - 32;
} else if (a[0] >= 'A' && a[0] <= 'Z') {
a[0] = a[0] + 32;
}
printf("%c\n", a[0]);
} else {
for (i = 1; a[i] != '\0'; i++) {
if (a[i] >= 'A' && a[i] <= 'Z') {
continue;
} else {
flag = 1;
break;
}
}
if (flag == 1) {
printf("%s\n", a);
} else {
for (i = 0; a[i] != '\0'; 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;
}
printf("%c", a[i]);
}
printf("\n");
}
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int l = s.length();
bool p = false, q = false;
for (int i = 0; i < l; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
p = true;
break;
}
}
if (s[0] >= 'a' && s[0] <= 'z') {
q = true;
}
bool z = false;
if (q == true) {
for (int i = 1; i < l; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
z = true;
break;
}
}
}
if (p == false || q == true && z == false) {
for (int i = 0; i < l; i++) {
if (s[i] >= 'A' && s[i] <= 'Z')
s[i] = s[i] + 32;
else
s[i] = s[i] - 32;
}
cout << s;
} else
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 l = s.length();
bool p = false, q = false;
for (int i = 0; i < l; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
p = true;
break;
}
}
if (s[0] >= 'a' && s[0] <= 'z') {
q = true;
}
bool z = false;
if (q == true) {
for (int i = 1; i < l; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
z = true;
break;
}
}
}
if (p == false || q == true && z == false) {
for (int i = 0; i < l; i++) {
if (s[i] >= 'A' && s[i] <= 'Z')
s[i] = s[i] + 32;
else
s[i] = s[i] - 32;
}
cout << s;
} else
cout << s;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
const long double EPS = 1e-10;
const int MAX = 1000 * 1000;
const int MOD = 1000;
int main() {
string s, gl = "aoyeui", ans = "";
cin >> s;
int n = int(s.length());
bool is_caps = true;
for (int i = 1; i < n; i++) {
if ('A' > s[i] || s[i] > 'Z') {
is_caps = false;
break;
}
}
if (is_caps) {
for (int i = 0; i < n; i++) {
s[i] >= 'a' ? s[i] = char(int(s[i]) - 32) : s[i] = char(int(s[i]) + 32);
}
}
cout << s;
}
| ### Prompt
Please create a solution in cpp to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
const long double EPS = 1e-10;
const int MAX = 1000 * 1000;
const int MOD = 1000;
int main() {
string s, gl = "aoyeui", ans = "";
cin >> s;
int n = int(s.length());
bool is_caps = true;
for (int i = 1; i < n; i++) {
if ('A' > s[i] || s[i] > 'Z') {
is_caps = false;
break;
}
}
if (is_caps) {
for (int i = 0; i < n; i++) {
s[i] >= 'a' ? s[i] = char(int(s[i]) - 32) : s[i] = char(int(s[i]) + 32);
}
}
cout << s;
}
``` |
#include <bits/stdc++.h>
int main() {
int i;
char st[101] = {'\0'};
scanf("%s", st);
for (int i = 1; st[i] != '\0'; i++) {
if (st[i] >= 'a' && st[i] <= 'z') {
printf("%s", st);
return 0;
}
}
for (int i = 0; st[i] != '\0'; i++) printf("%c", st[i] ^ 32);
}
| ### 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;
char st[101] = {'\0'};
scanf("%s", st);
for (int i = 1; st[i] != '\0'; i++) {
if (st[i] >= 'a' && st[i] <= 'z') {
printf("%s", st);
return 0;
}
}
for (int i = 0; st[i] != '\0'; i++) printf("%c", st[i] ^ 32);
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
char ar[100];
int len, count = 0, i, j;
gets(ar);
len = strlen(ar);
if (isupper(ar[0]) && islower(ar[1])) {
cout << ar;
} else {
for (i = 0; ar[i] != '\0'; i++) {
if (isupper(ar[i])) {
count++;
}
}
if (len == 1) {
if (islower(ar[0])) {
ar[0] = toupper(ar[0]);
} else if (isupper(ar[0])) {
ar[0] = tolower(ar[0]);
}
} else if (count == len) {
for (i = 0; ar[i] != '\0'; i++) {
ar[i] = tolower(ar[i]);
}
} else if (count == len - 1) {
if (islower(ar[0])) {
for (i = 1; ar[i] != '\0'; i++) {
ar[i] = tolower(ar[i]);
ar[0] = toupper(ar[0]);
}
}
}
cout << ar;
}
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 ar[100];
int len, count = 0, i, j;
gets(ar);
len = strlen(ar);
if (isupper(ar[0]) && islower(ar[1])) {
cout << ar;
} else {
for (i = 0; ar[i] != '\0'; i++) {
if (isupper(ar[i])) {
count++;
}
}
if (len == 1) {
if (islower(ar[0])) {
ar[0] = toupper(ar[0]);
} else if (isupper(ar[0])) {
ar[0] = tolower(ar[0]);
}
} else if (count == len) {
for (i = 0; ar[i] != '\0'; i++) {
ar[i] = tolower(ar[i]);
}
} else if (count == len - 1) {
if (islower(ar[0])) {
for (i = 1; ar[i] != '\0'; i++) {
ar[i] = tolower(ar[i]);
ar[0] = toupper(ar[0]);
}
}
}
cout << ar;
}
return 0;
}
``` |
#include <bits/stdc++.h>
int main() {
int i, flag = 1;
char s[105];
scanf("%s", &s);
for (i = 1; i < strlen(s); i++) {
if (s[i] >= 97) {
flag = 0;
break;
}
}
if (flag) {
for (i = 0; i < strlen(s); i++) {
if (s[i] < 97) {
s[i] = s[i] + 32;
} else {
s[i] = s[i] - 32;
}
}
}
printf("%s", s);
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int i, flag = 1;
char s[105];
scanf("%s", &s);
for (i = 1; i < strlen(s); i++) {
if (s[i] >= 97) {
flag = 0;
break;
}
}
if (flag) {
for (i = 0; i < strlen(s); i++) {
if (s[i] < 97) {
s[i] = s[i] + 32;
} else {
s[i] = s[i] - 32;
}
}
}
printf("%s", s);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int cl = 0, cu = 0;
for (int i = 0; i < s.length(); i++) {
if (isupper(s[i]))
cu++;
else
cl++;
}
if (cl == 0) {
for (int i = 0; i < s.length(); i++) s[i] = tolower(s[i]);
} else if (cl == 1 && cu == s.length() - 1 && islower(s[0])) {
s[0] = toupper(s[0]);
for (int i = 1; i < s.length(); i++) s[i] = tolower(s[i]);
}
cout << s;
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int cl = 0, cu = 0;
for (int i = 0; i < s.length(); i++) {
if (isupper(s[i]))
cu++;
else
cl++;
}
if (cl == 0) {
for (int i = 0; i < s.length(); i++) s[i] = tolower(s[i]);
} else if (cl == 1 && cu == s.length() - 1 && islower(s[0])) {
s[0] = toupper(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 i, j, k, a, b, c, n, t, f, d;
string s, v;
map<char, int> ma, sa;
vector<int> vv;
map<char, int>::iterator it, ki;
cin >> s;
f = 0;
c = 0;
for (j = 0; j < s.size(); j++) {
if ((s[j] >= 'A' && s[j] <= 'Z')) {
c++;
}
}
if (c == s.size()) {
for (j = 0; j < s.size(); j++) {
cout << char(s[j] + 32);
}
cout << endl;
} else if (s[0] >= 'a' && s[0] <= 'z' && c == s.size() - 1) {
cout << char(s[0] - 32);
for (j = 1; j < s.size(); j++) {
cout << char(s[j] + 32);
}
cout << endl;
} else {
cout << s << endl;
}
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentally switched on, if:
* either it only contains uppercase letters;
* or all letters except for the first one are uppercase.
In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed.
Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
Input
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Output
Print the result of the given word's processing.
Examples
Input
cAPS
Output
Caps
Input
Lock
Output
Lock
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, a, b, c, n, t, f, d;
string s, v;
map<char, int> ma, sa;
vector<int> vv;
map<char, int>::iterator it, ki;
cin >> s;
f = 0;
c = 0;
for (j = 0; j < s.size(); j++) {
if ((s[j] >= 'A' && s[j] <= 'Z')) {
c++;
}
}
if (c == s.size()) {
for (j = 0; j < s.size(); j++) {
cout << char(s[j] + 32);
}
cout << endl;
} else if (s[0] >= 'a' && s[0] <= 'z' && c == s.size() - 1) {
cout << char(s[0] - 32);
for (j = 1; j < s.size(); j++) {
cout << char(s[j] + 32);
}
cout << endl;
} else {
cout << s << endl;
}
return 0;
}
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.