AP 10 Ankit
AP 10 Ankit
Experiment 10
Student Name:Ankit Chaurasiya UID:21BCS11172
Branch:BE-CSE Section/Group: 604-A
Semester:5th Date : 31-10-23
Subject Name:Advance Programming - 1 Subject Code: 21CSP-314
Objective: (i) Marc loves cupcakes, but he also likes to stay fit. Each cupcake has a calorie
count, and Marc can walk a distance to expend those calories. If Marc has eaten cupcakes so
Code :
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
class Result {
/*
* Complete the 'marcsCakewalk' function below.
*
* The function is expected to return a LONG_INTEGER.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
int n = Integer.parseInt(bufferedReader.readLine().trim());
bufferedWriter.write(String.valueOf(result));
bufferedWriter.newLine();
bufferedReader.close();
bufferedWriter.close();
}
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
1. Output:
(ii) You are given two arrays, and , both containing integers. A pair of indices is beautiful if
the element of array is equal to the element of array . In other words, pair is beautiful if and
Code:
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
class Result {
public static int beautifulPairs(List<Integer> A, List<Integer> B) {
int countBeautifulPairs = 0;
for(int i = 0 ; i < A.size(); i++){
if(B.contains(A.get(i))){countBeautifulPairs++;
B.remove(B.indexOf(A.get(i)));
}
}
countBeautifulPairs+= (countBeautifulPairs==A.size()) ? -1 : 1;
return countBeautifulPairs;
}
}
int n = Integer.parseInt(bufferedReader.readLine().trim());
bufferedWriter.write(String.valueOf(result));
bufferedWriter.newLine();
bufferedReader.close();
bufferedWriter.close();
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
}
}
2. Output:
Learning Outcome: