华为2014机试题,压缩字符

来源:互联网 发布:mysql文件的编码 编辑:程序博客网 时间:2024/05/16 10:39

import java.util.Scanner;
public class StringFilter {
public static void main(String[]args){
  Scanner sc=new Scanner(System.in);
  String str=sc.nextLine();
  char[] ch=str.toCharArray();
  char[] rech=new char[ch.length];
  rech[0]=ch[0];
  int count=0;
  for(int i=1;i<ch.length;i++){
 boolean flag=true;
 for(int j=0;j<=count;j++){
 if(ch[i]==rech[j]){
 flag=false;
 }
 
 }
 if(flag){
 count++;
 rech[count]=ch[i];
 }
  }
  for(int j=0;j<=count;j++){
 System.out.print(rech[j]);
  }
  }
}

0 0