当前位置:网站首页>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);
}
}
}
边栏推荐
- [leetcode daily question] number of enclaves
- 注释、接续、转义等符号
- 饼干(考试版)
- RT thread analysis log system RT_ Kprintf analysis
- Chip debugging of es8316 of imx8mp
- Extension of graph theory
- JS quick start (II)
- Codeforces Round #804 (Div. 2) Editorial(A-B)
- Sorting out the knowledge points of multicast and broadcasting
- nacos-高可用seata之TC搭建(02)
猜你喜欢
随机推荐
Zynq learning notes (3) - partial reconfiguration
Review of double pointer problems
Easy to understand I2C protocol
RT thread analysis - object container implementation and function
Drive development - the first helloddk
Simple understanding of interpreters and compilers
Quelques conseils communs sur l'inspecteur de l'unit é, généralement pour les extensions d'éditeur ou d'autres
Tetris
图数据库ONgDB Release v-1.0.3
[mask requirements of OSPF and Isis in multi access network]
Notes, continuation, escape and other symbols
UCF (2022 summer team competition I)
idea一键导包
In 2022, we must enter the big factory as soon as possible
Talking about the type and function of lens filter
Lepton 无损压缩原理及性能分析
Weng Kai C language third week 3.1 punch in
Microblogging hot search stock selection strategy
ByteDance program yuan teaches you how to brush algorithm questions: I'm not afraid of the interviewer tearing the code
Ad20 is set with through-hole direct connection copper sheet, and the bonding pad is cross connected