Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For Problem 2, name your source code pair.ext, where ext denotes one of {java, p

ID: 3860340 • Letter: F

Question

For Problem 2, name your source code pair.ext, where ext denotes one of {java, py } that
indicates java/python language.

I want to use python or java language to solve this. Thanks

Problem Statement 2: Minimum Double Pair The input format for this problem is the same as in Problem 1 but all integers (per line) are assumed to be different. We read in a sequence of 32-bit signed integers (several per line separated by spaces) until a single line containing zero (0). For each lie except for the last one, compute the smallest sum s such that there are two different pairs of integers (11,12) and (yi,y2), where 1112, 11yi

Explanation / Answer


import java.util.Scanner;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Surya
*/
public class Problem1 {
  
public static int sum(int num[],int x1,int x2)
{
  
//finding y1,y2 by generating combinations remaining (excluding x1,x2)
int i,j,y1,y2;
for(i=0;i<num.length;i++)
{
for(j=0;j<num.length;j++)
{
if(i!=j && i!=x1 && j!=x2 && i!=x2 && j!=x1)
{
if(num[i]>num[j])
{
y2 =i;
y1 =j;
}
else
{
y2 = j;
y1 = i;
}
  
if(num[x1]+num[x2]==num[y1]+num[y2])
{
return 1;
}
  
  
  
}
}
  
}
  
  
  
return 0;
}
private static final int[] convertToInts(String[] numbers)
{//converting string array to integer array...
int[] ints = new int[numbers.length];
for (int i = 0; i < ints.length; i++) {
ints[i] = Integer.parseInt(numbers[i]);
}
return ints;
}
  
public static void main(String argv[])
{
  
int[][] num = new int[1000][];
String line;
Scanner bReader = new Scanner(System.in);
int row;
for (row = 0; (line = bReader.nextLine()) != null && row < num.length; ++row) {
num[row] = convertToInts(line.trim().split("\s+"));
  
if(num[row].length==1)
{
if(num[row][0]==0)break;
}
}
  
int i,j;
  
  
  
int x1,x2,k,check=0,min=1000000000;
for(i=0;i<row;i++)
{
//finding x1,x2/....
//by generating combinations..
for(j=0;j<num[i].length;j++)
{
  
  
for(k=0;k<num[i].length;k++)
{
if(j!=k)
{
if(num[i][j]>num[i][k])
{
x2 = j;
x1 = k;
}
else
{
x1=j;
x2=k;
}
  
//sum function
if(sum(num[i],x1,x2)==1)
{
int n= num[i][x1]+num[i][x2];
if(n<min)min=n;
  
check=1;

}
  
}
  
}
  
  
}
  
if(check==0)
{
System.out.println("none");
}
else
{
System.out.println("yes:"+min);
min = 1000000000;
check=0;
}
  
  
}
  
}
  
  
  
  
}
  

output:-

run:
2 1 3 4
10 20 40 45 5 15 25
24 23 8 29 31 5
10 20 50 51 52 53 54 12 15 16
0
yes:5
yes:25
none
yes:62
BUILD SUCCESSFUL (total time: 40 seconds)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote