首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >string1 +“|”+ string2 是什么意思

string1 +“|”+ string2 是什么意思
EN

Stack Overflow用户
提问于 2018-12-07 05:39:00
回答 1查看 0关注 0票数 0

我正在阅读一个代码,它在c ++中表示为地图上的键14是否有类似的东西代表一个键,如果有人知道请提前回复

string 1 +“|”是什么意思 +字符串2

这是代码......

代码语言:javascript
复制
#include <iostream>
#include <climits>
#include <unordered_map>
#include <algorithm>
using namespace std;

// N x N matrix
#define N 5

// create a map to store solutions of subproblems
 unordered_map<string, string> lookup;

// Function to check if cell (i, j) is a valid cell or not
bool isValid(int i, int j)
{
return (i >= 0 && i < N && j >= 0 && j < N);
}

  // Find longest path starting from cell (i, j) formed by adjacent 
 // numbers in the matrix
string findLongestPath(int mat[N][N], int i, int j)
{
// if the cell is invalid
if (!isValid (i, j))
    return 0;

// construct a unique map key from dynamic elements of the input
string key = to_string(i) + "|" + to_string(j);

// if sub-problem is seen for the first time, solve it and 
// store its result in a map
if (lookup.find(key) == lookup.end())
{
    // string to store path starting (i, j)
    string path;

    // recurse top cell if its value is +1 of value at (i, j)
    if (i > 0 && mat[i - 1][j] - mat[i][j] == 1)
        path = findLongestPath(mat, i - 1, j);

    // recurse right cell if its value is +1 of value at (i, j)
    if (j + 1 < N && mat[i][j + 1] - mat[i][j] == 1)
        path = findLongestPath(mat, i, j + 1);

    // recurse bottom cell if its value is +1 of value at (i, j)
    if (i + 1 < N && mat[i + 1][j] - mat[i][j] == 1)
        path = findLongestPath(mat, i + 1, j);

    // recurse left cell if its value is +1 of value at (i, j)
    if (j > 0 && mat[i][j - 1] - mat[i][j] == 1)
        path = findLongestPath(mat, i, j - 1);

    // note that as matrix contains all distinct elements,
    // there is only one path possible from current cell

    lookup[key] = to_string(mat[i][j]) + " - " +  path;
}

// return path starting from (i, j)
 return lookup[key];
}
EN

回答 1

Stack Overflow用户

发布于 2018-12-07 14:42:55

代码语言:txt
复制
string1 = "hello";
string2 = "world";

string1 + "|" + string2 == "hello|world"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100003025

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档