The program must accept M integers and N integers as the input. The program must form pairs of integers by selecting one integer from M integers and another integer from N integers. Then the program must print the number of pairs containing two integers with different number of digits as the output.
Boundary Condition(s):
1 <= M, N <= 10^4
1 <= Each integer value <= 10^16
Input Format:
The first line contains M and N separated by a space.
The second line contains M integers separated by a space.
The third line contains N integers separated by a space.
Output Format:
The first line contains the count of pairs as per the conditions.
Example Input/Output 1:
Input:
3 4
12 1 454
988 2 112 47
Output:
8
Explanation:
The pairs with two different length integers are
12 988
12 2
12 112
1 988
1 112
1 47
454 2
454 47
Example Input/Output 2:
Input:
5 10
464 69 1 9 62
69 26 592 28 22 252 172 341 9 5
Output:
34
# Read two integers as input and store them in num1 and num2
num1, num2 = map(int, input().split())
# Read two lists of integers as input and store them in lis1 and lis2
lis1 = list(map(int, input().split()))
lis2 = list(map(int, input().split()))
# Initialize empty lists lis3 and lis4
lis3, lis4 = [], []
# Calculate the number of digits in each element of lis1 and lis2, and store them in lis3 and lis4, respectively
for ele in lis1:
lis3.append(len(str(ele)))
for ele in lis2:
lis4.append(len(str(ele)))
# Sort the lists lis3 and lis4
lis3.sort()
lis4.sort()
# Initialize a counter variable ctr to 0
ctr = 0
# Compare the lengths of elements in lis3 and lis4 to find the count of elements in lis4 with fewer digits
for ele in lis3:
ctr += (len(lis4) - lis4.count(ele))
# Print the final count
print(ctr)
using System;
using System.Linq;
using System.Collections.Generic;
public class Program {
public static void Main() {
// Read two integers as input and store them in num1 and num2
string[] input1 = Console.ReadLine().Split();
int num1 = int.Parse(input1[0]);
int num2 = int.Parse(input1[1]);
// Read two lists of integers as input and store them in lis1 and lis2
int[] lis1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
int[] lis2 = Console.ReadLine().Split().Select(int.Parse).ToArray();
// Initialize lists lis3 and lis4 to store the number of digits in each element of lis1 and lis2, respectively
List<int> lis3 = new List<int>();
List<int> lis4 = new List<int>();
// Calculate the number of digits in each element of lis1 and lis2, and store them in lis3 and lis4, respectively
foreach (int ele in lis1) {
lis3.Add(ele.ToString().Length);
}
foreach (int ele in lis2) {
lis4.Add(ele.ToString().Length);
}
// Sort the lists lis3 and lis4
lis3.Sort();
lis4.Sort();
// Initialize a counter variable ctr to 0
int ctr = 0;
// Compare the lengths of elements in lis3 and lis4 to find the count of elements in lis4 with fewer digits
foreach (int ele in lis3) {
ctr += (lis4.Count - lis4.Count(n => n == ele));
}
// Print the final count
Console.WriteLine(ctr);
}
}
import java.util.Arrays;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
// Read two integers as input and store them in num1 and num2
Scanner scanner = new Scanner(System.in);
String[] input1 = scanner.nextLine().split(" ");
int num1 = Integer.parseInt(input1[0]);
int num2 = Integer.parseInt(input1[1]);
// Read two lists of integers as input and store them in lis1 and lis2
int[] lis1 = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
int[] lis2 = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
// Initialize lists lis3 and lis4 to store the number of digits in each element of lis1 and lis2, respectively
List<Integer> lis3 = new ArrayList<>();
List<Integer> lis4 = new ArrayList<>();
// Calculate the number of digits in each element of lis1 and lis2, and store them in lis3 and lis4, respectively
for (int ele : lis1) {
lis3.add(String.valueOf(ele).length());
}
for (int ele : lis2) {
lis4.add(String.valueOf(ele).length());
}
// Sort the lists lis3 and lis4
lis3.sort(null);
lis4.sort(null);
// Initialize a counter variable ctr to 0
int ctr = 0;
// Compare the lengths of elements in lis3 and lis4 to find the count of elements in lis4 with fewer digits
for (int ele : lis3) {
ctr += (lis4.size() - lis4.stream().filter(n -> n == ele).count());
}
// Print the final count
System.out.println(ctr);
}
}
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Read two integers as input and store them in num1 and num2
rl.question('Enter two integers separated by space: ', input1 => {
const [num1, num2] = input1.split(' ').map(Number);
// Read the first list of integers as input and store them in lis1
rl.question('Enter the first list of integers separated by space: ', input2 => {
const lis1 = input2.split(' ').map(Number);
// Read the second list of integers as input and store them in lis2
rl.question('Enter the second list of integers separated by space: ', input3 => {
const lis2 = input3.split(' ').map(Number);
// Initialize lists lis3 and lis4 to store the number of digits in each element of lis1 and lis2, respectively
const lis3 = lis1.map(ele => String(ele).length);
const lis4 = lis2.map(ele => String(ele).length);
// Sort the lists lis3 and lis4
lis3.sort((a, b) => a - b);
lis4.sort((a, b) => a - b);
// Initialize a counter variable ctr to 0
let ctr = 0;
// Compare the lengths of elements in lis3 and lis4 to find the count of elements in lis4 with fewer digits
for (const ele of lis3) {
ctr += lis4.length - lis4.filter(n => n === ele).length;
}
// Print the final count
console.log(ctr);
rl.close();
});
});
});