当前位置:网站首页>[programming question] water bottle
[programming question] water bottle
2022-04-22 01:49:00 【River University of Technology】
Regulations of a store : Three empty water bottles can be replaced by one soda , Allow to borrow an empty soda bottle from the boss ( But it must be returned ).
Xiao Zhang has n Empty water bottle , She wants to know how many bottles of soda she can drink at most .
Data range : The positive integer entered satisfies
Be careful : There are multiple sets of inputs for this question . Input 0 End of input , You don't have to output the results .
Input description :
The input file contains at most 10 Group test data , One line per data , Contains only a positive integer n( 1<=n<=100 ), Indicates the number of empty water bottles on the small hand .n=0 End of input , Your program should not deal with this line .
Output description :
For each group of test data , Output one line , Indicates the maximum number of soda bottles to drink . If you can't drink a bottle , Output 0.
Input example 1:
3 10 81 0
Output example 1:
1 5 40
Example illustrate 1:
Examples 1 explain : Exchange three empty bottles for a bottle of soda , There is one empty bottle left, and the exchange cannot continue Examples 2 explain : Trade nine empty bottles for three bottles of soda , There are four empty bottles left, and then three empty bottles for a bottle of soda , There are two empty bottles left , Borrow an empty bottle from the boss and then exchange three empty bottles for a bottle of soda. After drinking, one empty bottle will be returned to the boss
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Answer key
// 1. Borrow one empty bottle for every two empty bottles ;
// 2. Three empty bottles in A soda ;
// 3. Return a borrowed empty bottle .
Scanner sc = new Scanner(System.in);
while(true) {
int num = sc.nextInt();
if(num == 0) {
return;
}
System.out.println(num / 2);
}
}
}
#include <cstdio>
using namespace std;
int main() {
int n;
while(true) {
scanf("%d", &n);
if(n == 0) {
break;
}
printf("%d\n", n / 2);
}
return 0;
}
while True:
n = int(input())
if n == 0:
break
print(n // 2)
版权声明
本文为[River University of Technology]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220145286472.html
边栏推荐
- 树莓派4B 8G安装日志(3)——编程环境
- Webrtc video cannot be played. How to add UDP hole drilling program in easycvr?
- mysql实现主从复制/主从同步
- Mysql数据库中时间与当前时间判断
- Android four components interview
- [untitled]
- Learning summary of computer network security technology
- Automatic multiorgan segmentation in thorax CT images using U-net-GAN
- 项目搭建之代码规范化解决方案
- JVM - GC垃圾回收器
猜你喜欢

播放量超2000w,这些高能恰饭视频为什么能被B站用户“反复观看”?
![[Internet of things development notes] smart cloud device transplantation RT thread](/img/fb/8b3568c6f24cd781fbbef6ae829996.png)
[Internet of things development notes] smart cloud device transplantation RT thread

阿里专家原创,自学编程找工作

In depth understanding Construction mode of thread synchronization in. Net (1) user mode construction

How to call the login, playback address and video playback interface of easycvr platform?

Fundamentals lecture 30 Lecture 9 geometric application of univariate function integration

Alibaba Daniel teaches you to write your own Android third-party library. The latest Alibaba Android interview process in 2021

MySQL realizes master-slave replication / master-slave synchronization

Distributed transaction solution

What smart contract? Principle analysis of DAPP contract system customization technology
随机推荐
Enter the Android architecture and understand the analysis of 497 questions in the interview of Android senior engineer
Alibaba Android development specification, senior programmer interview questions
Station B charging | charging more than 1500 a week, Yinfa up is the new dark horse of station B?
经济学人翻译练习4.16期刊——美国国税局
Node target penetration test
【DFS】【剪枝】数独(简单版)
阿里专家原创,自学编程找工作
Cybox target penetration test
Stack and queue
Learning summary of computer network security technology
Transformation of trees, binary trees and forests
In depth understanding Construction mode of thread synchronization in. Net (1) user mode construction
C# 从数据库读取数据, 导出到CSV
Code source daily question div1 (601-607)
互联网使用代理IP有哪些作用?
C# UserControl造成内存泄漏
Appium mobile terminal automated testing -- building a simulator and real machine environment
Code source daily question div1 (301-307)
oracle安装server端
Code source daily question div1 (201-207)