Code Monkey home page Code Monkey logo

Comments (3)

YakultGo avatar YakultGo commented on June 14, 2024

确实,最近也做过很多笔试,一般都会让你自己处理输入,但是都是比较常规的,给你n行、1行m个数,然后读取n次、1次读取m个数这样子的,感觉牛客那样子的就够了

from kamacoder-solutions.

ZoYooJy avatar ZoYooJy commented on June 14, 2024

同意!!!将数据转换为vector<vector>耗费最多的时间
贴一个比较简单、可能复杂度较高的方法:

std::vector<std::vector<int>> str2vec(const std::string& str) {
  std::vector<std::string> rows;

  auto start = str.find("[", 1);
  auto end = str.find("]");

  while (start != std::string::npos) {
    rows.emplace_back(str.substr(start + 1, end - start - 1));
    start = str.find("[", end + 1);
    end = str.find("]", end + 1);
  }

  int r = rows.size();
  int c = std::count(rows[0].begin(), rows[0].end(), ',') + 1;
  std::vector<std::vector<int>> nums(r, std::vector<int>(c, 0));
  for (int i = 0; i < r; ++i) {
    std::stringstream ss(rows[i]);
    std::string elem;
    int j = 0;
    while (getline(ss, elem, ',')) {
      nums[i][j++] = std::stoi(elem);
    }
  }

  return nums;
}

from kamacoder-solutions.

JohnChenLiang avatar JohnChenLiang commented on June 14, 2024

第36题这种输入方式是不是有点考察的本末倒置了,[[2,3,1],[2,5,3],[4,2,1]]这种输入方式对于java来说有直接的函数可以用,但是对于c++或者其它语言来说,输入就要花费好长时间来想想怎么处理,可不可以卡尔考虑一下解决一下类似这种题目的输入问题,把问题的考察点重点放在算法而不是输入上?谢谢啦!

java什么函数能直接处理?我java写这题的时候也哼哧哼哧的写了半天,36. 网格路径和 就是力扣原题 剑指 Offer 47. 礼物的最大价值。入门dp,但把这一行字符串的输入 处理成二维数组是真麻烦。

from kamacoder-solutions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.