array – Pass two-dimensional arrays as parameters in c ++ | Dynamic programming – cheaper trip by the river

I am making the problem of the cheapest trip by the river. But it happens
that I have always had problems passing as a parameter
two-dimensional, I tried with

int minorCandidate (int origin, int destination, int n, int T[][10], int & C)

Y

int minorCandidate (int origin, int destination, int n, int T[][10], int C[][4])

and others, if not what you could do is put fixed values. But I would like to implement so that the user could assign the values ​​for the array T that is the rate table.

                #include 
    using namespace std;
    int piers (int origin, int destination, int T[][10]);
    int minorCandidate (int origin, int destination, int n, int T[][10], int & C);
    int minimum (int a, int b);
    int main () {
    int n;
    cout <<"Numero de embarcaderos: ";cin>> n;
    int T[n][n]= {{0,3,4,10}, {3,0,1,3}, {4,1,0,1}, {10,3,2,0}};
    // print T
    for (int i = 0; i <n; i ++) {
        cout << endl;
        for (int j = 0; j <n; j ++) {
            cout << T[i][j]<< "";
        }
    }
    // cout << "Solution:" << jetties (1,5, T);

}

int piers (int origin, int destination, int T[][10], int n) {
    int C[n][n];
    int i, j;
    for (i = 1; i <n; i ++) {
        for (j = 1; j <n; j ++) {
            C[i][j]= minorCandidate (i, j, n, T, C);
        }
    }
    return C[n][n];
}
int minorCandidate (int origin, int destination, int n, int T[][10], int & C) {
    int temp;
    temp = 100;
    for (int i = origin + 1; i <n; i ++) {
        temp = min (temp, T[origen][i]+ C[i][destino]);
    }
    return temp;
}
int min (int a, int b) {
    if (a <= b)
    return to;
    if (b <a)
    return b;
}

java – Get JSON composed of arrays with Retrofit 2 and Android

I am making an application in Android Studio and I want to consume a recipe for cooking recipes, I have the following response from the API that I am consuming with Android Studio and Java:

                {
  "q": "chicken",
  "from": 0,
  "to": 10,
  "params": {
    "heal": [ ],
    "q": [ "pollo" ],
    "app_id": [ "02" ],
    "app_key": [ "n66b" ]
  },
  "more": true,
  "count": 1000,
  "hits":[{
    "recipe": {
      "uri": "http://www.edamam.com/ontologies/edamam.owl#recipe_d56f75c72ab67a45174441af1efe4473",
      "label": "Chicken with Cream of Herbs",
      "image": "http://cdn.kiwilimon.com/recetaimagen/23127/thumb120x90-15802.jpg",
      "source": "KiwiLimon",
      "url": "http://www.kiwilimon.com/receta/carnes-y-aves/pollo-con-crema-a-las-hierbas",
      "shareAs": "http://www.edamam.com/recipe/pollo-con-crema-a-las-hierbas-d56f75c72ab67a45174441af1efe4473/pollo",
      "yield": 42.0,

And continue with more 'recipe', what I want is to get only the array of hits that all the recipes have to be able to show in my application, the problem is that I get the following error:

Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

I understand that it is because it expects an array and it obtains a JSON object, but I do not know how to parse it, I have my Recipe model class and the RecipeService service and I manage everything in MainActivity, I have seen in some answers that I would have to do an intermediate response, but I do not understand how I could implement it in my code, then I show the classes that handle all this.

Recipe:

public class Recipe {
    private String label;
    private String image;
    private String source;
    private String shareAs;
    private List dietLabels;
    private List healthLabels;
    private List cautions;
    private List ingredientLines;
    private List ingredients;
    private double calories;
    private double totalWeight;
    private List totalNutrients;
    private List totalDaily;

    public String getLabel () {
        return label;
    }
    .
    .
    .

RecipeService:

                public interface RecipeService {

    String API_ROUTE = "/ search";
    String API_KEY = "& app_key =" + Credentials.API_KEY;
    String APP_ID = "& app_id =" + Credentials.APP_ID;
    // String query = "";

    @GET (API_ROUTE)
    Call <List > getRecipe (@Query ("q") String q);

}

MainActivity:

    private void getRecipes () {
        Retrofit retrofit = new Retrofit.Builder ()
                            .baseUrl ("https://test-es.edamam.com")
                            .addConverterFactory (GsonConverterFactory.create ())
                            .build ();

        RecipeService recipeService = retrofit.create (RecipeService.class);
        Call <List> call = recipeService.getRecipe ("chicken");

        System.out.println ("GET RECIPES");
        System.out.println ("HEADERS:" + call.request (). Headers ());

        call.enqueue (new Callback <List> () {
            @Override
            public void onResponse (Call <List> call, Response <List> response) {

                System.out.println ("RESPONSE CODE:" + response.code ());
                for (Recipe recipe: response.body ()) {

                    System.out.println ("ADDING:" + recipe.getLabel ());
                    recipes.add (recipe.getLabel ());
                }
                //System.out.println(recipes.toArray (). ToString ());
            }

            @Override
            public void onFailure (Call <List> call, Throwable t) {
                System.out.println ("A FAULT HAPPENED");
                System.out.println (t.getMessage ());
            }
        });
    }

php – The WordPress loop by target key that is a matrix? and how to make multiple arrays

It can not be ordered by values ​​within serialized matrices in the publication goal. When you store an array like this:

$ value = [
    [
            'plan_name'  => 'name 1',
            'plan_price' => '1',
            'theType'    => 'yesPaid',
            'plan_space' => 'Unlimited',
    ],
    [
            'plan_name'  => 'name 2',
            'plan_price' => '3',
            'theType'    => 'yesFree',
            'plan_space' => '5000',
    ],
    [
            'plan_name'  => 'name2',
            'plan_price' => '5',
            'theType'    => 'yesPaid',
            'plan_space' => 'Unlimited',
    ],
]

This is stored in PHP in this way:

a: 3: {i: 0; a: 4: {s: 9: "plan_name"; s: 6: "name 1"; s: 10: "plan_price"; s: 1: "1"; s: 7: "theType"; s: 7: "yesPaid"; s: 10: "plan_space"; s: 9: "Unlimited";} i: 1; a: 4: {s: 9: "plan_name"; s: 6: "name 2"; s: 10: "plan_price"; s: 1: "3"; s: 7: "theType"; s: 7: "yesFree"; s: 10: "plan_space"; s: 4: "5000";} i: 2; a: 4: {s: 9: "plan_name"; s: 5: "name2"; s: 10: "plan_price"; s: 1: "5"; s: 7: "theType"; s: 7: "yesPaid"; s: 10: "plan_space"; s: 9: "Unlimited";}}

As for MySQL, which is responsible for consulting the publications, this is just a long string. Indistinguishable from a word or sentence that begins with a. WordPress only returns it to an array when the value is retrieved with get_post_meta ().

Therefore, it is not possible to sort by a property within a matrix, and if you try to sort by the target value of this goal, then it will only be ordered as if it were a string.

If you need to order in this way, then you need to find an alternative way to store the data. I do not have enough information about your project to suggest anything specific, but you will probably need a custom database table for these plans, which you then need to join and sort using the posts_join Y posts_orderby Hooks to modify the SQL query directly.

Union of C ++ arrays

Sorry, how would the algorithm or code to calculate the union of two vectors, without repeating any of its elements
for example:
TO[]= {3,5,6,4,3}
B[]= {3,10,1,2}
then the union would be
C[]= {3,5,6,4,10,1,2}

Join two arrays in a single PHP json

I have the following PHP:

"orange", "fruit2" => "strawberry");
$ item2 = array ("fruit3" => "goiaba", "fruit4" => "grape");
array_push ($ items1, $ item2);
echo json_encode ($ item1);
?>

I would like him to come back:

{"Fruit1", "orange", "fruit2", "strawberry", "fruit3": "guava", "fruit4": "grape"}

But it is not working, when I run PHP it returns:

{"Fruit1", "orange", "fruit2", "strawberry", "0": {"fruit3", "potato", "fruit4" "grape"}}

That is, it has a "0" there and two keys.
I have already researched and tried in various ways but I am not getting the desired result.

I already thank whoever can help me.

python 3.x – Version 2 – prints new pair length arrays from two arrays

This is an update of the code from my previous post for the GeeksForGeeks task.

Outline of the task

Given two arrays, print all the new arrays even length where each subsequent element in the new matrix comes alternately from A and B Y Each element is larger than the previous element.

Example:

  • Array 1 = [1, 2, 3]
  • Array 2 = [2, 4, 6]

Possible new matrix lengths = [2, 4, 6]

The output for matrices of length 2 is:
[1,2], [1,4], [1,6], [2,4], [2,6], [3,4] [3,6]

The complete solution for the above includes the following two additional matrices:
[1 2 3 4], [1 2 3 6]

This solution uses the itertools library

import itertools
A =[10, 20, 30,40]
B =[11,21,31,41]
list_solutions = []


for x in the range (1, min (len (A), len (B)) + 1):
newA = list (itertools.combinations (A, x))
newB = list (itertools.combinations (B, x))
for itemA in newA:
for itemB in newB:
to_print = True
for the index within the range (min (len (itemA), len (itemB))):
yes itemA[index] > = itemB[index]:
to_print = False
break
yes to_print == True:
list_solutions.append ([itemA, itemB])

#Print only valid solutions:
for the article in list_solutions:
print_valid = True
for index in range (len (item[0])):
if article[0][index]    > = item[1][index]:
print_valid = False
break
if index> = 1:
if article[0][index]    <= item[1][index-1]:
print_valid = False
break
If print_valid == True:
for index in range (len (item[0])):
print (article[0][index], Item[1][index], sep = "", end = "")
Print ("")
if print_valid == False:
continue  

Change columns in PHP 2-d arrays

guys I'm trying to write a magic PHP application. But, I'm a freshman in PHP. I want to change (better at random) the columns in 2-d matrices. As below,

$ array = (
array (& # 39 ;, 1 & # 39 ;, & # 39; 2 & # 39 ;, & # 39; 3 & # 39;),
array (& # 39 ;, 4 & # 39 ;, & # 39; 5 & # 39 ;, & # 39; 6 & # 39;),
array (& # 39; 7 & # 39 ;, & # 39; 8 & # 39 ;, & # 39; 9 & # 39;)
);
some_function ($ array);
var_dump ($ array);

I want the exit like this

array (3) {
[0]=> array (3) {
  [0]=> string (1) & # 39; 1 & # 39;
  [1]=> string (1) & # 39; 3 & # 39;
  [2]=> string (1) & # 39; 2 & # 39;
}
[1]=> array (3) {
  [0]=> string (1) & # 39; 4 & # 39;
  [1]=> string (1) & # 39; 6 & # 39;
  [2]=> string (1) & # 39; 5 & # 39;
}
[2]=> array (3) {
  [0]=> string (1) & # 39; 7 & # 39;
  [1]=> string (1) & # 39; 9 & # 39;
  [2]=> string (1) & # 39; 8 & # 39;
}
}

Can any superhero help me?

Exercise of arrays in javascript

This problem throws me wrong and I do not know where I am failing.

We need a "moreLess" function that receives an array and returns another with the following three numbers:
in the first position, the fraction of numbers that are positive
in the second position, the fraction of numbers that are zero
in the last position, the fraction of numbers that are negative
For example, more Less ([1, 2, 0, -1]) should return [0.5, 0.25, 0.25], since there are 50% positives, 25% zeros, and 25% negatives.

function moreMenos (numbers) {

        positive var = 0;
        var zero = 0;
        negative var = 0;

        for (var i = 0; i 0)
                positive + 1}


            if (numbers <0) {
              negative + 1}

            if (numbers == 0) {
               zero + 1}


   var sum = positive + negative + zero;

   var percentage = [positivos / suma, negativos / suma, cero / suma]

   return percentage

}

javascript: compare with arrays of objects and update the key in Angular 6, Typescript

listOne: [
{ 
  id: 1,
  compId: 11,
  active: false, 
},
{ 
  id: 2,
  compId: 22,
  active: false, 
},
{ 
  id: 3,
  compId: 33,
  active: false, 
},
]

list two [
{ 
  id: 1,
  compId: 11,
  active: true, 
},
{ 
  id: 2,
  compId: 33,
  active: false, 
},
]

I have two json, here how to compare with compId key and update the active key in listOne since list two .

In AngularJs I have tried with this link for AngularJs

But how to integrate with Angular 6 with Typescript.
Thank you.

postgresql – Arrays added with overlapping values

I have a table with the values ​​of id and cluster int like this in PostgreSQL:

eleven
1 2
2 2
2. 3
3. 4

Each ID can belong to several clusters and each cluster can cover several IDs.
How can I group by both columns to obtain this result?

[1,2] [1,2,3]
[3]   [4]

I have managed to group only one column so far

with t as (select "unesto" (matrix[1,1,2,2,3]) id, unnest (array[1,2,2,3,4]clst)
select array_agg (id) id, array_agg (clst) of group t by id