第一题
#include<iostream>
#include<set>#include<string>
using namespace std;
int main() {
set<char> chars{ 'A','H','I','M','O','T','U','V','W','X','Y' };
string s;
while (cin >> s) {
bool isTrue = true;
int left = 0, right = s.size()-1;
while (left <= right) {
if (s[left] != s[right] || chars.find(s[left]) == chars.end()) {
isTrue = false;
break;
}
left++;
right--;
}
if (isTrue) cout << "YES" << endl;
else cout << "NO" << endl;
}
}
第二题
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vec;
long long sum = 0;
while (n--) {
int a, b;
cin >> a >> b;
if (b == 0) sum += a;
else vec.push_back(a);
}
sort(vec.begin(), vec.end());
for (int i = vec.size() - 1; i >= 0; i--) {
if (vec[i] > sum) sum+=vec[i];
else sum *= 2;
}
cout << sum << endl;
}
#include<vector>
#include<algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vec;
long long sum = 0;
while (n--) {
int a, b;
cin >> a >> b;
if (b == 0) sum += a;
else vec.push_back(a);
}
sort(vec.begin(), vec.end());
for (int i = vec.size() - 1; i >= 0; i--) {
if (vec[i] > sum) sum+=vec[i];
else sum *= 2;
}
cout << sum << endl;
}
全部评论
(0) 回帖