We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 6: Let's Review
Day 6: Let's Review
+ 0 comments Instructions explicitly state that the solution is to have 2 spaces between the strings. Solution is looking for 1 space between the strings. Please fix.
+ 0 comments Here is my JavaScript solution:
function processData(input) { //Enter your code here let words = input.split('\n').slice(1); for(var i=0;i<words.length;i++){ var word = words[i]; var evenLetters= ''; var oddLetters = ''; for(var j=0;j<word.length;j++){ if(j==0 || j%2==0){ evenLetters += word[j]; }else{ oddLetters += word[j]; } } console.log(evenLetters+' '+oddLetters); } }
+ 0 comments import java.io.; import java.util.;
public class Solution {
public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner scn=new Scanner(System.in); int t=scn.nextInt(); //scn.nextLine(); for(int j=0;j<=t;j++){ String s=scn.next(); String even=""; String odd=""; for(int i=0;i<s.length();i++){ if(i%t==0){ even+=s.charAt(i); //System.out.println(even); } else { odd+=s.charAt(i);}//System.out.println(even+" "+odd); } System.out.println(even+" "+odd); any one check this code i got a reun time expectation i go } }
}
+ 0 comments My code Python 3
n = int(input()) for _ in range(n): s = input() print(s[::2] + ' ' + s[1::2])
+ 1 comment My solution is giving the error (shown below) in hackerrank. However, it's executing fine on my pc.
Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Scanner.java:1585) at Solution.main(Solution.java:14)
Here is my code :-
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); //sc.close(); String[] s = new String[n]; Scanner sc1 = new Scanner(System.in); for(int i = 0 ; i < n ; i++){ s[i]= new String(); s[i] = sc1.nextLine(); } for(int i = 0 ; i < n ; i++){ int l = s[i].length(); for(int j = 0 ; j < l ; j++){ System.out.print(s[i].charAt(j)); j++; } System.out.print(" "); for(int j = 1 ; j < l ; j++){ System.out.print(s[i].charAt(j)); j++; } System.out.println(); } } }
Load more conversations
Sort 3200 Discussions, By:
Please Login in order to post a comment