360 笔试题目 c++
824 下午的360笔试题目
(1)
代码:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
string duichen = { 'A', 'H','I', 'M', 'T', 'V', 'W', 'X', 'Y' }; // 定义好对称字符
bool isduichen(char ch) // 判断是否是对称字符
{
bool flag = false;
for (int i = 0; i < duichen.size(); i++)
{
if (ch == duichen[i])
flag = true;
}
return flag;
}
int main()
{
string str;
while (cin >> str) // 不停的读取字符串
{
bool flag;
int i, j;
i = 0;
j = str.size() - 1;
while (i <= j)
{
if (isalpha(str[i]) && isalpha(str[j]))
{
if (str[i] == str[j] && isduichen(str[i]))
{
flag = true;
i++;
j--;
}
else
{
flag = false;
cout << "NO" << endl;
break;
}
}
}
if (flag)
cout << "YES" << endl;
}
return 0;
}
2
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
string duichen = { 'A', 'H','I', 'M', 'T', 'V', 'W', 'X', 'Y' }; // 定义好对称字符
bool isduichen(char ch) // 判断是否是对称字符
{
bool flag = false;
for (int i = 0; i < duichen.size(); i++)
{
if (ch == duichen[i])
flag = true;
}
return flag;
}
int main()
{
string str;
while (cin >> str) // 不停的读取字符串
{
bool flag;
int i, j;
i = 0;
j = str.size() - 1;
while (i <= j)
{
if (isalpha(str[i]) && isalpha(str[j]))
{
if (str[i] == str[j] && isduichen(str[i]))
{
flag = true;
i++;
j--;
}
else
{
flag = false;
cout << "NO" << endl;
break;
}
}
}
if (flag)
cout << "YES" << endl;
}
return 0;
}
2
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int>score;
vector<int>baowu;
int res;
int a, b;
for (int i = 0; i < n; i++) // 获取输入数据
{
cin >> a >> b;
score.push_back(a);
baowu.push_back(b);
}
res = 0;
vector<int>array;
for (int i = 0; i < n; i++)
{
if (baowu[i] == 0)
res += score[i];
else
array.push_back(score[i]); // 存储有宝物的关卡
}
// 类似贪心算法,降序排列,先取最大值,目标是最大
sort(array.rbegin(), array.rend()); // 降序
for (int i = 0; i < array.size(); i++)
{
res = (res + array[i])>res * 2 ? res + array[i] : res * 2;
}
cout << res << endl;
return 0;
}
{
int n;
cin >> n;
vector<int>score;
vector<int>baowu;
int res;
int a, b;
for (int i = 0; i < n; i++) // 获取输入数据
{
cin >> a >> b;
score.push_back(a);
baowu.push_back(b);
}
res = 0;
vector<int>array;
for (int i = 0; i < n; i++)
{
if (baowu[i] == 0)
res += score[i];
else
array.push_back(score[i]); // 存储有宝物的关卡
}
// 类似贪心算法,降序排列,先取最大值,目标是最大
sort(array.rbegin(), array.rend()); // 降序
for (int i = 0; i < array.size(); i++)
{
res = (res + array[i])>res * 2 ? res + array[i] : res * 2;
}
cout << res << endl;
return 0;
}
题目整体不是很难,学到了新的东西,欢迎大家讨论,求offer
明天七夕了,大家都单身吗?🤣🤣🤣