大大小小笔试题也做了一些了,今天想回忆着将这些题目总结一下。
第一题 字符串排序
输入一个字符串,如abED123**&&%==,将字符串重排序,要求是:
- 数字放在最前面;
- 大写放在第二顺位;
- 小写放在第三顺位;
- 其他字符放在最后。
分析:
这题直接遍历即可,相对容易。
代码如下:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
string s, res;
string s1, s2, s3, s4;
cin >> s;
for (auto x : s) {
if (isdigit(x))
s1.push_back(x);
else if (isupper(x))
s2.push_back(x);
else if (islower(x))
s3.push_back(x);
else
s4.push_back(x);
}
res = s1 + s2 + s3 + s4;
cout << res << endl;
return 0;
}
第二题 字符串排序
{ax+by=cdx+ey=f\left\{\begin{matrix}
ax+by=c & \\
dx+ey=f&
\end{matrix}\right.{ax+by=cdx+ey=f
其中:x>=0,y>=0x>=0,y>=0x>=0,y>=0

求:
ab>0,de<0,c>0,f>0ab>0, de<0,c>0,f>0ab>0,de<0,c>0,f>0,实现函数使得x+yx+yx+y的值最大
#include <iostream>
#include <string>
using namespace std;
float GetMaxXY(int a, int b, int c, int d, int e, int f) {
float t = -a * 1.0 / b;
if (t > -1) return c * 1.0 / a;
else
return ((c * e - b * f) + (a * f - d * c)) * 1.0 / (a * e - d * b);
}
int main()
{
int a, b, c, d, e, f;
float output;
scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
output = GetMaxXY(a, b, c, d, e, f);
printf("%.2f\n", output);
return 0;
}
1万+

被折叠的 条评论
为什么被折叠?



