0% found this document useful (0 votes)
44 views

Wiley Edge Codes

The document contains code to solve 3 problems: 1) Print an X shape pattern given an input number 2) Count the minimum number of changes and insertions needed to make two strings equal given inputs with '?' as wildcards 3) Find and return the digit that needs to be appended to the end of a string to make its length equal to the first numeric digit found
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Wiley Edge Codes

The document contains code to solve 3 problems: 1) Print an X shape pattern given an input number 2) Count the minimum number of changes and insertions needed to make two strings equal given inputs with '?' as wildcards 3) Find and return the digit that needs to be appended to the end of a string to make its length equal to the first numeric digit found
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

x shape code :

input : 5

import java.io.*;
import java.util.Scanner;
public class varunjjfej {

public static void main(String[] args) {


Scanner obj = new Scanner (System.in);
int n = obj.nextInt();
for(int i =1,num1=1,num2=n*2-1;i<n*2;i++,num1++,num2--) {
for(int j=1;j<n*2;j++) {
if((i ==j || i+j == (n*2)) && num1<=n)
System.out.print(num1+ " ");
else if((i==j || i+j == (n*2)) && num1>n)
System.out.print(num2+ " ");
else
System.out.print(" ");
}
System.out.println();

}
-----end-----

caption contest :
input : ???a
???a
output : 0 3
import java.io.*;
import java.util.Scanner;
public class varunjjfej {

public static void main(String[] args) {


Scanner obj = new Scanner (System.in);
String s1 = obj.next();
String s2 = obj.next();
int ins1=0;
int ins2=0;
int min =0;
for(int i =0;i<s1.length();i++) {
if(s1.charAt(i) == '?')
ins1++;
if(s2.charAt(i) == '?')
ins2++;
if(s1.charAt(i) != s2.charAt(i) && (s1.charAt(i) !='?') &&
(s2.charAt(i)!='?'))
min++;

}
System.out.print(min+" "+(min+Math.max(ins1, ins2)));
}

}
------end -----
apppend end digit :
input:abcdefghijklmno1
output :6

import java.io.*;
import java.util.Scanner;
public class varunjjfej {

static int find_digit(String s, int n)


{
int first_digit = -1;
for (int i = n - 1; i >= 0; i--)
{
if (s.charAt(i) < '0' ||
s.charAt(i) > '9')
{
first_digit = i;
break;
}
}
first_digit++;
int s_len = first_digit;
int num = 0, pw = 1;
int i = n - 1;
while (i >= 0)
{
if (s.charAt(i) >= '0' &&
s.charAt(i) <= '9')
{
int digit = s.charAt(i) - '0';
num = num + (pw * digit);
if (num >= s_len)
return -1;
pw = pw * 10;
}
i--;
}
num = num * 10;
int req = s_len - num;
if (req > 9 || req < 0)
return -1;
return req;
}
public static void main (String[] args)
{
String s = "abcdefghijklmnop1";
int n = s.length();

System.out.print(find_digit(s, n));
}

-----end----

You might also like