C++小练习

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

class Box
{
private:
	double m_height;
	double m_breadth;
	double m_length;

public:
	void setHeight(double height)
	{
		m_height = height;
	}
	void setBreadth(double breadth)
	{
		m_breadth = breadth;
	}
	void setLength(double length)
	{
		m_length = length;
	}

	double getHeight()
	{
		return m_height;
	}

	double getBreadth()
	{
		return m_breadth;
	}
	double getLength()
	{
		return m_length;
	}
	double getV()
	{
		return m_height * m_length * m_breadth;
	}
};
void swap(int &a, int &b)
{
	int tmp = a;
	a = b;
	b = tmp;
	cout << "after --" << a << b << endl;

}

void reserve(int reverse)
{
	int rev = 0;
	while (reverse != 0)
	{
		if (rev < INT_MIN / 10 || rev > INT_MAX / 10)
		{
			return;
		}
		int digit = reverse % 10;
		reverse /= 10;
		rev = rev * 10 + digit;
	}
	cout << "rev=" << rev << endl;
}
bool isPalindrome(int x)
{
	if (x < 0 || (x % 10 == 0 && x != 0))
	{
		return false;
	}
	int revertedNum = 0;
	while (x > revertedNum)
	{
		revertedNum = revertedNum * 10 + x % 10;
		x /= 10;
	}
	return x == revertedNum || x == revertedNum / 10;
}
string LongestCommonPrefix(std::vector<string>& strs) 
{
	if (strs.empty()) return"";
	const auto p =minmax_element(strs.begin(), strs.end());
	for(int i =0;i<p.first->size();++i)
	{
		if (p.first->at(i) != p.second->at(i))
		{
			return p.first->substr(0, i);
		}
	}
	return *p.first;
}
int main()
{
	Box b;
	b.setHeight(1.00);
	b.setBreadth(2.00);
	b.setLength(3.00);
	int a = 10;
	int x = 20;
	cout << "before ---" << a << x << endl;
	swap(a, x);
	cout << "after2 --" << a << x << endl;
	reserve(321);
	//cout << b.getV();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值