Advertisement
adityagupta1089

wordlist results

Oct 17th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. (Wrong Answer:, see below for the correct answer too)
  2. Problem: WORDLIST
  3. State: Wrong Answer
  4. Total score for this submission: 0
  5. Your code compiled successfully but produced the following warnings
  6.  
  7. Test Case #0 for 2 points
  8. Wrong Answer
  9. Runtime: 0.152
  10. Test Case #1 for 2 points
  11. Wrong Answer
  12. Runtime: 0.176
  13. Test Case #2 for 2 points
  14. Wrong Answer
  15. Runtime: 0.232
  16. Test Case #3 for 2 points
  17. Wrong Answer
  18. Runtime: 0.224
  19. Test Case #4 for 2 points
  20. Wrong Answer
  21. Runtime: 0.572
  22. Test Case #5 for 2 points
  23. Wrong Answer
  24. Runtime: 0.56
  25. Test Case #6 for 2 points
  26. Wrong Answer
  27. Runtime: 0.492
  28. Test Case #7 for 2 points
  29. Wrong Answer
  30. Runtime: 1.1
  31. Test Case #8 for 2 points
  32. Wrong Answer
  33. Runtime: 1.152
  34. Test Case #9 for 2 points
  35. Wrong Answer
  36. Runtime: 1.724
  37.  
  38. import java.util.ArrayList;
  39. import java.util.Collections;
  40. import java.util.Scanner;
  41.  
  42. /**
  43. * Created by aditya on 14-10-2014.
  44. */
  45. public class Main {
  46.  
  47. public static void main(String args[]) {
  48.  
  49. Scanner scan = new Scanner(System.in);
  50. int n = Integer.parseInt(scan.nextLine());
  51. ArrayList<String> lines = new ArrayList<String>();
  52. ArrayList<String> words = new ArrayList<String>();
  53. boolean once_entered = true;
  54. for (int i = 0; i < n; i++) {
  55. lines.add(i, scan.nextLine() + " ");
  56. }
  57. for (int i = 0; i < n; i++) {
  58. String word = "";
  59. for (int j = 0; j < lines.get(i).length(); j++) {
  60. char char_0 = lines.get(i).toLowerCase().charAt(j);
  61. if ((int) (char_0) >= (int) ('a') && (int) (char_0) <= (int) ('z')) {
  62. word += char_0;
  63. once_entered = false;
  64. } else if (!once_entered) {
  65. words.add(word);
  66. word = "";
  67. once_entered = true;
  68. }
  69. }
  70. }
  71. for (int i = 0; i < words.size(); i++) {
  72. for (int j = 0; j < words.size(); j++) {
  73. if (i == j) continue;
  74. else if (words.get(i).equals(words.get(j))) {
  75. words.remove(words.get(j));
  76. }
  77. }
  78. }
  79. Collections.sort(words);
  80. System.out.println(words.size());
  81. for (int i = 0; i < words.size(); i++) {
  82. System.out.println(words.get(i));
  83. }
  84. }
  85. }
  86.  
  87. (Correct Answer:)
  88. Problem: WORDLIST
  89. State: Accepted
  90. Total score for this submission: 20
  91. Test Case #0 for 2 points
  92. Correct Answer
  93. Runtime: 0.156
  94. Test Case #1 for 2 points
  95. Correct Answer
  96. Runtime: 0.16
  97. Test Case #2 for 2 points
  98. Correct Answer
  99. Runtime: 0.212
  100. Test Case #3 for 2 points
  101. Correct Answer
  102. Runtime: 0.204
  103. Test Case #4 for 2 points
  104. Correct Answer
  105. Runtime: 0.524
  106. Test Case #5 for 2 points
  107. Correct Answer
  108. Runtime: 0.444
  109. Test Case #6 for 2 points
  110. Correct Answer
  111. Runtime: 0.456
  112. Test Case #7 for 2 points
  113. Correct Answer
  114. Runtime: 1.096
  115. Test Case #8 for 2 points
  116. Correct Answer
  117. Runtime: 1.54
  118. Test Case #9 for 2 points
  119. Correct Answer
  120. Runtime: 1.636
  121.  
  122. import java.util.ArrayList;
  123. import java.util.Collections;
  124. import java.util.Scanner;
  125.  
  126. /**
  127. * Created by aditya on 14-10-2014.
  128. */
  129. public class Main {
  130.  
  131. public static void main(String args[]) {
  132.  
  133. Scanner scan = new Scanner(System.in);
  134. int n = Integer.parseInt(scan.nextLine());
  135. ArrayList<String> lines = new ArrayList<String>();
  136. ArrayList<String> words = new ArrayList<String>();
  137. ArrayList<String> words_2 = new ArrayList<String>();
  138. boolean once_entered = true;
  139. for (int i = 0; i < n; i++) {
  140. lines.add(i, scan.nextLine() + " ");
  141. }
  142. for (int i = 0; i < n; i++) {
  143. String word = "";
  144. for (int j = 0; j < lines.get(i).length(); j++) {
  145. char char_0 = lines.get(i).toLowerCase().charAt(j);
  146. if ( (char_0) >= ('a') && (char_0) <= ('z')) {
  147. word += char_0;
  148. once_entered = false;
  149. } else if (!once_entered) {
  150. words.add(word);
  151. word = "";
  152. once_entered = true;
  153. }
  154. }
  155. }
  156. for (int i = 0; i < words.size(); i++) {
  157. boolean contains =false;
  158. for(int j=0;j<words_2.size();j++){
  159. if(words_2.get(j).contentEquals(words.get(i)))
  160. contains=true;
  161. }
  162. if(!contains)
  163. words_2.add(words.get(i));
  164. }
  165. Collections.sort(words_2);
  166. System.out.println(words_2.size());
  167. for (int i = 0; i < words_2.size(); i++) {
  168. System.out.println(words_2.get(i));
  169. }
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement