+ 1

TEST CASE TROUBLE T__T

import java.util.Scanner; public class DejaVu { public static void main(String[] args) { Scanner input = new Scanner(System.in); String S1 = input.next(); String ABC = "abcdefghijklmnopqrstuvwxyz"; char [] A = S1.toCharArray(); char [] c = ABC.toCharArray(); int [] d= new int[26]; int sum = 0; for (int p=0;p<26;p++){d[p]=0;} for(int i=0; i<S1.length(); i++) {for(int j=0; j<26; j++){ if(A[i]==c[j]){d[j]++; sum+= d[j];} if(d[j]>=2){break;} } } if(sum==A.length){System.out.println("Unique");} else {System.out.println("Deja Vu");} } } My code just through 4/5 test cases, so I can't gain 50 exp as expect. :((( Could someone help me figure out the shot coming, please...

10th Apr 2020, 10:19 AM
Le Hoang Tuan
Le Hoang Tuan - avatar
5 ответов
+ 5
Run this code and check whether this works or not. import java.util.Scanner; public class DejaVu { public static void main(String[] args) { Scanner input = new Scanner(System.in); String S1 = input.next(); String ABC = "abcdefghijklmnopqrstuvwxyz"; char [] A = S1.toCharArray(); char [] c = ABC.toCharArray(); int [] d= new int[26]; int sum = 0; for (int p=0;p<26;p++){d[p]=0;} for(int i=0; i<S1.length(); i++) {for(int j=0; j<26; j++){ if(A[i]==c[j]){d[j]++; sum+= d[j];} if(d[j]>2){break;} } } if(sum==A.length){System.out.print("Unique");} else {System.out.print("Deja Vu");} } }
10th Apr 2020, 10:30 AM
...
+ 3
RnT.Lee you are right Actually I have made one change in code. You can right greater than 2 instead of greater than or equal to 3.
10th Apr 2020, 11:16 AM
...
+ 1
Swapnil OMG, it worked. @@ but I don't get it. What the difference between "counter>=2" and "counter>=3"?? "Repeated" means there are 2 or more of same letter in the input string, isn't it?
10th Apr 2020, 10:55 AM
Le Hoang Tuan
Le Hoang Tuan - avatar
0
maybe you should also take into account capital letters.
10th Apr 2020, 10:39 AM
John Robotane
John Robotane - avatar
0
Super
10th Apr 2020, 5:23 PM
Kalki Is
Kalki Is - avatar