当前位置:网站首页>HJ9 提取不重复的整数
HJ9 提取不重复的整数
2022-07-25 22:54:00 【敏敏程序媛】
描述
输入一个 int 型整数,按照从右向左的阅读顺序,返回一个不含重复数字的新的整数。
保证输入的整数最后一位不是 0 。
数据范围: 1 \le n \le 10^{8} \1≤n≤108
输入描述:
输入一个int型整数
输出描述:
按照从右向左的阅读顺序,返回一个不含重复数字的新的整数
示例1
输入:9876673
输出:37689
import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
/**
*Author:向敏
*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();
}
//提取不重复的整数
private static String getInteger(String numStr)
{
StringBuilder builder = new StringBuilder();
HashSet<Character> set = new LinkedHashSet<>();
//把整数倒序输入链表集合中,可以去重
for (int i = numStr.length() - 1; i >= 0;i--)
{
set.add(numStr.charAt(i));
}
//把集合中的整数输入到字符串容器中
for (Character c : set)
{
builder.append(c);
}
//如果第一个字母是0
if (builder.charAt(0) == '0')
{
return builder.substring(1,builder.length());
}
return builder.toString();
}
}边栏推荐
- The fourth experiment nat
- Qt5.12 installation error prompt: c:\qt5.12.11\vcredist\vcredist_ msvc2019_ x86.exe /norestart /q
- [training Day12] min ratio [DFS] [minimum spanning tree]
- Madness. Smbms (supermarket order management system)
- The difference between "= =" and equals
- Severely crack down on illegal we media operators according to law: it is urgent to purify the we media industry
- Oracle query statement summary
- Use of qvariant
- Naming rules of software test pytest pytest the pre and post confitest of use cases Py customized allure report @pytest.mark.parameter() decorator as data-driven
- Summary of common methods of string:
猜你喜欢
![[training day13] travel [violence] [dynamic planning]](/img/ac/dd52771fec20432fd084d8e3cc89e1.png)
[training day13] travel [violence] [dynamic planning]

Hcie is finally in hand, and the road begins

Mysql数据类型

Network Security Learning (16)

Naming rules of software test pytest pytest the pre and post confitest of use cases Py customized allure report @pytest.mark.parameter() decorator as data-driven

Node.js operation database

Dom and events

Examples and points for attention about the use of getchar and scanf

Review of static routing

Deploy flash based websites using Google cloud
随机推荐
QT的Tree View Model示例
Matrixcube unveils the complete distributed storage system matrixkv implemented in 102-300 lines
Node.js operation database
[training day15] paint road [minimum spanning tree]
Summary 1 - deep learning - basic knowledge learning
The fourth experiment nat
Learning orientation today
Interpretation of English terms
Ip--- ia review
我们为什么要推出Getaverse?
Mocha test
JS makes elements get or lose focus
The difference between "rewrite" and "overload"
Extended configuration of static routing in the second experiment
Qt的TQTreeWidget控件
Interview question 17.11. word distance ●●
Solve several common problems
Network security and level protection
Summary of common methods of string:
Simple application of partial labels and selectors