题解 | 买橘子

买橘子

https://www.nowcoder.com/practice/73e0552b78474a9086781e47f4e01d73

#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin>>n;
	if(n%8==0){
		cout<<n/8;
		return 0;
	}
	int cnt=0;
	vector<int> a;
	while(n>0){
		if(n%6==0){
			a.push_back(n/6+cnt);
		}
		n=n-8;
		cnt++;
	}
	if(a.size()==0){
		cout<<"-1";
	}
	else{
		cout<<a[a.size()-1];
	}
	return 0;
}

全部评论

相关推荐

明明就不饿:看不懂你到底会啥,什么岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务