fork download
  1. package seventh;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.InputStreamReader;
  5. import java.util.ArrayList;
  6. import java.util.StringTokenizer;
  7.  
  8. public class main {
  9.  
  10. public static void main(String[] args) throws Exception {
  11. // TODO Auto-generated method stub
  12. solution();
  13. }
  14.  
  15. private static void solution() throws Exception {
  16.  
  17. StringTokenizer st = new StringTokenizer(br.readLine());
  18. int size = Integer.parseInt(st.nextToken());
  19. int count = 1;
  20. while(size != 0) {
  21. System.out.println("Simulation " + count++);
  22. st = new StringTokenizer(st.nextToken(), "!");
  23. ArrayList<Character> cache = new ArrayList<Character>();
  24. while (st.hasMoreTokens()) {
  25. String input = st.nextToken();
  26. for (int i = 0; i < input.length(); ++i) {
  27. if (!cache.contains(input.charAt(i))) {
  28. if (cache.size() < size)
  29. cache.add(input.charAt(i));
  30. else {
  31. cache.remove(0);
  32. cache.add(input.charAt(i));
  33. }
  34. } else {
  35. int index = 0;
  36. for(int x = 0; x < cache.size();++x) {
  37. if(cache.get(x) == input.charAt(i))
  38. index = x;
  39. }
  40. cache.remove(index);
  41. cache.add(input.charAt(i));
  42. }
  43. }
  44. for (int i = 0; i < cache.size(); ++i) {
  45. System.out.print(cache.get(i));
  46. }
  47. System.out.println();
  48. }
  49. st = new StringTokenizer(br.readLine());
  50. size = Integer.parseInt(st.nextToken());
  51. }
  52. }
  53. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
5 ABC!DEAF!B!
3 WXWYZ!YZWYX!XYXY!
5 EIEIO!
0
compilation info
Main.java:8: error: class main is public, should be declared in a file named main.java
public class main {
       ^
1 error
stdout
Standard output is empty