Category : matrix

I am trying too add every element in a int matrix so I can check if the player or computer wins. bool WinCondition(int Grid[10][10]) { int SumOfShips; for (int a = 0; a < 10; a++) { for (int b = 0; b < 10; b++) { SumOfShips += Grid[a][b] ; if (SumOfShips == 30) ..

Read more

I am trying to get an input to a matrix by placing the whole thing as in a function outside of main (), as follows: void input_matrix(int row, int col){ std::vector<std::vector<int>> matrix; for (int m=0; m<row; m++){ for (int n=0; n<col; n++){ std::cin >> matrix[m][n]; } } return matrix; } somehow the compiler doesn’t like ..

Read more

int main() { char Grid[8][8] = { ‘~’,’~’,’~’,’~’,’~’,’~’,’~’,’~’, ‘~’,’~’,’~’,’~’,’~’,’~’,’~’,’~’, ‘~’,’~’,’~’,’~’,’~’,’~’,’~’,’~’, ‘~’,’~’,’~’,’~’,’~’,’~’,’~’,’~’, ‘~’,’~’,’~’,’~’,’~’,’~’,’~’,’~’, ‘~’,’~’,’~’,’~’,’~’,’~’,’~’,’~’, ‘~’,’~’,’~’,’~’,’~’,’~’,’~’,’~’, ‘~’,’~’,’~’,’~’,’~’,’~’,’~’,’~’, }; int ShipCount = 1; while ( ShipCount < 6){ ShipPlacement(ShipCount, Grid[8][8]); ShipCount++; } ShowGrid(Grid[8][8]); return 0; } int ShipPlacement(int Shipcount, char Grid[8][8]) { srand(time(NULL)); int VerticalHorizontal = rand() % 2; //Randomly generates a number that will decide if the ..

Read more

https://codingcompetitions.withgoogle.com/codejamio/round/0000000000050ece/0000000000050df7#problem #include <iostream> #include <bits/stdc++.h> #define ll long long ; #define fo(i,n) for(int i=0;i<n;i++) #define si(x) scanf("%d",&x) #define sl(x) scanf("%lld",&x) #define ss(s) scanf("%s",s) using namespace std; int gcd(int a,int b){ if(a==0) return b ; if(b==0) return a ; if(a==b) return a; if(a>b){ return gcd(a-b,b); }else{ return gcd(a,b-a); } } int digit(int n ){ return floor(log10(n)+1); ..

Read more