当前位置:网站首页>喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水
喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水
2020-11-08 12:56:00 【osc_51airx3z】
第一种方法
#include<stdio.h>
#include<Windows.h>
#pragma warning(disable:4996)
int Qishui(int n)
{
int total = 0;
total += n;
for (; n >= 2;n=n/2+n%2)
{
total += n / 2;
}
return total;
}
int main()
{
int money = 0;
printf("你有多少钱:");
scanf_s("%d", &money);
int ret = Qishui(money);
printf("可以买%d瓶汽水\n", ret);
system("pause");
return 0;
}
第二种方法
#include<stdio.h>
#include<Windows.h>
#pragma warning(disable:4996)
int Qishui(int money)
{
int total = money;
int empty = money;
while (empty > 1)
{
total += empty / 2;
empty = empty / 2 + empty % 2;
}
return total;
}
int main()
{
int money = 0;
printf("你有多少钱:");
scanf_s("%d", &money);
int ret = Qishui(money);
printf("可以买%d瓶汽水\n", ret);
system("pause");
return 0;
}
版权声明
本文为[osc_51airx3z]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4263556/blog/4708158
边栏推荐
- 用科技赋能教育创新与重构 华为将教育信息化落到实处
- Flink从入门到真香(6、Flink实现UDF函数-实现更细粒度的控制流)
- 学习小结(关于深度学习、视觉和学习体会)
- Adobe media encoder /Me 2021软件安装包(附安装教程)
- 211考研失败后,熬夜了两个月拿下字节offer!【面经分享】
- Istio traffic management -- progress gateway
- Entry level! Teach you how to develop small programs without asking for help (with internet disk link)
- Harbor项目高手问答及赠书活动
- Research on WLAN direct connection (peer-to-peer connection or P2P) and cross platform research of IOS
- AQS analysis
猜你喜欢

Suitable for C / C + + novice learning some projects, do not give me to miss!

Rust : 性能测试criterion库

Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom

TiDB 性能竞赛 11.02-11.06

Adobe media encoder / me 2021 software installation package (with installation tutorial)

Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom

浅谈单调栈

在51CTO学院Get到PMP证书

阿里撕下电商标签

2天,利用下班后的4小时开发一个测试工具
随机推荐
BCCOIN告诉您:年底最靠谱的投资项目是什么!
On monotonous stack
笔试面试题目:求丢失的猪
虚拟机中安装 macOS 11 big sur
How TCP protocol ensures reliable transmission
Learning summary (about deep learning, vision and learning experience)
应届生年薪35w+ !倒挂老员工,互联网大厂薪资为何越来越高?
What can your cloud server do? What is the purpose of cloud server?
A scheme to improve the memory utilization of flutter
Python Gadgets: code conversion
浅谈单调栈
Ubuntu20.04 access FTP server garbled problem + upload files
当Kubernetes遇到机密计算,看阿里巴巴如何保护容器内数据的安全!(附网盘链接)
YGC问题排查,又让我涨姿势了!
On the confirmation of original data assets
Ubuntu20.04下访问FTP服务器乱码问题+上传文件
来自朋友最近阿里、腾讯、美团等P7级Python开发岗位面试题
Service architecture and transformation optimization process of e-commerce trading platform in mogujie (including ppt)
Understanding design patterns
用 Python 写出来的进度条,竟如此美妙~