当前位置:网站首页>Hj9 extract non duplicate integers
Hj9 extract non duplicate integers
2022-07-25 22:58:00 【Min Min, chengxuyuan】
describe
Enter a int Type integer , Read right to left , Returns a new integer with no repeating numbers .
Ensure that the last bit of the input integer is not 0 .
Data range : 1 \le n \le 10^{8} \1≤n≤108
Input description :
Enter a int Type integer
Output description :
Read right to left , Returns a new integer with no repeating numbers
Example 1
Input :9876673
Output :37689
import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
/**
*Author: Xiang min
*Date:2022/07/22 15:22
*/
public class Main
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext())
{
int input = scanner.nextInt();
System.out.println(getInteger(input+""));
}
scanner.close();
}
// Extract non duplicate integers
private static String getInteger(String numStr)
{
StringBuilder builder = new StringBuilder();
HashSet<Character> set = new LinkedHashSet<>();
// Input the integer in reverse order into the linked list set , You can get rid of it
for (int i = numStr.length() - 1; i >= 0;i--)
{
set.add(numStr.charAt(i));
}
// Enter the integers in the set into the string container
for (Character c : set)
{
builder.append(c);
}
// If the first letter is 0
if (builder.charAt(0) == '0')
{
return builder.substring(1,builder.length());
}
return builder.toString();
}
}边栏推荐
- Similarities and differences between equals and "= ="
- CSV intro
- HJ9 提取不重复的整数
- AI首席架构师12-AICA-工业生产过程优化场景下产业落地解析
- 汇编语言与微机原理实验一、实验二、实验三:分支程序设计/循环程序设计/子程序设计
- Use of qvariant
- QT string operation
- Notification(状态栏通知)详解
- Experiment 1, experiment 2 and Experiment 3 of assembly language and microcomputer principle: branch program design / loop program design / subroutine design
- DOM event binding
猜你喜欢
随机推荐
QT operation to solve large amount of duplicate data
Basic knowledge of radar
QT string operation
Recommend short videos every week: more and more smart devices need collaboration, posing a greater challenge to the development of the Internet of things?
Session and cookie, token and storage
HJ7 取近似值
[training day15] paint road [minimum spanning tree]
内存分页与调优,内核与用户空间
How to obtain the cash flow data of advertising services to help analyze the advertising effect?
Why is Google's internal tools not suitable for you?
Network Security Learning (XV) ARP
TFrecord写入与读取
每周推荐短视频:需要协同的智能设备越来越多,给物联网开发提出更大挑战?
【论文笔记】基于在线预测和规划的机器人动态跟踪抓取方法
What is the difference between bio, NiO and AIO?
冯诺依曼体系结构
Day006 select structure (if statement exercise)
Kibana~ the process number cannot be found after kibana is started in the background
Shanghai Second Polytechnic University - Health Daily autocheck
【论文笔记】A Meta-Reinforcement Learning Algorithm for Causal Discovery









