We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Constructing a Number
Constructing a Number
Sort by
recency
|
136 Discussions
|
Please Login in order to post a comment
Simplest Way To Do It !! string canConstruct(vector a) { // Return "Yes" or "No" denoting whether you can construct the required number. int n = a.size(); long sum = 0;
}
c#
public static string canConstruct(List a)
canConstruct Function:
This function takes an array of non-negative integers (numbers) and its size (n) as parameters. It initializes an array count to count the frequency of each digit from 0 to 9. It then iterates through each number in the array, updating the digit frequencies. After counting, it calculates the sum of digits weighted by their frequencies. It returns "Yes" if the sum is divisible by 3, indicating that a new integer can be constructed, and "No" otherwise. main Function:
It starts by inputting the number of queries (q). For each query, it takes the number of non-negative integers (n) and the integers themselves. It calls the canConstruct function for each set of numbers and prints the result. The program checks if it's possible to construct a new integer from each set of non-negative integers such that the resulting number is divisible by 3. The result for each query is printed.
include
include
include
// Function to check if it's possible to construct a new integer divisible by m char* canConstruct(int numbers[], int n) { // Count the frequency of each digit from 0 to 9 int count[10] = {0};
}
int main() { int q; // Number of queries scanf("%d", &q);
}