练习题

大大小小笔试题也做了一些了,今天想回忆着将这些题目总结一下。

第一题 字符串排序

输入一个字符串,如abED123**&&%==,将字符串重排序,要求是:

  1. 数字放在最前面;
  2. 大写放在第二顺位;
  3. 小写放在第三顺位;
  4. 其他字符放在最后。
    分析:
    这题直接遍历即可,相对容易。
    代码如下:
#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;
}

第二题 字符串排序

{ a x + b y = c d x + e y = f \left\{\begin{matrix} ax+by=c & \\ dx+ey=f& \end{matrix}\right. {ax+by=cdx+ey=f
其中: x > = 0 , y > = 0 x>=0,y>=0 x>=0,y>=0
在这里插入图片描述
求:
a b > 0 , d e < 0 , c > 0 , f > 0 ab>0, de<0,c>0,f>0 ab>0,de<0,c>0,f>0,实现函数使得 x + y x+y x+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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

量子孤岛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值