输入一个字符串,求出该字符串包含的字符集合,按照字母输入的顺序输出。
数据范围:输入的字符串长度满足 ,且只包含大小写字母,区分大小写。
本题有多组输入
每组数据输入一个字符串,字符串最大长度为100,且只包含字母,不可能为空串,区分大小写。
每组数据一行,按字符串原有的字符顺序,输出字符集合,即重复出现并靠后的字母不输出。
abcqweracb
abcqwer
aaa
a
import java.util.Scanner; import java.util.Arrays; import java.lang.Math; public class Main { public static final int MOD = 26; public static final int[] volume = new int[MOD << 1]; public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { String str = in.nextLine(); Arrays.fill(volume, -1); for (int i = 0, len = str.length(); i < len; i++) { char c = str.charAt(i); int idx = c >= 'A' && c <= 'Z' ? MOD + c - 'A' : c - 'a'; if (volume[idx] == -1) { volume[idx] = i; System.out.printf("%c", c); } } System.out.println(); } in.close(); } }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextLine()){ String str = in.nextLine(); String ret = Func(str); System.out.println(ret); } } public static String Func(String str) { boolean[] arr = new boolean[58]; StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if (arr[ch - 'A'] == false){ stringBuilder.append(ch); arr[ch - 'A'] = true; } } return stringBuilder.toString(); } }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); while(read.hasNext()){ int[] arr = new int[123]; String str = read.nextLine(); for(int i = 0;i < str.length();i++){ arr[str.charAt(i)] += 1; } int j = 0; for(j = 0 ;j < str.length();j++){ if(arr[str.charAt(j)] != 0){ System.out.print(str.charAt(j)); arr[str.charAt(j)]=0;} } System.out.println(); } } }
import java.util.*; public class Main{ public static StringBuffer func(String str) { int[] array = new int[127]; StringBuffer str1=new StringBuffer(); for (int i = 0; i < str.length(); i++) { if(array[str.charAt(i)]==0){ str1.append(str.charAt(i)); } array[str.charAt(i)]++; } return str1; } public static void main(String[] args) { Scanner scan = new Scanner(System.in); while(scan.hasNextLine()) { String str = scan.nextLine(); StringBuffer ret = func(str); System.out.println(ret); } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); while(scan.hasNext()) { String str = scan.nextLine(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if (!sb.toString().contains(ch + "")) { sb.append(ch); } } System.out.println(sb.toString()); } } }
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (input.hasNext()) {
String str = input.nextLine();
if (null == str && str.length() > 100)
return;
//String str = "abcfacg";
String str2 = String.valueOf(str.charAt(0));
for (int i = 0; i < str.length(); i++) {
if (!str2.contains(String.valueOf(str.charAt(i))))
str2 += str.charAt(i);
}
System.out.println(str2);
}
input.close(); }
}
import java.util.*; public class Main{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); while(scan.hasNext()){ String str = scan.nextLine(); StringBuilder sb = new StringBuilder(); for(int i = 0;i <str.length();i++){ char ch = str.charAt(i); if(!sb.toString().contains(ch+"")){ sb.append(ch); } } System.out.println(sb); } } }
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNextLine()){ String str = sc.nextLine(); Set<Character> keys = new HashSet<Character>(); for(int i=0; i<str.length();i++){ char v = str.charAt(i); if(!keys.contains(v)){ System.out.print(v); keys.add(v); } } System.out.println(""); } } }
import java.util.LinkedHashSet; import java.util.Scanner; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()) { String str=sc.next(); String regex="^[A-Za-z]+$"; Matcher matcher=Pattern.compile(regex).matcher(str); boolean flag=matcher.matches(); if(!flag||str.length()>100) { return; } Set<Character> set=new LinkedHashSet<>(); set.clear(); for(int i=0;i<str.length();i++) { char s=str.charAt(i); set.add(s); } StringBuilder sb=new StringBuilder(); for(char s:set) { sb.append(""+s); } System.out.println(sb.toString()); } } }