当前位置:网站首页>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);
}
}
}
边栏推荐
- 2021robocom robot developer competition (Preliminary)
- 關於Unity Inspector上的一些常用技巧,一般用於編輯器擴展或者其他
- pix2pix:使用条件对抗网络的图像到图像转换
- [classic example] binary tree recursive structure classic topic collection @ binary tree
- 注释、接续、转义等符号
- Tetris
- GAMES202-WebGL中shader的编译和连接(了解向)
- 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
- Oracle query table index, unique constraint, field
- Mongodb basic knowledge summary
猜你喜欢
[leetcode16] the sum of the nearest three numbers (double pointer)
Three methods of Oracle two table Association update
Excel转换为Lua的配置文件
图论的扩展
Golang -- TCP implements concurrency (server and client)
【OSPF 和 ISIS 在多路访问网络中对掩码的要求】
Cuda11.1 online installation
Hyperledger Fabric2. Some basic concepts of X (1)
pix2pix:使用条件对抗网络的图像到图像转换
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
随机推荐
集合详解之 Map + 面试题
The underlying structure of five data types in redis
Please wait while Jenkins is getting ready to work
On the solution of es8316's audio burst
Using stopwatch to count code time
用StopWatch 统计代码耗时
Principle and performance analysis of lepton lossless compression
Zynq learning notes (3) - partial reconfiguration
Fuzzy -- basic application method of AFL
Unity Vector3. Use and calculation principle of reflect
Force buckle 1189 Maximum number of "balloons"
指針經典筆試題
Three. JS learning - light and shadow (understanding)
A little knowledge of CPU, disk and memory
Ora-01779: the column corresponding to the non key value saving table cannot be modified
Postman manage test cases
GAMES202-WebGL中shader的編譯和連接(了解向)
flutter 实现一个有加载动画的按钮(loadingButton)
浅谈镜头滤镜的类型及作用
Knowledge points of circular structure