当前位置:网站首页>Huawei od computer test question 2
Huawei od computer test question 2
2022-07-06 05:16:00 【Dream youhuang】
Simple difficulty
1.HJ11 The numbers are upside down
describe
Enter an integer , Output this integer in reverse order as a string
The program does not consider negative numbers , If the number contains 0, Then the reverse form also contains 0, If the input is 100, The output of 001
Data range : 0 \ n \ 2^{30}-1 \0≤n≤230−1
Input description :
Enter a int Integers
Output description :
Output this integer in reverse order as a string
Example 1
Input :
1516000
Output :
0006151
Example 2
Input :
0
Output :
0
Sample code :
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.nextLine();
StringBuffer strb = new StringBuffer(str);
strb.reverse();
System.out.println(strb.toString());
}
}
summary :
The following is the syntax of this method -
public StringBuffer reverse()
Return value
- This method returns
StringBuffer
object
2.HJ22 Water bottle
describe
There is such an intellectual problem :“ Regulations of a store : Three empty water bottles can be replaced by one soda . There are ten empty water bottles on Xiao Zhang's hand , How many bottles of soda can she change at most ?” The answer is 5 bottle , The method is as follows : First use 9 Empty bottle change 3 Bottle of soda , Drink up 3 Bottle full , After drinking 4 Empty bottles , use 3 One for another , Drink the full bottle , This is the time left 2 Empty bottles . Then you ask the boss to lend you a soda , Drink the full bottle , Use after drinking 3 Change an empty bottle for a full one and give it back to the boss . If Xiaozhang has n Empty water bottle , How many bottles of soda can I change at most ?
Data range : The positive integer entered satisfies 1 n 100 \1≤n≤100
Be careful : There are multiple sets of inputs for this question .
Allow to borrow soda from the boss as described in the question .
Input 0 Only indicates the 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.
Example 1
Input :
3 10 81 0
Output :
1 5 40
explain :
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 a bottle of soda from the boss. After drinking three empty bottles, change one bottle of soda and return it to the boss
solution : Want to change the most soda , Be cheeky , Borrow a bottle of soda from the boss every two empty bottles , After drinking, take three empty bottles and exchange one for the boss ; Equivalent to one bottle of soda for every two empty bottles
Core code bottle/2
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNextInt()){
int bottle = sc.nextInt();
if(bottle==0){
break;
}
System.out.println(bottle/2);
}
}
}
边栏推荐
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- In 2022, we must enter the big factory as soon as possible
- Postman assertion
- Compilation et connexion de shader dans games202 - webgl (comprendre la direction)
- 剑指 Offer II 039. 直方图最大矩形面积
- Sliding window problem review
- [lgr-109] Luogu may race II & windy round 6
- ISP learning (2)
- Postman manage test cases
- Excel转换为Lua的配置文件
猜你喜欢
Codeforces Round #804 (Div. 2) Editorial(A-B)
Modbus协议通信异常
Can the feelings of Xi'an version of "Coca Cola" and Bingfeng beverage rush for IPO continue?
pix2pix:使用条件对抗网络的图像到图像转换
Principle and performance analysis of lepton lossless compression
[classic example] binary tree recursive structure classic topic collection @ binary tree
The underlying structure of five data types in redis
指針經典筆試題
Yyds dry inventory SSH Remote Connection introduction
Three methods of Oracle two table Association update
随机推荐
【LGR-109】洛谷 5 月月赛 II & Windy Round 6
yolov5 tensorrt加速
Nacos - TC Construction of High available seata (02)
Flody的应用
Unity Vector3. Use and calculation principle of reflect
C# AES对字符串进行加密
你需要知道的 TCP 三次握手
RT thread analysis - object container implementation and function
Sliding window problem review
Excel转换为Lua的配置文件
Nestjs配置文件上传, 配置中间件以及管道的使用
Postman manage test cases
【OSPF 和 ISIS 在多路访问网络中对掩码的要求】
February 12 relativelayout
Ora-01779: the column corresponding to the non key value saving table cannot be modified
Pagoda configuration mongodb
Rce code and Command Execution Vulnerability
Huawei equipment is configured with OSPF and BFD linkage
Vite configures the development environment and production environment
flutter 实现一个有加载动画的按钮(loadingButton)