Skip to main content

Posts

FIND THE NO OF SUBSTRINGS DIVISIBLE BY 7 --> INPUT -3567 OUTPUT-4 -->(35,56,567,7)

/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { Scanner input = new Scanner(System.in); String number = input.nextLine(); String sub; int length=number.length(); int i=0; for(int first=0;first<length;first++) { for(int second=first+1;second<=length;second++) { sub = number.substring(first,second); int a = Integer.parseInt(sub); if((a%7)==0) { i++; } } } System.out.println(i); } }

SWAP EACH CONSECUTIVE PAIRS UNTIL THERE IS NO PAIR and THEN REVERSE THE VOWELS ---> INPUT:-NAGIEM OUTPUT:-ENIGMA

/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*;a /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { Scanner input = new Scanner(System.in); String s = input.nextLine(); char[] sCharArray = s.toCharArray(); char[] newWordArray = new char[sCharArray.length]; char temp; int firstletter=0; int secondletter=1; int length = sCharArray.length; for(int i=0,n=length/2;i<n;i++) { temp= sCharArray[firstletter]; sCharArray[firstletter]=sCharArray[secondletter]; sCharArray[secondletter]=temp; firstletter=firstletter+2; secondletter=secondletter+2; } String news = new String(sCharArray); System.out.println(news); int j=0; for(int i=0,n=sCharArray.length;i<n;i++) { if(Character.toLowerCase(sCharArray[i])=='a'||Character.toLowe...

Seating Arrangement

Akash  and  Vishal  are quite fond of travelling. They mostly travel by railways. They were travelling in a train one day and they got interested in the seating arrangement of their compartment. The compartment looked something like So they got interested to know the seat number facing them and the seat type facing them. The seats are denoted as follows : Window Seat :  WS Middle Seat :  MS Aisle Seat :  AS You will be given a seat number, find out the seat number facing you and the seat type, i.e.  WS ,  MS  or  AS . INPUT First line of input will consist of a single integer  T  denoting number of test-cases. Each test-case consists of a single integer  N  denoting the seat-number. OUTPUT For each test case, print the facing seat-number and the seat-type, separated by a single space in a new line. CONSTRAINTS 1<= T <=10 5 1<= N <=108 SAMPLE INPUT   2 18 40 SAMPLE OUTPUT...

MINIMUM DISTANCE BETWEEN TWO SIMILAR STRINGS

LATEST using System ; using System . Linq ; public class Test { public static void Main () { int arrayLength ; int T = Convert . ToInt32 ( Console . ReadLine ()); for ( int i = 0 ; i < T ; i ++) { arrayLength = Convert . ToInt32 ( Console . ReadLine ()); string Line = Console . ReadLine (); GetMinimumDistanceBetweenStrings ( arrayLength , Line ); } } public static void GetMinimumDistanceBetweenStrings ( int length , string Line ) { int min = - 1 ; int initial = 0 ; string [] stringArray = Line . Split ( " " ); for ( int start = 0 ; start < length - 1 ; start ++) { for ( int a = start + 1 ; a <= length - 1 ; a ++) { if ( stringArray [ start ]== stringArray [ a ]) { if ( initial == 0 ) ...

GRANDSON PROBLEM

https://www.geeksforgeeks.org/zoho-interview-set-1-campus/ Given a two dimensional array of string like <”luke”, “shaw”> <”wayne”, “rooney”> <”rooney”, “ronaldo”> <”shaw”, “rooney”> Where the first string is “child”, second string is “Father”. And given “ronaldo” we have to find his no of grandchildren Here “ronaldo” has 2 grandchildren. So our output should be 2. SOLUTION using System; public class Test { public static void Main() { var noOfInputs = Console.ReadLine(); int noOfInputLines = Convert.ToInt32(noOfInputs); string[,] FatherSonArray= new String[noOfInputLines,noOfInputLines]; for(int father=0;father<noOfInputLines;father++) { for(int son=0;son<2;son++) { FatherSonArray[father,son] = Console.ReadLine(); } }     Console.WriteLine("No of grandchildrens:");     string GrandFather = Console.ReadLine();     int NoOfGrandSons=0;     Console.Wr...

CHARACTER OR VOWEL

LATEST using System; public class Test { public static void Main() {       var Letter = Console.ReadLine();       char c = char.Parse(Letter);       if(CheckIfCharacterisVowel(c))       {          Console.WriteLine("YES");       }       else       {       Console.WriteLine("NO");       } } public static bool CheckIfCharacterisVowel(char c) { if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U'|| c=='a'||c=='e'||c=='i'||c=='o'||c=='u') { return true; } return false; } }

NQUEEN's PROBLEM

using System; public class GFG { static int n; static public void Main () { var TC = Console.ReadLine(); int T = Convert.ToInt32(TC); for(int a=0;a<T;a++) {     var no= Console.ReadLine();      n = Convert.ToInt32(no);     int [,]board =  new int [n,n];     InitializeBoardWithZeros(board,n,n);     SolveNQueen(board,0);     PrintBoard(board,n,n); } } static public void InitializeBoardWithZeros(int [,]board,int row,int col) {     for(int i=0;i<col;i++)     {         for(int j=0;j<row;j++)         {             board[i,j]=0;         }     }     } static public void PrintBoard(int [,]board,int row,int col) { for(int i=0;i<col;i++)     {         for(int j=0;j<row;j++) ...