0827 360笔试
题1:DNA序列
int minChange(string s1, string s2){
int len = s1.size();
int res = 0;
int a1 = 0, a2 = 0;
for (int i = 0; i < len; i++){
if (s1[i] == 'A') a1++;
if (s2[i] == 'A') a2++;
}
int dif = abs(a1 - a2);//需要修改多少个字符
res += dif;
int cur = 0;
for (int i = 0; i < len; i++){
if (s1[i] != s2[i]) {
if (dif-->0) continue;
else cur++;
}
}
res += cur / 2;
return res;
} 题2:不及格的小A
string check(unordered_set<string>& zy, unordered_set<string>& wy, unordered_set<string>& by, string s){
vector<string> vec;
istringstream in(s);
string tmp;
while (getline(in, tmp, ' ')){
vec.push_back(tmp);
}
bool hasZy=false,hasWy = false;//记录有没有主语谓语
for (int i = 0; i < vec.size(); i++){
string cur = vec[i];
if (i == 0 && zy.count(cur) == 0) return "NO";//没有主语
else hasZy = true;
if (wy.count(cur) != 0) {
if (hasWy) return "NO"; //如果谓语不止一个
hasWy = true;
}
}
if (!hasWy) return "NO";//没有谓语
return "YES";
}
输入输出省略了
SHEIN希音公司福利 222人发布
查看8道真题和解析