[Solved] Reading multiple lines of strings from a file and storing it in string array in C++

NumberOfStrings++ is outside of your for loop when you read (i.e. it only gets incremented once). Also please consider using std::vector<std::string> instead of a dynamic array. Here’s a version of your code using std::vector instead of an array: #include <vector> #include <fstream> #include <iostream> #include <string> class StringList { public: StringList(): str(1000000), numberOfStrings(0) { std::ifstream … Read more

[Solved] algorithm removing duplicate elements in array without auxillay storage

OK, here’s my answer, which should be O(N*N) worst case. (With smaller constant, since even worstcase I’m testing N against — on average — 1/2 N, but this is computer science rather than software engineering and a mere 2X speedup isn’t significant. Thanks to @Alexandru for pointing that out.) 1) Split cursor (input and output … Read more

[Solved] Optimal way to creating a multiplication table -java

You can define the table size and print the multiplication grid as follows: public static void main(String[]args) { final int TABLE_SIZE = 12; // Declare the rectangular array to store the multiplication table: int[][] table = new int[TABLE_SIZE][TABLE_SIZE]; // Fill in the array with the multiplication table: for(int i = 0 ; i < table.length … Read more

[Solved] Check if value of one array is found in another [closed]

You can simlpy cycle through the second array, split at :, check the first part and, in case of a match, return the second function findX(value, arr) { for (var i = 0; i < arr.length; i++) { var toSplit = arr[i].split(‘:’); if (toSplit[0] === value) { return toSplit[1]; } } } console.log(findX(“User1-2”, [“User1-2:280”, “User2-2:280”, … Read more

[Solved] How to group and create relationship from JSON response [closed]

It sounds like you want to group the items by league. Let’s use our array_reduce friend for that. This is the basic syntax: $arr = [ [ “leauge” => “sweeden”, “fixture” => “12” ], [ “leauge” => “sweeden”, “fixture” => “13” ], [ “leauge” => “germany”, “fixture” => “14” ], [ “leauge” => “france”, “fixture” … Read more

[Solved] find the min and avg of student if it exist show the name of the student

Try to add a for loop to calcolate the sum of ages like this: for(i=0;i<age.length;i++){ sum+=age[i]; } And take out this below block out of for loop: avg= sum/age.length; System.out.println(“the avarage of all Students are :”+avg); System.out.println(“the minimum age of all Students : “+min); Like this: public static void main(String[] args) { // TODO code … Read more

[Solved] Why compilers put zeros into arrays while they do not have to?

A structValue{}; is aggregate initialization, so 0 are guaranteed. As A has no user provided constructor because explicitly defaulted constructors do not count as such, the same applies for value initialization as in A* psstructValue = new A();. For the default initialization cases: Reading uninitialized variables is UB, and Undefined behavior is undefined. The compiler … Read more