shenyg 发表于 2017-7-10 15:47:44

输入一个字符串,去掉重复的字符,并按ASCII值排序-华为机试

1 import java.util.Scanner;
2
3 //输入字符串,去掉重复的字符,并按ASSIC码值排序
4 public class quChong {
5
6   public static void main(String arg[]){
7         Scanner cin = new Scanner(System.in);
8         String str = cin.nextLine();
9         char c[] = str.toCharArray();
10         int count=0;
11         int flag=0;
12         for(int i=0;i<c.length-count;i++){
13             char temp;            
14             if(count>i&&flag==1){
15               i=0;
16             }else if(count<=i&&flag==1){
17               i=i-count;
18             }
19             temp = c;
20             flag = 0;
21             for(int j =i+1;j<c.length-count;j++){
22               if(temp==c){            
23                     for(int z =i;z<c.length-count-1;z++){
24                         c=c;
25                     }
26                     count++;
27                     flag=1;
28                     break;
29               }
30             }      
31         }
32         for(int i=0;i<c.length-count;i++){
33             for(int j=0;j<c.length-count-1;j++){
34               char temp;
35               if(c>c){
36                     temp=c;
37                     c=c;
38                     c=temp;
39               }
40             }
41         }
42         for(int i=0;i<c.length-count;i++){
43             System.out.print(c);
44         }
45         
46         
47   }
48 }
  要点:字符串可用部分长度在变化,前面的比较起始位置在变
  测试用例:
  输入:qqqwww1212
输出:12qw
页: [1]
查看完整版本: 输入一个字符串,去掉重复的字符,并按ASCII值排序-华为机试