fork download
  1. import java.io.BufferedReader;
  2. import java.io.BufferedWriter;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.io.OutputStreamWriter;
  6. import java.util.HashSet;
  7. import java.util.Set;
  8.  
  9. public class Main {
  10. public static void main(String[] args) throws IOException{
  11.  
  12. String N = rd.readLine();
  13. String[] strs = new String[Integer.parseInt(N)];
  14. boolean[] check = new boolean[Integer.parseInt(N)];
  15.  
  16. for (int i =0; i < Integer.parseInt(N); i++) {
  17. strs[i] = rd.readLine();
  18. }
  19.  
  20. for (int i = 0; i < strs.length; i++) {
  21. boolean ch = true;
  22.  
  23. if (strs[i].length() == 1) {
  24. ch = true;
  25. check[i] = ch;
  26. continue;
  27. }
  28.  
  29. for (int j = 0; j < strs[i].length(); j++) {
  30. Set<Character> p = new HashSet<>();
  31. int index = j;
  32.  
  33. for (int k = j+1; k < strs[i].length(); k++) {
  34. if (p.contains(strs[i].charAt(k))) {
  35. ch = false;
  36. break;
  37. }
  38.  
  39. if (strs[i].charAt(j) != strs[i].charAt(k)) {
  40. p.add(strs[i].charAt(j));
  41. index = k-1;
  42. }
  43. }
  44.  
  45. if (! ch) {
  46. break;
  47. }
  48.  
  49. j = index;
  50. }
  51.  
  52. check[i] = ch;
  53. }
  54.  
  55. int count = 0;
  56.  
  57. for (boolean t : check) {
  58. if (t) {
  59. count++;
  60. }
  61. }
  62.  
  63. wt.write(String.valueOf(count));
  64.  
  65.  
  66. wt.flush();
  67. wt.close();
  68. }
  69. }
Success #stdin #stdout 0.05s 2184192KB
stdin
1
abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbba
stdout
Standard output is empty