提取不重复的整数

题目描述

输入一个int型整数,按照从右向左的阅读顺序,返回一个不含重复数字的新的整数。

输入描述:

输入一个int型整数

输出描述:

按照从右向左的阅读顺序,返回一个不含重复数字的新的整数

输入例子:
9876673
输出例子:
37689

如果返的整数以0开头,去掉0;

如 intput:1010   output:1

如果为0000,输出0

 

 1 import java.util.*;
 2 
 3 public class Main{
 4     public static void main(String[] args){
 5         Scanner in = new Scanner(System.in);
 6         
 7         while(in.hasNext()){
 8             String s = in.nextLine();
 9             char[] c = s.toCharArray();
10             Set<Character> set = new LinkedHashSet<Character>();//顺序去重输出
11             
12             for(int i= c.length-1;i>=0;i--){
13                 set.add(c[i]);
14             }
15             if(c[s.length()-1]=='0'){
16                 if(set.size()!=1){
17                      set.remove('0');
18                      for(Character ch : set){
19                         System.out.print(ch);
20                     } 
21                 }
22                 else
23                     System.out.println(0);
24             }
25             else
26                 for(Character ch : set){
27                         System.out.print(ch);
28                     }        
29         }
30     }
31 }

测试用例,题中都不说清楚的么 。。



posted @ 2016-08-18 21:31  蛋蛋的守护  阅读(163)  评论(0)    收藏  举报