Found 33676 Articles for Programming

C++ Program to find out if there is a pattern in a grid

Arnab Chakraborty
Updated on 07-Apr-2022 09:12:43

367 Views

Suppose, we are given a grid of dimensions n * n. We have to detect if there is a cross pattern in the grid, like below −#...# .#.#. ..#.. .#.#. #...#The grid can only contain '#' and '.'. We have to detect the pattern and find out how many such patterns are in the grid. The grid and the dimension are given to us as input.Problem CategoryVarious problems in programming can be solved through different techniques. To solve a problem, we have to devise an algorithm first, and to do that we have to study the particular problem in detail. ... Read More

C++ Program to find out the number of border cells in a grid

Arnab Chakraborty
Updated on 07-Apr-2022 09:06:35

378 Views

Suppose, we are given a grid of dimensions h * w. We have to color the border cells of the grid (i.e. the outermost cells of the grid) with a special color. We have to find out how many border cells we have to color.Problem CategoryVarious problems in programming can be solved through different techniques. To solve a problem, we have to devise an algorithm first, and to do that we have to study the particular problem in detail. A recursive approach can be used if there is a recurring appearance of the same problem over and over again; alternatively, ... Read More

C++ Program to find number of working components

Arnab Chakraborty
Updated on 07-Apr-2022 09:04:23

241 Views

Suppose, there is an electronic control board that implies the status of all the components in a system. Each component status is depicted using two LEDs; if any one of them is lit then that component is working. In the board, there are n rows of LED lights, and m components status are in a particular row; that means there are 2*m LED lights in each row. A given array 'grid' depicts the status of the board, if a light is lit then it is '1', otherwise '0'. We have to find out the number of components currently working from ... Read More

C++ Program to print unique integer pairs

Arnab Chakraborty
Updated on 07-Apr-2022 08:57:46

321 Views

Suppose, we are given two arrays a and b that each contain n integer numbers. From the arrays, we have to create integer pairs where one number is from array a and another one is from array b, and the addition of the numbers is always unique. We print all such integer pairs.Problem CategoryThe above-mentioned problem can be solved by applying Greedy problem-solving techniques. The greedy algorithm techniques are types of algorithms where the current best solution is chosen instead of going through all possible solutions. Greedy algorithm techniques are also used to solve optimization problems, like its bigger brother ... Read More

C++ Program to check if a string has been seen before

Arnab Chakraborty
Updated on 07-Apr-2022 08:50:15

233 Views

Suppose, we have n number of strings given to us in an array 'stringArr'. We iterate through the string elements one by one and find out if a string has appeared before in the array. If such occurs, we print 'Seen Before!' or otherwise, we print 'Didn't see before!'Problem CategoryTo solve this problem, we need to manipulate strings. Strings in a programming language are a stream of characters that are stored in a particular array-like data type. Several languages specify strings as a specific data type (eg. Java, C++, Python); and several other languages specify strings as a character array ... Read More

C++ Program to find an array satisfying an condition

Arnab Chakraborty
Updated on 07-Apr-2022 08:46:43

586 Views

Suppose, we are given an array of n integers 'x'. We have to find out another array of integers 'y', so that x[1].y[1] + x[2].y[2] +...+ x[n].y[n] = 0. We print the contents of array y.Problem CategoryVarious problems in programming can be solved through different techniques. To solve a problem, we have to devise an algorithm first, and to do that we have to study the particular problem in detail. A recursive approach can be used if there is a recurring appearance of the same problem over and over again; alternatively, we can use iterative structures also. Control statements such ... Read More

Express.js – req.subdomains Property

Mayank Agarwal
Updated on 06-Apr-2022 08:27:37

537 Views

req.subdomains returns an array of all the subdomains in the domain name of the request. The application property subdomain offset is used for determining the beginning of the subdomain segments. The default value of the subdomain offset property is 2.Syntaxreq.subdomainsExampleCreate a file with the name "reqSubdomains.js" and copy the following code snippet. After creating the file, use the command "node reqSubdomains.js" to run this code as shown in the example below −// req.subdomains Property Demo Example // Importing the express var express = require('express'); // Initializing the express and port number var app = express(); // Initializing the ... Read More

Express.js – req.signedCookies Property

Mayank Agarwal
Updated on 06-Apr-2022 08:26:34

318 Views

req.signedCookies contains the signed cookies (ready for use) sent by the request while using the cookie-parser middleware. Signed cookies exist in a different object to show the developer intent, else a malicious attack could be made on the request.cookie values that are relatively easy to spoof.The property defaults are set to "{ }", if no cookies are sent.Syntaxreq.signedCookiesInstalling the cookie-parser modulenpm install cookie-parserExample 1Create a file with the name "reqSignedCookies.js" and copy the following code snippet. After creating the file, use the command "node reqSignedCookies.js" to run this code as shown in the example below −// req.signedCookies() Method Demo Example ... Read More

Express.js – req.originalUrl Property

Mayank Agarwal
Updated on 06-Apr-2022 08:23:37

1K+ Views

The req.originalUrl property is similar to the req.url property. This property retains the original URL and lets us rewrite the same to redirect the request further to some other network or as needed. The app.use() method will rewrite the req.url to strip the mount point.Syntaxreq.originalUrlExample 1Create a file with the name "reqOriginalUrl.js" and copy the following code snippet. After creating the file, use the command "node reqOriginalUrl.js" to run this code as shown in the example below −// req.originalUrl Property Demo Example // Importing the express var express = require('express'); // Initializing the express and port number var app ... Read More

Express.js – req.ips Property

Mayank Agarwal
Updated on 06-Apr-2022 08:21:30

338 Views

The req.ips property contains an array of all the IP addresses in the X-Forwarded-For request header value. This property is only populated when the trust proxy setting does not evaluate to False. This header values or IP's can be set either by the proxy or the client.Syntaxreq.ipsExample 1Create a file with the name "reqIps.js" and copy the following code snippet. After creating the file, use the command "node reqIps.js" to run this code as shown in the example below −// req.ips Property Demo Example // Importing the express & cookieParser module var cookieParser = require('cookie-parser'); var express = require('express'); ... Read More

Advertisements