当前位置:网站首页>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
StringBufferobject
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 dynamic planning day 16
- UCF (summer team competition II)
- Figure database ongdb release v-1.0.3
- Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
- Postman pre script - global variables and environment variables
- Chip debugging of es8316 of imx8mp
- Cuda11.1 online installation
- Cve-2019-11043 (PHP Remote Code Execution Vulnerability)
- Upload nestjs configuration files, configure the use of middleware and pipelines
- UCF(暑期团队赛二)
猜你喜欢
![[effective Objective-C] - memory management](/img/1e/611aa998486bbac76ac103c3091794.jpg)
[effective Objective-C] - memory management

SQLite add index

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

Weng Kai C language third week 3.1 punch in

nacos-高可用seata之TC搭建(02)

Lepton 无损压缩原理及性能分析

Questions d'examen écrit classiques du pointeur

【OSPF 和 ISIS 在多路访问网络中对掩码的要求】

RT thread analysis - object container implementation and function
随机推荐
Class inheritance in yyds dry inventory C
图论的扩展
2021robocom robot developer competition (Preliminary)
Raspberry pie 3.5-inch white screen display connection
Driver development - hellowdm driver
Huawei equipment is configured with OSPF and BFD linkage
Questions d'examen écrit classiques du pointeur
关于Unity Inspector上的一些常用技巧,一般用于编辑器扩展或者其他
Mongodb basic knowledge summary
Postman Association
EditorUtility.SetDirty在Untiy中的作用以及应用
2021RoboCom机器人开发者大赛(初赛)
2022半年总结
[mask requirements of OSPF and Isis in multi access network]
MySQL advanced learning summary 9: create index, delete index, descending index, and hide index
GAMES202-WebGL中shader的編譯和連接(了解向)
Imperial cms7.5 imitation "D9 download station" software application download website source code
RT thread analysis log system RT_ Kprintf analysis
RT thread analysis - object container implementation and function
[NOIP2008 提高组] 笨小猴