资源限制
时间限制:10.0s 内存限制:256.0MB
问题描述
为库设计新函数DelPack,删除输入字符串中所有的重复元素。不连续的重复元素也要删除。
要求写成函数,函数内部使用指针操作。
样例输入
1223445667889
样例输出
13579
样例输入
else
样例输出
ls
数据规模和约定
字符串数组最大长度为100。
——————————————————————————————————————————————
import java.util.Scanner;
public class Main {
static String str;
static int[] num = new int[10];//统计数字
static int[] low = new int[26];//统计小写字母
static int[] up = new int[26];//统计大写字母
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
str = sc.next();
sc.close();
for(int i = 0;i < str.length();i++) {
char c = str.charAt(i);
if(c >= 'a' && c <= 'z') {
low[c - 'a']++;
}else if(c >= 'A' && c <= 'Z') {
up[c - 'A']++;
}else {
num[c - '0']++;
}
}
StringBuilder sb = new StringBuilder();
for(int i = 0;i < str.length();i++) {
char c = str.charAt(i);
if(c >= 'a' && c <= 'z') {
if(low[c - 'a'] == 1) sb.append(c);
}else if(c >= 'A' && c <= 'Z') {
if(up[c - 'A'] == 1) sb.append(c);
}else {
if(num[c - '0'] == 1) sb.append(c);
}
}
System.out.println(sb.toString());
}
}