[Solved] Why this code is not giving right result for large arrays? [closed]

Here is the correct code #include<stdio.h> #include<stdlib.h> int main() { int t,T,n,i,j; long long int count,k; scanf(“%d”,&T); int *c = calloc(1000000,sizeof(int)); for(t=0;t<T;t++){ scanf(“%d”,&n); int temp; count =0; for(i=0;i<n;i++){ scanf(“%d”,&temp); c[temp-1]++ ; } for(i=0;i<1000000;i++){ if(c[i]>1){ k = c[i]; count+= k*(k-1); } c[i] = 0; } printf(“%lld\n”,count); } return 0; } Changes : Used calloc to initialize … Read more

[Solved] How to match two values in an array?

Why use arrays when you can use a sorted dictionary? take a look at this code example: SortedDictionary<int, int> sd = new SortedDictionary<int, int>(); sd.Add(1, 54); sd.Add(5, 12); sd.Add(3, 17); sd.Add(9, 1); sd.Add(2, 44); MessageBox.Show(“First: ” + sd[sd.Keys.ElementAt<int>(0)].ToString() + “\nLast: ” + sd[sd.Keys.ElementAt<int>(sd.Count-1)].ToString()); solved How to match two values in an array?

[Solved] Golf Score Tally Program Java – Stuck

Looks like you need to use another for loop to make sure you’re tallying each score: for(int i = 0; i < h; i++) { score_result = pArray[i] – hArray[i]; System.out.print(score_result); } If you just want the final score it would look something like this: int final_score = 0; for(int i = 0; i < … Read more

[Solved] C# does array.length start from 0?

If your array is empty, it contains 0 elements and has length 0. If your array has 1 element in 0 index, then its length is equal to 1. If your array has 2 elements in 0 and 1 indexes, then its length is equal 2. and so on… 5 solved C# does array.length start … Read more

[Solved] Array answer[i] to if Java

You cannot use a regular int declaration for an array unless you include brackets in the variable name answer[]. Also, array values are defined with curly braces: int count = 0; int[] answer = {2,4,3,2,1}; or int count = 0, answer[] = {2,4,3,2,1}; 3 solved Array answer[i] to if Java

[Solved] Summing the digits of a very large number [closed]

This would be a complete implementation in Haskell import Data.List.Split (chunksOf) import Data.List import Data.Char (digitToInt) main :: IO () main = do digits <- map digitToInt <$> readFile “pifile.txt” let summator = foldl1′ (zipWith (+)) . chunksOf 4 print $ summator digits I will update this with some explanation later this day. Update @Comments … Read more

[Solved] equality between two arrays

it’s reason is pointers. Variable a and b is points same positions because a = b; After this code a points same memory adress with b. And all the changes and result will be same. solved equality between two arrays